Commit 1a9ac197 authored by Ingo Leindecker's avatar Ingo Leindecker
Browse files

Show Model:

- Field "FundingCategory" is not mandatory anymore
- Added new field "is_active": Active shows will be determined either by existing timeslots in the future (if show is active). If show is not active it will always be considered as inactive, even if there are upcoming timeslots.
parent ba140e6d
......@@ -231,7 +231,7 @@ class ShowAdmin(admin.ModelAdmin):
fields = (
'predecessor', 'type', 'name', 'slug', 'image', 'logo', 'short_description', 'description',
'email', 'website', 'hosts', 'owners', 'language', 'category', 'fundingcategory', 'topic',
'musicfocus', 'fallback_id', 'cba_series_id',
'musicfocus', 'fallback_id', 'cba_series_id', 'is_active'
)
......
......@@ -307,7 +307,7 @@ class Show(models.Model):
language = models.ManyToManyField(Language, blank=True, related_name='language', verbose_name=_("Language"))
type = models.ForeignKey(Type, related_name='shows', verbose_name=_("Type"))
category = models.ManyToManyField(Category, blank=True, related_name='shows', verbose_name=_("Category"))
fundingcategory = models.ForeignKey(FundingCategory, related_name='shows', verbose_name=_("Funding Category"))
fundingcategory = models.ForeignKey(FundingCategory, null=True, blank=True, related_name='shows', verbose_name=_("Funding Category"))
topic = models.ManyToManyField(Topic, blank=True, related_name='shows', verbose_name=_("Topic"))
musicfocus = models.ManyToManyField(MusicFocus, blank=True, related_name='shows', verbose_name=_("Music focus"))
name = models.CharField(_("Name"), max_length=255, help_text=_("The show's name. Avoid a subtitle."))
......@@ -325,6 +325,7 @@ class Show(models.Model):
fallback_id = models.IntegerField(_("Fallback ID"), blank=True, null=True, help_text=_("If a timeslot of your show is empty, this playlist will be aired as a backup."))
created = models.DateTimeField(auto_now_add=True, editable=False)
last_updated = models.DateTimeField(auto_now=True, editable=False)
is_active = models.BooleanField(_("Is active?"), default=True)
class Meta:
ordering = ('slug',)
......
......@@ -256,7 +256,7 @@ class ShowSerializer(serializers.HyperlinkedModelSerializer):
fields = ('id', 'name', 'slug', 'image', 'ppoi', 'logo', 'short_description', 'description',
'email', 'website', 'created', 'last_updated', 'type', 'fundingcategory',
'predecessor', 'cba_series_id', 'fallback_id', 'category', 'hosts',
'owners', 'language', 'topic', 'musicfocus', 'thumbnails')
'owners', 'language', 'topic', 'musicfocus', 'thumbnails', 'is_active')
def create(self, validated_data):
......@@ -315,6 +315,7 @@ class ShowSerializer(serializers.HyperlinkedModelSerializer):
instance.type = validated_data.get('type', instance.type)
instance.fundingcategory = validated_data.get('fundingcategory', instance.fundingcategory)
instance.predecessor = validated_data.get('predecessor', instance.predecessor)
instance.is_active = validated_data.get('is_active', instance.is_active)
instance.save()
return instance
......
......@@ -280,7 +280,11 @@ def json_playout(request):
topics = ', '.join(ts.show.topic.values_list('topic', flat=True))
musicfocus = ', '.join(ts.show.musicfocus.values_list('focus', flat=True))
languages = ', '.join(ts.show.language.values_list('name', flat=True))
fundingcategory = FundingCategory.objects.get(pk=ts.show.fundingcategory_id)
fdcategory = None
if ts.show.fundingcategory_id is not None:
fundingcategory = FundingCategory.objects.get(pk=ts.show.fundingcategory_id)
fdcategory = fundingcategory.fundingcategory
type = Type.objects.get(pk=ts.show.type_id)
classname = 'default'
......@@ -307,7 +311,7 @@ def json_playout(request):
'show_topics': topics,
'show_musicfocus': musicfocus,
'show_languages': languages,
'show_fundingcategory': fundingcategory.fundingcategory,
'show_fundingcategory': fdcategory,
'station_fallback_id': STATION_FALLBACK_ID, # TODO: Find a better way than getting it from the settings
'memo': ts.memo,
'className': classname,
......@@ -477,11 +481,13 @@ class APIShowViewSet(viewsets.ModelViewSet):
Q(rrule_id=1,dstart__gte=date.today())
).distinct().values_list('show_id', flat=True)
shows = Show.objects.filter(id__in=show_ids)
# Filter active shows based on timeslots as well as on the is_active flag
# Even if there are future timeslots but is_active=True the show will be considered as inactive
shows = Show.objects.filter(id__in=show_ids,is_active=True)
if self.request.GET.get('active') == 'false':
'''Return all shows except those which are running'''
shows = Show.objects.exclude(id__in=show_ids)
shows = Show.objects.exclude(id__in=show_ids,is_active=True)
if self.request.GET.get('owner') != None:
'''Filter shows by owner'''
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment