forked from rc/aircox
cfr #121 Co-authored-by: Christophe Siraut <d@tobald.eu.org> Co-authored-by: bkfox <thomas bkfox net> Co-authored-by: Thomas Kairos <thomas@bkfox.net> Reviewed-on: rc/aircox#131 Co-authored-by: Chris Tactic <ctactic@noreply.git.radiocampus.be> Co-committed-by: Chris Tactic <ctactic@noreply.git.radiocampus.be>
49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
from django.contrib import admin
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
from aircox.models import Program, Schedule, Stream
|
|
from .page import PageAdmin
|
|
from .schedule import ScheduleInline
|
|
|
|
|
|
__all__ = (
|
|
"ProgramAdmin",
|
|
"StreamInline",
|
|
)
|
|
|
|
|
|
class StreamInline(admin.TabularInline):
|
|
model = Stream
|
|
fields = ["delay", "begin", "end"]
|
|
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")
|
|
prepopulated_fields = {"slug": ("title",)}
|
|
search_fields = ("title",)
|
|
ordering = ("title",)
|
|
|
|
inlines = [ScheduleInline, StreamInline]
|
|
|
|
def get_fieldsets(self, request, obj=None):
|
|
fields = super().get_fieldsets(request, obj)
|
|
if request.user.has_perm("aircox.program.scheduling"):
|
|
fields = fields + [
|
|
(
|
|
_("Program Settings"),
|
|
{
|
|
"fields": ["active", "station", "sync"],
|
|
},
|
|
)
|
|
]
|
|
return fields
|