1 from django.apps import apps
2 from django.db import models
3 from django.urls import reverse
4 from django.utils.translation import gettext_lazy as _
5 from .constants import WIKIDATA
6 from .utils import UnrelatedManager
7 from .wikidata import WikidataMixin
10 class Author(WikidataMixin, models.Model):
11 slug = models.SlugField(max_length=255, null=True, blank=True, unique=True)
12 first_name = models.CharField(max_length=255, blank=True)
13 last_name = models.CharField(max_length=255, blank=True)
15 name_de = models.CharField(max_length=255, blank=True)
16 name_lt = models.CharField(max_length=255, blank=True)
18 year_of_death = models.SmallIntegerField(null=True, blank=True)
19 status = models.PositiveSmallIntegerField(
29 notes = models.TextField(blank=True)
30 gazeta_link = models.CharField(max_length=255, blank=True)
31 culturepl_link = models.CharField(max_length=255, blank=True)
33 description = models.TextField(blank=True)
34 description_de = models.TextField(blank=True)
35 description_lt = models.TextField(blank=True)
37 priority = models.PositiveSmallIntegerField(
38 default=0, choices=[(0, _("Low")), (1, _("Medium")), (2, _("High"))]
40 collections = models.ManyToManyField("Collection", blank=True)
43 ordering = ("last_name", "first_name", "year_of_death")
46 first_name = WIKIDATA.GIVEN_NAME
47 last_name = WIKIDATA.LAST_NAME
48 year_of_death = WIKIDATA.DATE_OF_DEATH
52 return f"{self.first_name} {self.last_name}"
54 def get_absolute_url(self):
55 return reverse("catalogue_author", args=[self.slug])
59 if self.year_of_death:
60 return self.year_of_death + 71
61 elif self.year_of_death == 0:
66 class Book(WikidataMixin, models.Model):
67 slug = models.SlugField(max_length=255, blank=True, null=True, unique=True)
68 authors = models.ManyToManyField(Author, blank=True)
69 translators = models.ManyToManyField(
71 related_name="translated_book_set",
72 related_query_name="translated_book",
75 title = models.CharField(max_length=255, blank=True)
76 language = models.CharField(max_length=255, blank=True)
77 based_on = models.ForeignKey(
78 "self", models.PROTECT, related_name="translation", null=True, blank=True
80 scans_source = models.CharField(max_length=255, blank=True)
81 text_source = models.CharField(max_length=255, blank=True)
82 notes = models.TextField(blank=True)
83 priority = models.PositiveSmallIntegerField(
84 default=0, choices=[(0, _("Low")), (1, _("Medium")), (2, _("High"))]
86 pd_year = models.IntegerField(null=True, blank=True)
87 gazeta_link = models.CharField(max_length=255, blank=True)
88 collections = models.ManyToManyField("Collection", blank=True)
90 objects = UnrelatedManager()
96 authors = WIKIDATA.AUTHOR
97 translators = WIKIDATA.TRANSLATOR
98 title = WIKIDATA.TITLE
99 language = WIKIDATA.LANGUAGE
100 based_on = WIKIDATA.BASED_ON
101 notes = "description"
105 astr = self.authors_str()
107 txt = f"{astr} – {txt}"
108 tstr = self.translators_str()
110 txt = f"{txt} (tłum. {tstr})"
113 def get_absolute_url(self):
114 return reverse("catalogue_book", args=[self.slug])
116 def authors_str(self):
117 return ", ".join(str(author) for author in self.authors.all())
119 def translators_str(self):
120 return ", ".join(str(author) for author in self.translators.all())
122 def get_document_books(self):
123 DBook = apps.get_model("documents", "Book")
124 return DBook.objects.filter(dc_slug=self.slug)
127 class Collection(models.Model):
128 name = models.CharField(max_length=255)
129 slug = models.SlugField(max_length=255, unique=True)