X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/0251adf97488c11e936a714976261febfb8c5268..6251ad833bb249f4cbc52e1676c9d6a2b7d95fff:/src/catalogue/models.py diff --git a/src/catalogue/models.py b/src/catalogue/models.py index b974de14..4544fc68 100644 --- a/src/catalogue/models.py +++ b/src/catalogue/models.py @@ -2,12 +2,14 @@ from collections import Counter import decimal from django.apps import apps from django.db import models +from django.template.loader import render_to_string from django.urls import reverse from django.utils.translation import gettext_lazy as _ from admin_ordering.models import OrderableModel from wikidata.client import Client from .constants import WIKIDATA from .wikidata import WikidataModel +from .wikimedia import WikiMedia class Author(WikidataModel): @@ -50,8 +52,13 @@ class Author(WikidataModel): ], ) notes = models.TextField(_("notes"), blank=True) + gazeta_link = models.CharField(_("gazeta link"), max_length=255, blank=True) culturepl_link = models.CharField(_("culture.pl link"), max_length=255, blank=True) + plwiki = models.CharField(blank=True, max_length=255) + photo = models.ImageField(blank=True, null=True, upload_to='catalogue/author/') + photo_source = models.CharField(blank=True, max_length=255) + photo_attribution = models.CharField(max_length=255, blank=True) description = models.TextField(_("description"), blank=True) @@ -77,6 +84,10 @@ class Author(WikidataModel): place_of_death = WIKIDATA.PLACE_OF_DEATH gender = WIKIDATA.GENDER notes = "description" + plwiki = "plwiki" + photo = WikiMedia.download(WIKIDATA.IMAGE) + photo_source = WikiMedia.descriptionurl(WIKIDATA.IMAGE) + photo_attribution = WikiMedia.attribution(WIKIDATA.IMAGE) def _supplement(obj): if not obj.first_name and not obj.last_name: @@ -104,6 +115,12 @@ class Author(WikidataModel): else: return None + def generate_description(self): + t = render_to_string( + 'catalogue/author_description.html', + {'obj': self} + ) + return t class NotableBook(OrderableModel): author = models.ForeignKey(Author, models.CASCADE) @@ -164,6 +181,7 @@ class Book(WikidataModel): _("priority"), default=0, choices=[(0, _("Low")), (1, _("Medium")), (2, _("High"))] ) + original_year = models.IntegerField(_('original publication year'), null=True, blank=True) pd_year = models.IntegerField(_('year of entry into PD'), null=True, blank=True) gazeta_link = models.CharField(_("gazeta link"), max_length=255, blank=True) collections = models.ManyToManyField("Collection", blank=True, verbose_name=_("collections")) @@ -186,10 +204,13 @@ class Book(WikidataModel): title = WIKIDATA.TITLE language = WIKIDATA.LANGUAGE based_on = WIKIDATA.BASED_ON + original_year = WIKIDATA.PUBLICATION_DATE notes = "description" def __str__(self): txt = self.title + if self.original_year: + txt = f"{txt} ({self.original_year})" astr = self.authors_str() if astr: txt = f"{txt}, {astr}" @@ -244,6 +265,7 @@ class Collection(models.Model): slug = models.SlugField(max_length=255, unique=True) category = models.ForeignKey(CollectionCategory, models.SET_NULL, null=True, blank=True, verbose_name=_("category")) notes = models.TextField(_("notes"), blank=True) + description = models.TextField(_("description"), blank=True) class Meta: ordering = ('category', 'name')