forked from rc/aircox
create aircox_streamer as separate application
This commit is contained in:
@ -1,8 +0,0 @@
|
||||
from .article import ArticleAdmin
|
||||
from .episode import DiffusionAdmin, EpisodeAdmin
|
||||
from .log import LogAdmin
|
||||
from .program import ProgramAdmin, ScheduleAdmin, StreamAdmin
|
||||
from .sound import SoundAdmin, TrackAdmin
|
||||
from .station import StationAdmin
|
||||
|
||||
|
@ -1,18 +0,0 @@
|
||||
import copy
|
||||
|
||||
from django.contrib import admin
|
||||
|
||||
from ..models import Article
|
||||
from .page import PageAdmin
|
||||
|
||||
|
||||
__all__ = ['ArticleAdmin']
|
||||
|
||||
|
||||
@admin.register(Article)
|
||||
class ArticleAdmin(PageAdmin):
|
||||
list_filter = PageAdmin.list_filter
|
||||
search_fields = PageAdmin.search_fields + ['parent__title']
|
||||
# TODO: readonly field
|
||||
|
||||
|
@ -1,58 +0,0 @@
|
||||
import copy
|
||||
|
||||
from django.contrib import admin
|
||||
from django.utils.translation import ugettext as _, ugettext_lazy
|
||||
|
||||
from aircox.models import Episode, Diffusion, Sound, Track
|
||||
|
||||
from .page import PageAdmin
|
||||
from .sound import SoundInline, TracksInline
|
||||
|
||||
|
||||
class DiffusionBaseAdmin:
|
||||
fields = ['type', 'start', 'end']
|
||||
|
||||
def get_readonly_fields(self, request, obj=None):
|
||||
fields = super().get_readonly_fields(request, obj)
|
||||
if not request.user.has_perm('aircox_program.scheduling'):
|
||||
fields += ['program', 'start', 'end']
|
||||
return [field for field in fields if field in self.fields]
|
||||
|
||||
|
||||
@admin.register(Diffusion)
|
||||
class DiffusionAdmin(DiffusionBaseAdmin, admin.ModelAdmin):
|
||||
def start_date(self, obj):
|
||||
return obj.local_start.strftime('%Y/%m/%d %H:%M')
|
||||
start_date.short_description = _('start')
|
||||
|
||||
def end_date(self, obj):
|
||||
return obj.local_end.strftime('%H:%M')
|
||||
end_date.short_description = _('end')
|
||||
|
||||
list_display = ('episode', 'start_date', 'end_date', 'type', 'initial')
|
||||
list_filter = ('type', 'start', 'program')
|
||||
list_editable = ('type',)
|
||||
ordering = ('-start', 'id')
|
||||
|
||||
fields = ['type', 'start', 'end', 'initial', 'program']
|
||||
|
||||
|
||||
class DiffusionInline(DiffusionBaseAdmin, admin.TabularInline):
|
||||
model = Diffusion
|
||||
fk_name = 'episode'
|
||||
extra = 0
|
||||
|
||||
def has_add_permission(self, request):
|
||||
return request.user.has_perm('aircox_program.scheduling')
|
||||
|
||||
|
||||
@admin.register(Episode)
|
||||
class EpisodeAdmin(PageAdmin):
|
||||
list_display = PageAdmin.list_display
|
||||
list_filter = PageAdmin.list_filter
|
||||
search_fields = PageAdmin.search_fields + ['parent__title']
|
||||
# readonly_fields = ('parent',)
|
||||
|
||||
inlines = [TracksInline, SoundInline, DiffusionInline]
|
||||
|
||||
|
@ -1,13 +0,0 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from ..models import Log
|
||||
|
||||
|
||||
__all__ = ['LogAdmin']
|
||||
|
||||
|
||||
@admin.register(Log)
|
||||
class LogAdmin(admin.ModelAdmin):
|
||||
list_display = ['id', 'date', 'station', 'source', 'type', 'comment']
|
||||
list_filter = ['date', 'source', 'station']
|
||||
|
@ -1,42 +0,0 @@
|
||||
class UnrelatedInlineMixin:
|
||||
"""
|
||||
Inline class that can be included in an admin change view whose model
|
||||
is not directly related to inline's model.
|
||||
"""
|
||||
view_model = None
|
||||
parent_model = None
|
||||
parent_fk = ''
|
||||
|
||||
def __init__(self, parent_model, admin_site):
|
||||
self.view_model = parent_model
|
||||
super().__init__(self.parent_model, admin_site)
|
||||
|
||||
def get_parent(self, view_obj):
|
||||
""" Get formset's instance from `obj` of AdminSite's change form. """
|
||||
field = self.parent_model._meta.get_field(self.parent_fk).remote_field
|
||||
return getattr(view_obj, field.name, None)
|
||||
|
||||
def save_parent(self, parent, view_obj):
|
||||
""" Save formset's instance. """
|
||||
setattr(parent, self.parent_fk, view_obj)
|
||||
parent.save()
|
||||
return parent
|
||||
|
||||
def get_formset(self, request, obj):
|
||||
ParentFormSet = super().get_formset(request, obj)
|
||||
inline = self
|
||||
class FormSet(ParentFormSet):
|
||||
view_obj = None
|
||||
|
||||
def __init__(self, *args, instance=None, **kwargs):
|
||||
self.view_obj = instance
|
||||
instance = inline.get_parent(instance)
|
||||
self.instance = instance
|
||||
super().__init__(*args, instance=instance, **kwargs)
|
||||
|
||||
def save(self):
|
||||
inline.save_parent(self.instance, self.view_obj)
|
||||
return super().save()
|
||||
return FormSet
|
||||
|
||||
|
@ -1,52 +0,0 @@
|
||||
from django.contrib import admin
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from adminsortable2.admin import SortableInlineAdminMixin
|
||||
|
||||
from ..models import Category, Article, NavItem
|
||||
|
||||
|
||||
__all__ = ['CategoryAdmin', 'PageAdmin', 'NavItemInline']
|
||||
|
||||
|
||||
@admin.register(Category)
|
||||
class CategoryAdmin(admin.ModelAdmin):
|
||||
list_display = ['pk', 'title', 'slug']
|
||||
list_editable = ['title', 'slug']
|
||||
search_fields = ['title']
|
||||
fields = ['title', 'slug']
|
||||
prepopulated_fields = {"slug": ("title",)}
|
||||
|
||||
|
||||
# limit category choice
|
||||
class PageAdmin(admin.ModelAdmin):
|
||||
list_display = ('cover_thumb', 'title', 'status', 'category', 'parent')
|
||||
list_display_links = ('cover_thumb', 'title')
|
||||
list_editable = ('status', 'category')
|
||||
list_filter = ('status', 'category')
|
||||
prepopulated_fields = {"slug": ("title",)}
|
||||
|
||||
search_fields = ['title', 'category__title']
|
||||
fieldsets = [
|
||||
('', {
|
||||
'fields': ['title', 'slug', 'category', 'cover', 'content'],
|
||||
}),
|
||||
(_('Publication Settings'), {
|
||||
'fields': ['featured', 'allow_comments', 'status', 'parent'],
|
||||
'classes': ('collapse',),
|
||||
}),
|
||||
]
|
||||
|
||||
change_form_template = 'admin/aircox/page_change_form.html'
|
||||
|
||||
def cover_thumb(self, obj):
|
||||
return mark_safe('<img src="{}"/>'.format(obj.cover.icons['64'])) \
|
||||
if obj.cover else ''
|
||||
|
||||
|
||||
class NavItemInline(SortableInlineAdminMixin, admin.TabularInline):
|
||||
model = NavItem
|
||||
|
||||
|
||||
|
@ -1,76 +0,0 @@
|
||||
from copy import deepcopy
|
||||
|
||||
from django.contrib import admin
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from ..models import Program, Schedule, Stream
|
||||
from .page import PageAdmin
|
||||
|
||||
|
||||
class ScheduleInline(admin.TabularInline):
|
||||
model = Schedule
|
||||
extra = 1
|
||||
|
||||
|
||||
class StreamInline(admin.TabularInline):
|
||||
fields = ['delay', 'begin', 'end']
|
||||
model = Stream
|
||||
extra = 1
|
||||
|
||||
|
||||
@admin.register(Program)
|
||||
class ProgramAdmin(PageAdmin):
|
||||
def schedule(self, obj):
|
||||
return Schedule.objects.filter(program=obj).count() > 0
|
||||
|
||||
schedule.boolean = True
|
||||
schedule.short_description = _("Schedule")
|
||||
|
||||
list_display = PageAdmin.list_display + ('schedule', 'station', 'active')
|
||||
list_filter = PageAdmin.list_filter + ('station', 'active')
|
||||
fieldsets = deepcopy(PageAdmin.fieldsets) + [
|
||||
(_('Program Settings'), {
|
||||
'fields': ['active', 'station', 'sync'],
|
||||
'classes': ('collapse',),
|
||||
})
|
||||
]
|
||||
|
||||
prepopulated_fields = {'slug': ('title',)}
|
||||
search_fields = ['title']
|
||||
|
||||
inlines = [ScheduleInline, StreamInline]
|
||||
|
||||
|
||||
@admin.register(Schedule)
|
||||
class ScheduleAdmin(admin.ModelAdmin):
|
||||
def program_title(self, obj):
|
||||
return obj.program.title
|
||||
program_title.short_description = _('Program')
|
||||
|
||||
def freq(self, obj):
|
||||
return obj.get_frequency_verbose()
|
||||
freq.short_description = _('Day')
|
||||
|
||||
def rerun(self, obj):
|
||||
return obj.initial is not None
|
||||
rerun.short_description = _('Rerun')
|
||||
rerun.boolean = True
|
||||
|
||||
list_filter = ['frequency', 'program']
|
||||
list_display = ['program_title', 'freq', 'time', 'timezone', 'duration',
|
||||
'rerun']
|
||||
list_editable = ['time', 'duration']
|
||||
|
||||
def get_readonly_fields(self, request, obj=None):
|
||||
if obj:
|
||||
return ['program', 'date', 'frequency']
|
||||
else:
|
||||
return []
|
||||
|
||||
|
||||
@admin.register(Stream)
|
||||
class StreamAdmin(admin.ModelAdmin):
|
||||
list_display = ('id', 'program', 'delay', 'begin', 'end')
|
||||
|
||||
|
||||
|
@ -1,65 +0,0 @@
|
||||
from django.contrib import admin
|
||||
from django.utils.translation import ugettext as _, ugettext_lazy
|
||||
|
||||
from adminsortable2.admin import SortableInlineAdminMixin
|
||||
|
||||
from ..models import Sound, Track
|
||||
|
||||
|
||||
class TracksInline(SortableInlineAdminMixin, admin.TabularInline):
|
||||
template = 'admin/aircox/playlist_inline.html'
|
||||
model = Track
|
||||
extra = 0
|
||||
fields = ('position', 'artist', 'title', 'info', 'timestamp', 'tags')
|
||||
|
||||
list_display = ['artist', 'title', 'tags', 'related']
|
||||
list_filter = ['artist', 'title', 'tags']
|
||||
|
||||
|
||||
|
||||
class SoundInline(admin.TabularInline):
|
||||
model = Sound
|
||||
fields = ['type', 'path', 'embed', 'duration', 'is_public']
|
||||
readonly_fields = ['type', 'path', 'duration']
|
||||
extra = 0
|
||||
|
||||
|
||||
@admin.register(Sound)
|
||||
class SoundAdmin(admin.ModelAdmin):
|
||||
def filename(self, obj):
|
||||
return '/'.join(obj.path.split('/')[-2:])
|
||||
filename.short_description=_('file')
|
||||
|
||||
fields = None
|
||||
list_display = ['id', 'name', 'program', 'type', 'duration',
|
||||
'is_public', 'is_good_quality', 'episode', 'filename']
|
||||
list_filter = ('program', 'type', 'is_good_quality', 'is_public')
|
||||
|
||||
search_fields = ['name', 'program']
|
||||
fieldsets = [
|
||||
(None, {'fields': ['name', 'path', 'type', 'program', 'episode']}),
|
||||
(None, {'fields': ['embed', 'duration', 'is_public', 'mtime']}),
|
||||
(None, {'fields': ['is_good_quality']})
|
||||
]
|
||||
readonly_fields = ('path', 'duration',)
|
||||
inlines = [TracksInline]
|
||||
|
||||
|
||||
@admin.register(Track)
|
||||
class TrackAdmin(admin.ModelAdmin):
|
||||
def tag_list(self, obj):
|
||||
return u", ".join(o.name for o in obj.tags.all())
|
||||
|
||||
list_display = ['pk', 'artist', 'title', 'tag_list', 'episode', 'sound', 'timestamp']
|
||||
list_editable = ['artist', 'title']
|
||||
list_filter = ['artist', 'title', 'tags']
|
||||
|
||||
search_fields = ['artist', 'title']
|
||||
fieldsets = [
|
||||
(_('Playlist'), {'fields': ['episode', 'sound', 'position', 'timestamp']}),
|
||||
(_('Info'), {'fields': ['artist', 'title', 'info', 'tags']}),
|
||||
]
|
||||
|
||||
# TODO on edit: readonly_fields = ['episode', 'sound']
|
||||
|
||||
|
@ -1,20 +0,0 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from ..models import Port, Station
|
||||
from .page import NavItemInline
|
||||
|
||||
|
||||
__all__ = ['PortInline', 'StationAdmin']
|
||||
|
||||
|
||||
class PortInline(admin.StackedInline):
|
||||
model = Port
|
||||
extra = 0
|
||||
|
||||
|
||||
@admin.register(Station)
|
||||
class StationAdmin(admin.ModelAdmin):
|
||||
prepopulated_fields = {'slug': ('name',)}
|
||||
inlines = [PortInline, NavItemInline]
|
||||
|
||||
|
Reference in New Issue
Block a user