forked from rc/aircox
add episode: models, admin, diffusion gen, sounds_monitor, playlist import
This commit is contained in:
@ -1,5 +1,28 @@
|
||||
from .base import *
|
||||
from .diffusion import DiffusionAdmin
|
||||
from django.contrib import admin
|
||||
|
||||
|
||||
from .episode import DiffusionAdmin, EpisodeAdmin
|
||||
# from .playlist import PlaylistAdmin
|
||||
from .program import ProgramAdmin, ScheduleAdmin, StreamAdmin
|
||||
from .sound import SoundAdmin
|
||||
|
||||
from aircox.models import Log, Port, Station
|
||||
|
||||
|
||||
class PortInline(admin.StackedInline):
|
||||
model = Port
|
||||
extra = 0
|
||||
|
||||
|
||||
@admin.register(Station)
|
||||
class StationAdmin(admin.ModelAdmin):
|
||||
prepopulated_fields = {'slug': ('name',)}
|
||||
inlines = [PortInline]
|
||||
|
||||
|
||||
@admin.register(Log)
|
||||
class LogAdmin(admin.ModelAdmin):
|
||||
list_display = ['id', 'date', 'station', 'source', 'type', 'diffusion', 'sound', 'track']
|
||||
list_filter = ['date', 'source', 'station']
|
||||
|
||||
|
||||
|
BIN
aircox/admin/__pycache__/__init__.cpython-37.pyc
Normal file
BIN
aircox/admin/__pycache__/__init__.cpython-37.pyc
Normal file
Binary file not shown.
BIN
aircox/admin/__pycache__/base.cpython-37.pyc
Normal file
BIN
aircox/admin/__pycache__/base.cpython-37.pyc
Normal file
Binary file not shown.
BIN
aircox/admin/__pycache__/diffusion.cpython-37.pyc
Normal file
BIN
aircox/admin/__pycache__/diffusion.cpython-37.pyc
Normal file
Binary file not shown.
BIN
aircox/admin/__pycache__/episode.cpython-37.pyc
Normal file
BIN
aircox/admin/__pycache__/episode.cpython-37.pyc
Normal file
Binary file not shown.
BIN
aircox/admin/__pycache__/mixins.cpython-37.pyc
Normal file
BIN
aircox/admin/__pycache__/mixins.cpython-37.pyc
Normal file
Binary file not shown.
BIN
aircox/admin/__pycache__/page.cpython-37.pyc
Normal file
BIN
aircox/admin/__pycache__/page.cpython-37.pyc
Normal file
Binary file not shown.
BIN
aircox/admin/__pycache__/playlist.cpython-37.pyc
Normal file
BIN
aircox/admin/__pycache__/playlist.cpython-37.pyc
Normal file
Binary file not shown.
BIN
aircox/admin/__pycache__/program.cpython-37.pyc
Normal file
BIN
aircox/admin/__pycache__/program.cpython-37.pyc
Normal file
Binary file not shown.
BIN
aircox/admin/__pycache__/sound.cpython-37.pyc
Normal file
BIN
aircox/admin/__pycache__/sound.cpython-37.pyc
Normal file
Binary file not shown.
@ -1,91 +0,0 @@
|
||||
from django import forms
|
||||
from django.contrib import admin
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import ugettext as _, ugettext_lazy
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from adminsortable2.admin import SortableInlineAdminMixin
|
||||
|
||||
from aircox.models import *
|
||||
|
||||
|
||||
class ScheduleInline(admin.TabularInline):
|
||||
model = Schedule
|
||||
extra = 1
|
||||
|
||||
class StreamInline(admin.TabularInline):
|
||||
fields = ['delay', 'begin', 'end']
|
||||
model = Stream
|
||||
extra = 1
|
||||
|
||||
|
||||
@admin.register(Stream)
|
||||
class StreamAdmin(admin.ModelAdmin):
|
||||
list_display = ('id', 'program', 'delay', 'begin', 'end')
|
||||
|
||||
|
||||
@admin.register(Program)
|
||||
class ProgramAdmin(admin.ModelAdmin):
|
||||
def schedule(self, obj):
|
||||
return Schedule.objects.filter(program=obj).count() > 0
|
||||
|
||||
schedule.boolean = True
|
||||
schedule.short_description = _("Schedule")
|
||||
|
||||
list_display = ('name', 'id', 'active', 'schedule', 'sync', 'station')
|
||||
fields = ['name', 'slug', 'active', 'station', 'sync']
|
||||
prepopulated_fields = {'slug': ('name',)}
|
||||
search_fields = ['name']
|
||||
|
||||
inlines = [ScheduleInline, StreamInline]
|
||||
|
||||
|
||||
@admin.register(Schedule)
|
||||
class ScheduleAdmin(admin.ModelAdmin):
|
||||
def program_name(self, obj):
|
||||
return obj.program.name
|
||||
program_name.short_description = _('Program')
|
||||
|
||||
def day(self, obj):
|
||||
return '' # obj.date.strftime('%A')
|
||||
day.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 = ['id', 'program_name', 'frequency', 'day', 'date',
|
||||
'time', 'duration', 'timezone', 'rerun']
|
||||
list_editable = ['time', 'timezone', 'duration']
|
||||
|
||||
def get_readonly_fields(self, request, obj=None):
|
||||
if obj:
|
||||
return ['program', 'date', 'frequency']
|
||||
else:
|
||||
return []
|
||||
|
||||
# TODO: sort & redo
|
||||
class PortInline(admin.StackedInline):
|
||||
model = Port
|
||||
extra = 0
|
||||
|
||||
|
||||
@admin.register(Station)
|
||||
class StationAdmin(admin.ModelAdmin):
|
||||
prepopulated_fields = {'slug': ('name',)}
|
||||
inlines = [PortInline]
|
||||
|
||||
|
||||
@admin.register(Log)
|
||||
class LogAdmin(admin.ModelAdmin):
|
||||
list_display = ['id', 'date', 'station', 'source', 'type', 'diffusion', 'sound', 'track']
|
||||
list_filter = ['date', 'source', 'station']
|
||||
|
||||
admin.site.register(Port)
|
||||
|
||||
|
||||
|
||||
|
@ -9,7 +9,7 @@ from .playlist import TracksInline
|
||||
class SoundInline(admin.TabularInline):
|
||||
model = Sound
|
||||
fk_name = 'diffusion'
|
||||
fields = ['type', 'path', 'duration','public']
|
||||
fields = ['type', 'path', 'duration', 'is_public']
|
||||
readonly_fields = ['type']
|
||||
extra = 0
|
||||
|
||||
|
82
aircox/admin/episode.py
Normal file
82
aircox/admin/episode.py
Normal file
@ -0,0 +1,82 @@
|
||||
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 .playlist import 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']
|
||||
|
||||
def get_object(self, *args, **kwargs):
|
||||
"""
|
||||
We want rerun to redirect to the given object.
|
||||
"""
|
||||
obj = super().get_object(*args, **kwargs)
|
||||
if obj and obj.initial:
|
||||
obj = obj.initial
|
||||
return obj
|
||||
|
||||
def get_queryset(self, request):
|
||||
qs = super().get_queryset(request)
|
||||
if request.GET and len(request.GET):
|
||||
return qs
|
||||
return qs.exclude(type=Diffusion.Type.unconfirmed)
|
||||
|
||||
|
||||
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')
|
||||
|
||||
|
||||
class SoundInline(admin.TabularInline):
|
||||
model = Sound
|
||||
fk_name = 'episode'
|
||||
fields = ['type', 'path', 'duration', 'is_public']
|
||||
readonly_fields = ['type']
|
||||
extra = 0
|
||||
|
||||
|
||||
@admin.register(Episode)
|
||||
class EpisodeAdmin(PageAdmin):
|
||||
list_display = PageAdmin.list_display + ('program',)
|
||||
list_filter = ('program',)
|
||||
readonly_fields = ('program',)
|
||||
|
||||
fieldsets = copy.deepcopy(PageAdmin.fieldsets)
|
||||
fieldsets[1][1]['fields'].insert(0, 'program')
|
||||
inlines = [TracksInline, SoundInline, DiffusionInline]
|
||||
|
||||
|
28
aircox/admin/page.py
Normal file
28
aircox/admin/page.py
Normal file
@ -0,0 +1,28 @@
|
||||
from django.contrib import admin
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
||||
class PageAdmin(admin.ModelAdmin):
|
||||
list_display = ('cover_thumb', 'title', 'status')
|
||||
list_display_links = ('cover_thumb', 'title')
|
||||
list_editable = ('status',)
|
||||
prepopulated_fields = {"slug": ("title",)}
|
||||
|
||||
fieldsets = [
|
||||
('', {
|
||||
'fields': ['title', 'slug', 'cover', 'content'],
|
||||
}),
|
||||
(_('Publication Settings'), {
|
||||
'fields': ['featured', 'allow_comments', 'status'],
|
||||
'classes': ('collapse',),
|
||||
}),
|
||||
]
|
||||
|
||||
def cover_thumb(self, obj):
|
||||
return mark_safe('<img src="{}"/>'.format(obj.cover.icons['64'])) \
|
||||
if obj.cover else ''
|
||||
|
||||
|
||||
|
||||
|
@ -21,19 +21,19 @@ 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', 'diffusion', 'sound', 'timestamp']
|
||||
list_display = ['pk', 'artist', 'title', 'tag_list', 'episode', 'sound', 'timestamp']
|
||||
list_editable = ['artist', 'title']
|
||||
list_filter = ['sound', 'diffusion', 'artist', 'title', 'tags']
|
||||
list_filter = ['sound', 'episode', 'artist', 'title', 'tags']
|
||||
fieldsets = [
|
||||
(_('Playlist'), {'fields': ['diffusion', 'sound', 'position', 'timestamp']}),
|
||||
(_('Playlist'), {'fields': ['episode', 'sound', 'position', 'timestamp']}),
|
||||
(_('Info'), {'fields': ['artist', 'title', 'info', 'tags']}),
|
||||
]
|
||||
|
||||
# TODO on edit: readonly_fields = ['diffusion', 'sound']
|
||||
# TODO on edit: readonly_fields = ['episode', 'sound']
|
||||
|
||||
#@admin.register(Playlist)
|
||||
#class PlaylistAdmin(admin.ModelAdmin):
|
||||
# fields = ['diffusion', 'sound']
|
||||
# fields = ['episode', 'sound']
|
||||
# inlines = [TracksInline]
|
||||
# # TODO: dynamic read only fields
|
||||
|
||||
|
75
aircox/admin/program.py
Normal file
75
aircox/admin/program.py
Normal file
@ -0,0 +1,75 @@
|
||||
from copy import deepcopy
|
||||
|
||||
from django.contrib import admin
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from aircox.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')
|
||||
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')
|
||||
|
||||
|
||||
|
@ -7,12 +7,16 @@ from .playlist import TracksInline
|
||||
|
||||
@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', 'mtime',
|
||||
'is_public', 'is_good_quality', 'path']
|
||||
list_display = ['id', 'name', 'program', 'type', 'duration',
|
||||
'is_public', 'is_good_quality', 'episode', 'filename']
|
||||
list_filter = ('program', 'type', 'is_good_quality', 'is_public')
|
||||
fieldsets = [
|
||||
(None, {'fields': ['name', 'path', 'type', 'program', 'diffusion']}),
|
||||
(None, {'fields': ['name', 'path', 'type', 'program', 'episode']}),
|
||||
(None, {'fields': ['embed', 'duration', 'is_public', 'mtime']}),
|
||||
(None, {'fields': ['is_good_quality']})
|
||||
]
|
||||
|
Reference in New Issue
Block a user