From: Radek Czajka Date: Tue, 29 Nov 2022 13:12:26 +0000 (+0100) Subject: Add grammar to tags. Also: respect custom tag slugs on publishing. X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/bde2a16ae2669bea94ec0f23c60213a26d4881f4 Add grammar to tags. Also: respect custom tag slugs on publishing. --- diff --git a/src/catalogue/migrations/0042_tag_adjective_feminine_singular_and_more.py b/src/catalogue/migrations/0042_tag_adjective_feminine_singular_and_more.py new file mode 100644 index 000000000..5935f30d6 --- /dev/null +++ b/src/catalogue/migrations/0042_tag_adjective_feminine_singular_and_more.py @@ -0,0 +1,43 @@ +# Generated by Django 4.0.8 on 2022-11-29 10:21 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('catalogue', '0041_alter_collection_authors'), + ] + + operations = [ + migrations.AddField( + model_name='tag', + name='adjective_feminine_singular', + field=models.CharField(blank=True, help_text='twórczość … Adama Mickiewicza; dotyczy epok', max_length=255, verbose_name='przymiotnik pojedynczy żeński'), + ), + migrations.AddField( + model_name='tag', + name='adjective_nonmasculine_plural', + field=models.CharField(blank=True, help_text='utwory … Adama Mickiewicza; dotyczy epok', max_length=255, verbose_name='przymiotnik mnogi niemęskoosobowy'), + ), + migrations.AddField( + model_name='tag', + name='collective_noun', + field=models.CharField(blank=True, help_text='np. „Liryka” albo „Twórczość dramatyczna”; dotyczy rodzajów', max_length=255, verbose_name='określenie zbiorowe'), + ), + migrations.AddField( + model_name='tag', + name='genitive', + field=models.CharField(blank=True, help_text='utwory … (czyje?); dotyczy autorów', max_length=255, verbose_name='dopełniacz'), + ), + migrations.AddField( + model_name='tag', + name='genre_epoch_specific', + field=models.BooleanField(default=False, help_text='Po wskazaniu tego gatunku, dodanie epoki byłoby nadmiarowe, np. „dramat romantyczny”'), + ), + migrations.AddField( + model_name='tag', + name='plural', + field=models.CharField(blank=True, help_text='dotyczy gatunków', max_length=255, verbose_name='liczba mnoga'), + ), + ] diff --git a/src/catalogue/models/tag.py b/src/catalogue/models/tag.py index 740b84bac..2ade345a5 100644 --- a/src/catalogue/models/tag.py +++ b/src/catalogue/models/tag.py @@ -73,6 +73,31 @@ class Tag(models.Model): created_at = models.DateTimeField(_('creation date'), auto_now_add=True, db_index=True) changed_at = models.DateTimeField(_('creation date'), auto_now=True, db_index=True) + plural = models.CharField( + 'liczba mnoga', max_length=255, blank=True, + help_text='dotyczy gatunków' + ) + genre_epoch_specific = models.BooleanField( + default=False, + help_text='Po wskazaniu tego gatunku, dodanie epoki byłoby nadmiarowe, np. „dramat romantyczny”' + ) + adjective_feminine_singular = models.CharField( + 'przymiotnik pojedynczy żeński', max_length=255, blank=True, + help_text='twórczość … Adama Mickiewicza; dotyczy epok' + ) + adjective_nonmasculine_plural = models.CharField( + 'przymiotnik mnogi niemęskoosobowy', max_length=255, blank=True, + help_text='utwory … Adama Mickiewicza; dotyczy epok' + ) + genitive = models.CharField( + 'dopełniacz', max_length=255, blank=True, + help_text='utwory … (czyje?); dotyczy autorów' + ) + collective_noun = models.CharField( + 'określenie zbiorowe', max_length=255, blank=True, + help_text='np. „Liryka” albo „Twórczość dramatyczna”; dotyczy rodzajów' + ) + after_change = Signal() intermediary_table_model = TagRelation @@ -132,6 +157,10 @@ class Tag(models.Model): def get_absolute_gallery_url(self): return reverse('tagged_object_list_gallery', args=[self.url_chunk]) + def get_absolute_catalogue_url(self): + # TODO: remove magic. + return reverse(f'{self.category}_catalogue') + def has_description(self): return len(self.description) > 0 has_description.short_description = _('description') @@ -197,25 +226,23 @@ class Tag(models.Model): if category == 'author': tag_sort_key = ' '.join((tag_name.last_name,) + tag_name.first_names) tag_name = tag_name.readable() - if lang == settings.LANGUAGE_CODE: - # Allow creating new tag, if it's in default language. - tag, created = Tag.objects.get_or_create(slug=slugify(tag_name), category=category) - if created: - tag_name = str(tag_name) - tag.name = tag_name - setattr(tag, "name_%s" % lang, tag_name) - tag.sort_key = sortify(tag_sort_key.lower()) - tag.save() - meta_tags.append(tag) - else: - # Ignore unknown tags in non-default languages. - try: - tag = Tag.objects.get(category=category, **{"name_%s" % lang: tag_name}) - except Tag.DoesNotExist: - pass - else: + try: + tag = Tag.objects.get(category=category, **{"name_%s" % lang: tag_name}) + except Tag.DoesNotExist: + if lang == settings.LANGUAGE_CODE: + # Allow creating new tag, if it's in default language. + tag, created = Tag.objects.get_or_create(slug=slugify(tag_name), category=category) + if created: + tag_name = str(tag_name) + tag.name = tag_name + setattr(tag, "name_%s" % lang, tag_name) + tag.sort_key = sortify(tag_sort_key.lower()) + tag.save() + meta_tags.append(tag) + else: + meta_tags.append(tag) return meta_tags