diff --git a/program/admin.py b/program/admin.py index 57597c60cf0e7eb4ad2e6679292f24e4acb6ed90..9db5ccc8699871a6202631ae83bbf73adf49fdf2 100644 --- a/program/admin.py +++ b/program/admin.py @@ -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' ) diff --git a/program/models.py b/program/models.py index c6c706596294cf4d19174616f9ba772d9e3ef10c..def5d0b694e3a89eb74fed90f4c5a0f6c5383706 100644 --- a/program/models.py +++ b/program/models.py @@ -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',) diff --git a/program/serializers.py b/program/serializers.py index b2ec91a69ff4f6090e8200b056f0275abf2ffe09..779316f4100e78f65b42f3cbd7ea7367c2ab7509 100644 --- a/program/serializers.py +++ b/program/serializers.py @@ -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 diff --git a/program/views.py b/program/views.py index d99e828da318756f3927e9ab1da59c8192ffe8b9..bace06fe6246de8b1e4a7952d1e6ef4157b74854 100644 --- a/program/views.py +++ b/program/views.py @@ -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'''