forked from rc/aircox
		
	work on logging
This commit is contained in:
		@ -90,6 +90,20 @@ class DiffusionAdmin (admin.ModelAdmin):
 | 
			
		||||
    list_filter = ('type', 'date', 'program')
 | 
			
		||||
    list_editable = ('type', 'date')
 | 
			
		||||
 | 
			
		||||
    fields = ['type', 'date', 'initial', 'sounds', 'program']
 | 
			
		||||
    readonly_fields = ('duration',)
 | 
			
		||||
 | 
			
		||||
    def get_form(self, request, obj=None, **kwargs):
 | 
			
		||||
        if obj:
 | 
			
		||||
            if obj.date < tz.make_aware(tz.datetime.now()):
 | 
			
		||||
                self.readonly_fields = list(self.fields)
 | 
			
		||||
                self.readonly_fields.remove('type')
 | 
			
		||||
            elif obj.initial:
 | 
			
		||||
                self.readonly_fields = ['program', 'sounds']
 | 
			
		||||
            else:
 | 
			
		||||
                self.readonly_fields = []
 | 
			
		||||
        return super().get_form(request, obj, **kwargs)
 | 
			
		||||
 | 
			
		||||
    def get_queryset(self, request):
 | 
			
		||||
        qs = super(DiffusionAdmin, self).get_queryset(request)
 | 
			
		||||
        if '_changelist_filters' in request.GET or \
 | 
			
		||||
 | 
			
		||||
@ -396,32 +396,6 @@ class Schedule (models.Model):
 | 
			
		||||
        verbose_name_plural = _('Schedules')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Log (models.Model):
 | 
			
		||||
    """
 | 
			
		||||
    Log a played sound start and stop, or a single message
 | 
			
		||||
    """
 | 
			
		||||
    sound = models.ForeignKey(
 | 
			
		||||
        'Sound',
 | 
			
		||||
        help_text = 'Played sound',
 | 
			
		||||
        blank = True, null = True,
 | 
			
		||||
    )
 | 
			
		||||
    stream = models.ForeignKey(
 | 
			
		||||
        'Stream',
 | 
			
		||||
        blank = True, null = True,
 | 
			
		||||
    )
 | 
			
		||||
    start = models.DateTimeField(
 | 
			
		||||
        'start',
 | 
			
		||||
    )
 | 
			
		||||
    stop = models.DateTimeField(
 | 
			
		||||
        'stop',
 | 
			
		||||
        blank = True, null = True,
 | 
			
		||||
    )
 | 
			
		||||
    comment = models.CharField(
 | 
			
		||||
        max_length = 512,
 | 
			
		||||
        blank = True, null = True,
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Station (Nameable):
 | 
			
		||||
    """
 | 
			
		||||
    A Station regroup one or more programs (stream and normal), and is the top
 | 
			
		||||
@ -607,11 +581,51 @@ class Diffusion (models.Model):
 | 
			
		||||
        super(Diffusion, self).save(*args, **kwargs)
 | 
			
		||||
 | 
			
		||||
    def __str__ (self):
 | 
			
		||||
        return self.program.name + ' on ' + str(self.date) \
 | 
			
		||||
               + str(self.type)
 | 
			
		||||
        return self.program.name + ', ' + \
 | 
			
		||||
                self.date.strftime('%Y-%m-%d %H:%M') +\
 | 
			
		||||
                '' # FIXME str(self.type_display)
 | 
			
		||||
 | 
			
		||||
    class Meta:
 | 
			
		||||
        verbose_name = _('Diffusion')
 | 
			
		||||
        verbose_name_plural = _('Diffusions')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Log (models.Model):
 | 
			
		||||
    """
 | 
			
		||||
    Log a played sound start and stop, or a single message
 | 
			
		||||
    """
 | 
			
		||||
    source = models.CharField(
 | 
			
		||||
        _('source'),
 | 
			
		||||
        max_length = 64,
 | 
			
		||||
        help_text = 'source information',
 | 
			
		||||
        blank = True, null = True,
 | 
			
		||||
    )
 | 
			
		||||
    diffusion = models.ForeignKey(
 | 
			
		||||
        'Diffusion',
 | 
			
		||||
        help_text = _('related diffusion'),
 | 
			
		||||
        blank = True, null = True,
 | 
			
		||||
    )
 | 
			
		||||
    sound = models.ForeignKey(
 | 
			
		||||
        'Sound',
 | 
			
		||||
        help_text = _('played sound'),
 | 
			
		||||
        blank = True, null = True,
 | 
			
		||||
    )
 | 
			
		||||
    date = models.DateTimeField(
 | 
			
		||||
        'date',
 | 
			
		||||
    )
 | 
			
		||||
    comment = models.CharField(
 | 
			
		||||
        max_length = 512,
 | 
			
		||||
        blank = True, null = True,
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    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)
 | 
			
		||||
 | 
			
		||||
    def __str__ (self):
 | 
			
		||||
        return self.date.strftime('%Y-%m-%d %H:%M') + ', ' + self.source
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user