change strategy on liquidsoap logging

This commit is contained in:
bkfox
2015-12-16 21:09:21 +01:00
parent 1a71aeb166
commit f03acb4c1b
22 changed files with 115 additions and 86 deletions

View File

@ -100,7 +100,7 @@ class DiffusionAdmin (admin.ModelAdmin):
else:
self.readonly_fields = ['program', 'date', 'duration']
if obj.initial:
if obj and obj.initial:
self.readonly_fields += ['program', 'sounds']
return super().get_form(request, obj, **kwargs)

View File

@ -639,13 +639,9 @@ class Log (models.Model):
help_text = 'source information',
blank = True, null = True,
)
sound = models.ForeignKey(
'Sound',
help_text = _('played sound'),
blank = True, null = True,
)
date = models.DateTimeField(
'date',
auto_now_add=True,
)
comment = models.CharField(
max_length = 512,
@ -662,12 +658,20 @@ class Log (models.Model):
'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):
print(str(self), ':', self.comment or '')
if self.diffusion:
print(' - diffusion #' + str(self.diffusion.id))
if self.sound:
print(' - sound #' + str(self.sound.id), self.sound.path)
if self.related_object:
print(' - {}: #{}'.format(self.related_type,
self.related_id))
def __str__ (self):
return self.date.strftime('%Y-%m-%d %H:%M') + ', ' + self.source