start app controllers that aims to replace liquidsoap on long term, and be more generic and reusable

This commit is contained in:
bkfox
2016-07-12 11:11:21 +02:00
parent 37b807b403
commit 0d75f65ed4
12 changed files with 988 additions and 87 deletions

View File

@ -147,12 +147,6 @@ class DiffusionAdmin(admin.ModelAdmin):
return qs.exclude(type = Diffusion.Type.unconfirmed)
@admin.register(Log)
class LogAdmin(admin.ModelAdmin):
list_display = ['id', 'date', 'source', 'comment', 'related_object']
list_filter = ['date', 'source', 'related_type']
@admin.register(Schedule)
class ScheduleAdmin(admin.ModelAdmin):
def program_name(self, obj):

View File

@ -713,77 +713,3 @@ class Diffusion(models.Model):
('programming', _('edit the diffusion\'s planification')),
)
class Log(models.Model):
"""
Log sounds and diffusions that are played in the streamer. It
can also be used for other purposes.
"""
class Type(IntEnum):
stop = 0x00
"""
Source has been stopped (only when there is no more sound)
"""
play = 0x01
"""
Source has been started/changed and is running related_object
If no related_object is available, comment is used to designate
the sound.
"""
load = 0x02
"""
Source starts to be preload related_object
"""
type = models.SmallIntegerField(
verbose_name = _('type'),
choices = [ (int(y), _(x)) for x,y in Type.__members__.items() ],
blank = True, null = True,
)
source = models.CharField(
_('source'),
max_length = 64,
help_text = 'source information',
blank = True, null = True,
)
date = models.DateTimeField(
_('date'),
auto_now_add=True,
)
comment = models.CharField(
_('comment'),
max_length = 512,
blank = True, null = True,
)
related_type = models.ForeignKey(
ContentType,
blank = True, null = True,
)
related_id = models.PositiveIntegerField(
blank = True, null = True,
)
related_object = GenericForeignKey(
'related_type', 'related_id',
)
@classmethod
def get_for_related_model(cl, model):
"""
Return a queryset that filter related_type to the given one.
"""
return cl.objects.filter(related_type__pk =
ContentType.objects.get_for_model(model).id)
def print(self):
logger.info('log #%s: %s%s',
str(self),
self.comment or '',
' -- {} #{}'.format(self.related_type, self.related_id)
if self.related_object else ''
)
def __str__(self):
return '#{} ({}, {})'.format(
self.id, self.date.strftime('%Y-%m-%d %H:%M'), self.source
)