From 8fa0d03d3509290ea6f523c2223966b1a2b73488 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Wed, 17 Feb 2021 14:33:49 +0100 Subject: add language to model diff --git a/program/admin.py b/program/admin.py index eb55554..d5be9a1 100644 --- a/program/admin.py +++ b/program/admin.py @@ -1,7 +1,7 @@ from django.contrib import admin from django.utils.translation import ugettext_lazy as _ -from models import BroadcastFormat, MusicFocus, ShowInformation, ShowTopic, Host, Note, ProgramSlot, Show, TimeSlot +from models import BroadcastFormat, MusicFocus, ShowInformation, ShowTopic, Language, Host, Note, ProgramSlot, Show, TimeSlot from forms import MusicFocusForm from datetime import date, datetime, timedelta @@ -69,6 +69,10 @@ class ShowTopicAdmin(admin.ModelAdmin): prepopulated_fields = {'slug': ('topic',)} +class LanguageAdmin(admin.ModelAdmin): + list_display = ('name', 'native_name') + + class HostAdmin(admin.ModelAdmin): list_display = ('name',) list_filter = (ActiveHostsFilter, 'is_always_visible',) @@ -142,16 +146,16 @@ class ProgramSlotInline(admin.TabularInline): class ShowAdmin(admin.ModelAdmin): - filter_horizontal = ('hosts', 'owners', 'musicfocus', 'showinformation', 'showtopic') + filter_horizontal = ('hosts', 'owners', 'musicfocus', 'showinformation', 'showtopic', 'language') inlines = (ProgramSlotInline,) list_display = ('name', 'short_description') - list_filter = (ActiveShowsFilter, 'broadcastformat', 'showinformation', 'showtopic', 'musicfocus') + list_filter = (ActiveShowsFilter, 'broadcastformat', 'showinformation', 'showtopic', 'musicfocus', 'language') ordering = ('slug',) prepopulated_fields = {'slug': ('name',)} search_fields = ('name', 'short_description', 'description') fields = ( 'predecessor', 'broadcastformat', 'name', 'slug', 'image', 'image_enabled', 'short_description', 'description', - 'email', 'website', 'hosts', 'owners', 'showinformation', 'showtopic', + 'email', 'website', 'hosts', 'owners', 'showinformation', 'showtopic', 'language', 'musicfocus', ) @@ -166,10 +170,12 @@ class ShowAdmin(admin.ModelAdmin): return super(ShowAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs) + admin.site.register(BroadcastFormat, BroadcastFormatAdmin) admin.site.register(MusicFocus, MusicFocusAdmin) admin.site.register(ShowInformation, ShowInformationAdmin) admin.site.register(ShowTopic, ShowTopicAdmin) +admin.site.register(Language, LanguageAdmin) admin.site.register(Host, HostAdmin) admin.site.register(Note, NoteAdmin) admin.site.register(ProgramSlot, ProgramSlotAdmin) diff --git a/program/migrations/0012_add_language.py b/program/migrations/0012_add_language.py new file mode 100644 index 0000000..59be77d --- /dev/null +++ b/program/migrations/0012_add_language.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('program', '0011_programslot_remove_is_active'), + ] + + operations = [ + migrations.CreateModel( + name='Language', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('name', models.CharField(max_length=32, verbose_name='Language')), + ('native_name', models.CharField(max_length=32, verbose_name='Native Name')), + ], + options={ + 'ordering': ('language',), + 'verbose_name': 'Language', + 'verbose_name_plural': 'Languages', + }, + ), + migrations.AddField( + model_name='show', + name='language', + field=models.ManyToManyField(related_name='language', verbose_name='Language', to='program.Language', blank=True), + ), + ] diff --git a/program/models.py b/program/models.py index d52d1bf..dd6cac4 100644 --- a/program/models.py +++ b/program/models.py @@ -208,6 +208,19 @@ class MusicFocus(models.Model): return u'%s' % self.focus +class Language(models.Model): + name = models.CharField(_("Language"), max_length=32) + native_name = models.CharField(_("Native Name"), max_length=32) + + class Meta: + ordering = ('language',) + verbose_name = _("Language") + verbose_name_plural = _("Languages") + + def __unicode__(self): + return '%s' % self.name + + class Host(models.Model): name = models.CharField(_("Name"), max_length=128) is_always_visible = models.BooleanField(_("Is always visible"), default=False) @@ -233,6 +246,7 @@ class Show(models.Model): predecessor = models.ForeignKey('self', blank=True, null=True, related_name='successors', verbose_name=_("Predecessor")) hosts = models.ManyToManyField(Host, blank=True, related_name='shows', verbose_name=_("Hosts")) owners = models.ManyToManyField(User, blank=True, related_name='shows', verbose_name=_("Owners")) + language = models.ManyToManyField(Language, blank=True, related_name='language', verbose_name=_("Language")) broadcastformat = models.ForeignKey(BroadcastFormat, related_name='shows', verbose_name=_("Broadcast format")) showinformation = models.ManyToManyField(ShowInformation, blank=True, related_name='shows', verbose_name=_("Show information")) showtopic = models.ManyToManyField(ShowTopic, blank=True, related_name='shows', verbose_name=_("Show topic")) -- cgit v0.10.2 From aafc069b9d6945138c2c2de1228f1a52c22d3c40 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Wed, 17 Feb 2021 18:50:37 +0100 Subject: fix model for new language field and add language filter to show list template diff --git a/program/migrations/0012_add_language.py b/program/migrations/0012_add_language.py index 59be77d..21d3c4f 100644 --- a/program/migrations/0012_add_language.py +++ b/program/migrations/0012_add_language.py @@ -15,7 +15,8 @@ class Migration(migrations.Migration): name='Language', fields=[ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), - ('name', models.CharField(max_length=32, verbose_name='Language')), + ('slug', models.SlugField(unique=True, max_length=32, verbose_name='Slug')), + ('name', models.CharField(max_length=32, verbose_name='Name')), ('native_name', models.CharField(max_length=32, verbose_name='Native Name')), ], options={ diff --git a/program/models.py b/program/models.py index dd6cac4..7951c35 100644 --- a/program/models.py +++ b/program/models.py @@ -209,11 +209,12 @@ class MusicFocus(models.Model): class Language(models.Model): - name = models.CharField(_("Language"), max_length=32) + slug = models.SlugField(_("Slug"), max_length=32, unique=True) + name = models.CharField(_("Name"), max_length=32) native_name = models.CharField(_("Native Name"), max_length=32) class Meta: - ordering = ('language',) + ordering = ('name',) verbose_name = _("Language") verbose_name_plural = _("Languages") @@ -246,7 +247,7 @@ class Show(models.Model): predecessor = models.ForeignKey('self', blank=True, null=True, related_name='successors', verbose_name=_("Predecessor")) hosts = models.ManyToManyField(Host, blank=True, related_name='shows', verbose_name=_("Hosts")) owners = models.ManyToManyField(User, blank=True, related_name='shows', verbose_name=_("Owners")) - language = models.ManyToManyField(Language, blank=True, related_name='language', verbose_name=_("Language")) + language = models.ManyToManyField(Language, blank=True, related_name='shows', verbose_name=_("Language")) broadcastformat = models.ForeignKey(BroadcastFormat, related_name='shows', verbose_name=_("Broadcast format")) showinformation = models.ManyToManyField(ShowInformation, blank=True, related_name='shows', verbose_name=_("Show information")) showtopic = models.ManyToManyField(ShowTopic, blank=True, related_name='shows', verbose_name=_("Show topic")) diff --git a/program/templates/boxes/language.html b/program/templates/boxes/language.html new file mode 100644 index 0000000..050c342 --- /dev/null +++ b/program/templates/boxes/language.html @@ -0,0 +1,15 @@ +{% if language_list %} +
+
Sprache
+
+ +
+
+{% endif %} diff --git a/program/templates/day_schedule.html b/program/templates/day_schedule.html index eb0d3d7..a117a10 100644 --- a/program/templates/day_schedule.html +++ b/program/templates/day_schedule.html @@ -46,6 +46,7 @@ {% musicfocus %} {% showinformation %} {% showtopic %} +{% language %} {% endcomment %} diff --git a/program/templates/show_list.html b/program/templates/show_list.html index d9b9a47..fc02872 100644 --- a/program/templates/show_list.html +++ b/program/templates/show_list.html @@ -15,6 +15,7 @@ {% musicfocus %} {% showinformation %} {% showtopic %} + {% language %}
diff --git a/program/templatetags/content_boxes.py b/program/templatetags/content_boxes.py index 2d1745e..ece466b 100644 --- a/program/templatetags/content_boxes.py +++ b/program/templatetags/content_boxes.py @@ -1,6 +1,6 @@ from django import template -from program.models import BroadcastFormat, MusicFocus, ShowInformation, ShowTopic +from program.models import BroadcastFormat, MusicFocus, ShowInformation, ShowTopic, Language register = template.Library() @@ -23,3 +23,8 @@ def showinformation(): @register.inclusion_tag('boxes/showtopic.html') def showtopic(): return {'showtopic_list': ShowTopic.objects.all()} + + +@register.inclusion_tag('boxes/language.html') +def language(): + return {'language_list': Language.objects.all()} diff --git a/program/views.py b/program/views.py index 365a4db..256ad5d 100644 --- a/program/views.py +++ b/program/views.py @@ -8,7 +8,7 @@ from django.views.generic.base import TemplateView from django.views.generic.detail import DetailView from django.views.generic.list import ListView -from models import BroadcastFormat, MusicFocus, Note, Show, ShowInformation, ShowTopic, TimeSlot, Host +from models import BroadcastFormat, MusicFocus, Note, Show, ShowInformation, ShowTopic, Language, TimeSlot, Host from program.utils import tofirstdayinisoweek, get_cached_shows @@ -43,6 +43,9 @@ class ShowListView(ListView): elif 'showtopic' in self.request.GET: showtopic = get_object_or_404(ShowTopic, slug=self.request.GET['showtopic']) queryset = queryset.filter(showtopic=showtopic) + elif 'language' in self.request.GET: + language = get_object_or_404(Language, slug=self.request.GET['language']) + queryset = queryset.filter(language=language) return queryset @@ -108,6 +111,9 @@ class DayScheduleView(TemplateView): elif 'showtopic' in self.request.GET: showtopic = get_object_or_404(ShowTopic, slug=self.request.GET['showtopic']) context['showtopic'] = timeslots.filter(show__showtopic=showtopic) + elif 'language' in self.request.GET: + language = get_object_or_404(Language, slug=self.request.GET['language']) + context['showtopic'] = timeslots.filter(show__language=language) else: context['timeslots'] = timeslots return context @@ -214,6 +220,7 @@ def json_day_schedule(request, year=None, month=None, day=None): return HttpResponse(json.dumps(schedule, ensure_ascii=False, encoding='utf8').encode('utf8'), content_type="application/json; charset=utf-8") + def json_timeslots_specials(request): specials = {} shows = get_cached_shows()['shows'] -- cgit v0.10.2 From 8a3cd771a51054107dd33ad77bb772adcc6d8ac0 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Wed, 17 Feb 2021 18:57:30 +0100 Subject: add fixtures for language diff --git a/program/fixtures/languages.yaml b/program/fixtures/languages.yaml new file mode 100644 index 0000000..f8f513b --- /dev/null +++ b/program/fixtures/languages.yaml @@ -0,0 +1,12 @@ +- model: program.language + pk: 1 + fields: + name: Deutsch + native_name: Deutsch + slug: de +- model: program.language + pk: 2 + fields: + name: Englisch + native_name: English + slug: en -- cgit v0.10.2 From 7360b58fbb96dfee255b07dd3275bd0329bf368d Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Wed, 24 Feb 2021 14:05:37 +0100 Subject: show language slug in admin view diff --git a/program/admin.py b/program/admin.py index d5be9a1..16d6973 100644 --- a/program/admin.py +++ b/program/admin.py @@ -70,7 +70,7 @@ class ShowTopicAdmin(admin.ModelAdmin): class LanguageAdmin(admin.ModelAdmin): - list_display = ('name', 'native_name') + list_display = ('slug', 'name', 'native_name') class HostAdmin(admin.ModelAdmin): -- cgit v0.10.2 From db5100338b42d55d68238bef3a6cd5199185b87f Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Wed, 24 Feb 2021 14:28:14 +0100 Subject: add more language fixtures diff --git a/program/fixtures/languages.yaml b/program/fixtures/languages.yaml index f8f513b..157bb9b 100644 --- a/program/fixtures/languages.yaml +++ b/program/fixtures/languages.yaml @@ -10,3 +10,81 @@ name: Englisch native_name: English slug: en +- model: program.language + pk: 3 + fields: + name: Ungarisch + native_name: Magyar + slug: hu +- model: program.language + pk: 4 + fields: + name: Italienisch + native_name: Italiano + slug: it +- model: program.language + pk: 5 + fields: + name: Spanisch + native_name: Español + slug: es +- model: program.language + pk: 6 + fields: + name: Rumänisch + native_name: Română + slug: ro +- model: program.language + pk: 7 + fields: + name: Französisch + native_name: Français + slug: fr +- model: program.language + pk: 8 + fields: + name: Albanisch + native_name: Shqip + slug: sq +- model: program.language + pk: 9 + fields: + name: Bosnisch + native_name: Bosanski + slug: bs +- model: program.language + pk: 10 + fields: + name: Kroatisch + native_name: Hrvatski + slug: hr +- model: program.language + pk: 11 + fields: + name: Serbisch + native_name: Српски + slug: sr +- model: program.language + pk: 12 + fields: + name: Russisch + native_name: Русский + slug: ru +- model: program.language + pk: 13 + fields: + name: Slowenisch + native_name: Slovenščina + slug: sl +- model: program.language + pk: 14 + fields: + name: Türkisch + native_name: Türkçe + slug: tr +- model: program.language + pk: 15 + fields: + name: Kurdisch + native_name: كوردی + slug: ku -- cgit v0.10.2 From f7f4a5d5378b37c32b64bf0f71d0a438fd5d19d8 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Wed, 24 Feb 2021 14:51:35 +0100 Subject: disable language selector in templates for now diff --git a/program/templates/day_schedule.html b/program/templates/day_schedule.html index a117a10..2215211 100644 --- a/program/templates/day_schedule.html +++ b/program/templates/day_schedule.html @@ -46,7 +46,7 @@ {% musicfocus %} {% showinformation %} {% showtopic %} -{% language %} +{# {% language %} #}
{% endcomment %} diff --git a/program/templates/show_list.html b/program/templates/show_list.html index fc02872..0602335 100644 --- a/program/templates/show_list.html +++ b/program/templates/show_list.html @@ -15,7 +15,7 @@ {% musicfocus %} {% showinformation %} {% showtopic %} - {% language %} + {# {% language %} #}
-- cgit v0.10.2