add sound item in diffusions; move programs.Sound's attribute 'remove' into the type + update its public attribute based on diffusion publication

This commit is contained in:
bkfox
2016-07-28 16:21:01 +02:00
parent 502af1dba0
commit 801a89e503
9 changed files with 123 additions and 31 deletions

View File

@ -418,6 +418,11 @@ class DiffusionPage(Publication):
'initial__isnull': True,
},
)
publish_archive = models.BooleanField(
_('publish archive'),
default = False,
help_text = _('publish the podcast of the complete diffusion'),
)
class Meta:
verbose_name = _('Diffusion')
@ -425,11 +430,11 @@ class DiffusionPage(Publication):
content_panels = [
FieldPanel('diffusion'),
FieldPanel('publish_archive'),
] + Publication.content_panels + [
InlinePanel('tracks', label=_('Tracks')),
]
@classmethod
def from_diffusion(cl, diff, model = None, **kwargs):
model = model or cl
@ -470,9 +475,50 @@ class DiffusionPage(Publication):
item.css_class = 'diffusion'
return item
def get_archive(self):
if not self.publish_archive:
return
sound = self.diffusion.get_archives() \
.filter(public = True).first()
if sound:
sound.detail_url = self.detail_url
return sound
def get_podcasts(self):
"""
Return a list of podcasts, with archive as the first item of the
list when available.
"""
podcasts = []
archive = self.get_archive()
if archive:
podcasts.append(archive)
qs = self.diffusion.get_excerpts().filter(public = True)
podcasts.extend(qs[:])
for podcast in podcasts:
podcast.detail_url = self.url
return podcasts
def save(self, *args, **kwargs):
# TODO: update public attribute of the archive + podcasts check if live
if self.diffusion:
self.date = self.diffusion.start
# update podcasts' attributes
for podcast in self.diffusion.sound_set \
.exclude(type = programs.Sound.Type.removed):
publish = self.live and self.publish_archive \
if podcast.type == podcast.Type.archive else self.live
if podcast.public != publish:
podcast.public = publish
podcast.save()
super().save(*args, **kwargs)