diff --git a/fixtures/program/show.json b/fixtures/program/show.json index ba2a701bb482b0c7c817b7222e7dcb0351939e70..778075b642628d57792d4c88036a2a066fac7eea 100644 --- a/fixtures/program/show.json +++ b/fixtures/program/show.json @@ -5,7 +5,7 @@ "fields": { "predecessor": null, "type": 3, - "fundingcategory": 1, + "funding_category": 1, "name": "Musikprogramm", "slug": "musikprogramm", "ppoi": "0.5x0.5", @@ -28,7 +28,7 @@ "language": [], "category": [], "topic": [], - "musicfocus": [] + "music_focus": [] } } ] diff --git a/program/migrations/0016_auto_20220222_0209.py b/program/migrations/0016_auto_20220222_0209.py new file mode 100644 index 0000000000000000000000000000000000000000..84ca864ed749ed69c6bf735189e7aa904703e0f6 --- /dev/null +++ b/program/migrations/0016_auto_20220222_0209.py @@ -0,0 +1,23 @@ +# Generated by Django 3.2.11 on 2022-02-22 01:09 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('program', '0015_rename_bysetpos_rrule_by_set_pos'), + ] + + operations = [ + migrations.RenameField( + model_name='show', + old_name='fundingcategory', + new_name='funding_category', + ), + migrations.RenameField( + model_name='show', + old_name='musicfocus', + new_name='music_focus', + ), + ] diff --git a/program/models.py b/program/models.py index 283902b30e1fdbe16050fed173f20cd2489c5c0f..17168f64f62c05cbc97566de6dfa4a6bb0af7194 100644 --- a/program/models.py +++ b/program/models.py @@ -143,9 +143,9 @@ class Show(models.Model): language = models.ManyToManyField(Language, blank=True, related_name='language') type = models.ForeignKey(Type, on_delete=models.CASCADE, related_name='shows') category = models.ManyToManyField(Category, blank=True, related_name='shows') - fundingcategory = models.ForeignKey(FundingCategory, null=True, on_delete=models.CASCADE, blank=True, related_name='shows') + funding_category = models.ForeignKey(FundingCategory, null=True, on_delete=models.CASCADE, blank=True, related_name='shows') topic = models.ManyToManyField(Topic, blank=True, related_name='shows') - musicfocus = models.ManyToManyField(MusicFocus, blank=True, related_name='shows') + music_focus = models.ManyToManyField(MusicFocus, blank=True, related_name='shows') name = models.CharField(max_length=255) slug = models.CharField(max_length=255, unique=True) ppoi = PPOIField() @@ -211,7 +211,6 @@ class Schedule(models.Model): @staticmethod def instantiate_upcoming(sdl, show_pk, pk=None): """Returns an upcoming schedule instance for conflict resolution""" - pk = int(pk) if pk is not None else None rrule = RRule.objects.get(pk=int(sdl['rrule'])) show = Show.objects.get(pk=int(show_pk)) @@ -222,7 +221,6 @@ class Schedule(models.Model): add_business_days_only = True if sdl.get('add_business_days_only') is True else False dstart = parse_date(str(sdl['dstart'])) - # Schedule mustn't start in the past when adding if pk is None and dstart < timezone.now().date(): dstart = timezone.now().date() @@ -267,7 +265,6 @@ class Schedule(models.Model): starts = [] ends = [] timeslots = [] - # Handle ending weekday for timeslots over midnight if schedule.tend < schedule.tstart: if schedule.byweekday < 6: diff --git a/program/serializers.py b/program/serializers.py index 6c1ea2ad4cfadb7e1b1da1d9992cbe49edd25f2c..7f8c218e9ccdd48892668c67ef937384c975c05a 100644 --- a/program/serializers.py +++ b/program/serializers.py @@ -211,9 +211,11 @@ class ShowSerializer(serializers.HyperlinkedModelSerializer): hosts = serializers.PrimaryKeyRelatedField(queryset=Host.objects.all(), many=True) language = serializers.PrimaryKeyRelatedField(queryset=Language.objects.all(), many=True) topic = serializers.PrimaryKeyRelatedField(queryset=Topic.objects.all(), many=True) - musicfocus = serializers.PrimaryKeyRelatedField(queryset=MusicFocus.objects.all(), many=True) + # TODO: replace `musicfocs` with `music_focus` and remove the source when the dashboard in updated + musicfocus = serializers.PrimaryKeyRelatedField(queryset=MusicFocus.objects.all(), source='music_focus', many=True) type = serializers.PrimaryKeyRelatedField(queryset=Type.objects.all()) - fundingcategory = serializers.PrimaryKeyRelatedField(queryset=FundingCategory.objects.all()) + # TODO: replace `fundingcategory` with `funding_category` and remove the source when the dashboard is updated + fundingcategory = serializers.PrimaryKeyRelatedField(queryset=FundingCategory.objects.all(), source='funding_category') predecessor = serializers.PrimaryKeyRelatedField(queryset=Show.objects.all(), required=False, allow_null=True) thumbnails = serializers.SerializerMethodField() # Read-only @@ -245,7 +247,8 @@ class ShowSerializer(serializers.HyperlinkedModelSerializer): hosts = validated_data.pop('hosts') language = validated_data.pop('language') topic = validated_data.pop('topic') - musicfocus = validated_data.pop('musicfocus') + # TODO: replace `musicfocus` with `music_focus` when the dashboard is updated + music_focus = validated_data.pop('musicfocus') show = Show.objects.create(**validated_data) @@ -255,7 +258,7 @@ class ShowSerializer(serializers.HyperlinkedModelSerializer): show.hosts.set(hosts) show.language.set(language) show.topic.set(topic) - show.musicfocus.set(musicfocus) + show.music_focus.set(music_focus) show.save() return show @@ -282,9 +285,11 @@ class ShowSerializer(serializers.HyperlinkedModelSerializer): instance.hosts.set(validated_data.get('hosts', instance.hosts)) instance.language.set(validated_data.get('language', instance.language)) instance.topic.set(validated_data.get('topic', instance.topic)) - instance.musicfocus.set(validated_data.get('musicfocus', instance.musicfocus)) + # TODO: replace `musicfocs` with `music_focus` when the dashboard in updated + instance.music_focus.set(validated_data.get('musicfocus', instance.musicfocus)) instance.type = validated_data.get('type', instance.type) - instance.fundingcategory = validated_data.get('fundingcategory', instance.fundingcategory) + # TODO: replace `fundingcategory` with `funding_category` when the dashboard is updated + instance.funding_category = 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.is_public = validated_data.get('is_public', instance.is_public) diff --git a/program/views.py b/program/views.py index ead86f4ade06ffeea19fe7b4004f97d250674a4f..9de565b9269f5e7da135189f100eb4dd8ee9d86b 100644 --- a/program/views.py +++ b/program/views.py @@ -90,18 +90,14 @@ def json_playout(request): schedule = [] for ts in timeslots: - is_repetition = ' ' + _('REP') if ts.schedule.is_repetition is True else '' hosts = ', '.join(ts.show.hosts.values_list('name', flat=True)) - categories = ', '.join(ts.show.category.values_list('category', flat=True)) - topics = ', '.join(ts.show.topic.values_list('topic', flat=True)) - musicfocus = ', '.join(ts.show.musicfocus.values_list('focus', flat=True)) + categories = ', '.join(ts.show.category.values_list('name', flat=True)) + topics = ', '.join(ts.show.topic.values_list('name', flat=True)) + music_focus = ', '.join(ts.show.music_focus.values_list('name', flat=True)) languages = ', '.join(ts.show.language.values_list('name', flat=True)) - fdcategory = None - if ts.show.fundingcategory_id: - fundingcategory = FundingCategory.objects.get(pk=ts.show.fundingcategory_id) - fdcategory = fundingcategory.fundingcategory + funding_category = FundingCategory.objects.get(pk=ts.show.funding_category_id) if ts.show.funding_category_id else None type_ = Type.objects.get(pk=ts.show.type_id) @@ -126,9 +122,11 @@ def json_playout(request): 'show_type': type_.type, 'show_categories': categories, 'show_topics': topics, - 'show_musicfocus': musicfocus, + # TODO: replace `show_musicfocus` with `show_music_focus` when engine is updated + 'show_musicfocus': music_focus, 'show_languages': languages, - 'show_fundingcategory': fdcategory, + # TODO: replace `show_fundingcategory` with `show_funding_category` when engine is updated + 'show_fundingcategory': funding_category, 'memo': ts.memo, 'className': classname, } @@ -311,9 +309,10 @@ class APIShowViewSet(viewsets.ModelViewSet): if topic != 'undefined': shows = shows.filter(topic__in=[int(topic)]) - if musicfocus := self.request.query_params.get('musicfocus'): - if musicfocus != 'undefined': - shows = shows.filter(musicfocus__in=[int(musicfocus)]) + # TODO: replace `musicfocus` with `music_focus` when dashboard is updated + if music_focus := self.request.query_params.get('musicfocus'): + if music_focus != 'undefined': + shows = shows.filter(music_focus__in=[int(music_focus)]) return shows