summaryrefslogtreecommitdiff
path: root/ishtar_common/models.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2024-02-06 11:29:57 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2024-02-10 14:45:20 +0100
commit312663b48eb1472a5283225705e44ad9005257b9 (patch)
tree223c1e66a8b61b6a7e6e3ce06af70a37df80b279 /ishtar_common/models.py
parent098f1596fa82d4f2a509f549e50f13e07d0c5ded (diff)
downloadIshtar-312663b48eb1472a5283225705e44ad9005257b9.tar.bz2
Ishtar-312663b48eb1472a5283225705e44ad9005257b9.zip
🗃️ museum module: new db fields, add admin
Diffstat (limited to 'ishtar_common/models.py')
-rw-r--r--ishtar_common/models.py80
1 files changed, 75 insertions, 5 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index c978b087b..bd457e970 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -24,6 +24,7 @@ from ipware import get_client_ip
import sys
from bs4 import BeautifulSoup
+import bleach
import copy
import datetime
import inspect
@@ -78,6 +79,7 @@ from django.template import Context, Template
from django.template.defaultfilters import slugify
from django.urls import reverse
from django.utils.functional import lazy
+from django.utils.safestring import mark_safe
from ishtar_common.data_importer import post_importer_action
from ishtar_common.utils import (
ugettext_lazy as _,
@@ -141,6 +143,8 @@ from ishtar_common.utils import (
from ishtar_common.models_common import (
GeneralType,
HierarchicalType,
+ OrderedHierarchicalType,
+ OrderedType,
BaseHistorizedItem,
LightHistorizedItem,
HistoricalRecords,
@@ -194,6 +198,8 @@ __all__ = [
"Regexp",
"ImportTarget",
"ItemKey",
+ "OrderedHierarchicalType",
+ "OrderedType",
"TargetKey",
"FormaterType",
"Import",
@@ -2612,6 +2618,7 @@ class Organization(Address, Merge, OwnPerms, BaseGenderedType, ValueGetter, Main
default="",
help_text=documentation_get_gender_values,
)
+ museum_museofile_id = models.TextField(_("Museofile id"), blank=True, default="")
cached_label = models.TextField(
_("Cached name"), blank=True, default="", db_index=True
)
@@ -3204,6 +3211,38 @@ class Person(Address, Merge, OwnPerms, ValueGetter, MainItem):
post_save.connect(cached_label_changed, sender=Person)
+TEXT_FORMAT = (
+ ("NO", _("None")),
+ ("MD", _("Markdown")),
+ ("HT", _("HTML")),
+)
+
+
+def text_format(text, text_format):
+ if text_format == "MD":
+ return mark_safe(markdown(text))
+ elif text_format == "HT":
+ return mark_safe(bleach.clean(text))
+ return text_format
+
+
+class BiographicalNote(models.Model):
+ denomination = models.TextField(_("Denomination"))
+ last_name = models.TextField(_("Last name"), blank=True, default="")
+ first_name = models.TextField(_("First name"), blank=True, default="")
+ birth_year = models.PositiveIntegerField(_("Year of birth"), blank=True, null=True)
+ death_year = models.PositiveIntegerField(_("Year of death"), blank=True, null=True)
+ biography = models.TextField(_("Biography"), blank=True, default="")
+ biography_format = models.CharField(
+ _("Biography format"), blank=True, default="NO", max_length=2, choices=TEXT_FORMAT
+ )
+ person = models.ForeignKey(Person, verbose_name=_("Person"), blank=True, null=True, on_delete=models.SET_NULL)
+
+ @property
+ def formatted_biography(self):
+ return text_format(self.biography, self.biography_format)
+
+
GDPR_ACTIVITY = (
("DC", _("Directory consultation")),
("DE", _("Directory export")),
@@ -3939,16 +3978,20 @@ post_save.connect(post_save_cache, sender=Format)
post_delete.connect(post_save_cache, sender=Format)
-class LicenseType(GeneralType):
+class LicenseType(OrderedHierarchicalType):
url = models.URLField(_("URL"), blank=True, null=True)
class Meta:
verbose_name = _("License type")
verbose_name_plural = _("License types")
- ordering = ("label",)
+ ordering = ("parent__label", "order", "label",)
ADMIN_SECTION = _("Documents")
+post_save.connect(post_save_cache, sender=LicenseType)
+post_delete.connect(post_save_cache, sender=LicenseType)
+
+
class DocumentTag(GeneralType):
SLUG = "documenttag"
@@ -3959,8 +4002,20 @@ class DocumentTag(GeneralType):
ADMIN_SECTION = _("Documents")
-post_save.connect(post_save_cache, sender=LicenseType)
-post_delete.connect(post_save_cache, sender=LicenseType)
+post_save.connect(post_save_cache, sender=DocumentTag)
+post_delete.connect(post_save_cache, sender=DocumentTag)
+
+
+class ShootingAngle(OrderedType):
+ class Meta:
+ verbose_name = _("Shooting angle")
+ verbose_name_plural = _("Shooting angles")
+ ordering = ("order", "label",)
+ ADMIN_SECTION = _("Documents")
+
+
+post_save.connect(post_save_cache, sender=ShootingAngle)
+post_delete.connect(post_save_cache, sender=ShootingAngle)
class Document(
@@ -4391,9 +4446,17 @@ class Document(
publishing_year = models.PositiveIntegerField(
_("Year of publication"), blank=True, null=True
)
+ rights_owner = models.ForeignKey(
+ Organization,
+ verbose_name=_("Rights owner"),
+ blank=True,
+ null=True,
+ on_delete=models.SET_NULL,
+ )
licenses = models.ManyToManyField(
- LicenseType, verbose_name=_("License"), blank=True
+ LicenseType, verbose_name=_("Rights of use / license"), blank=True
)
+ copyright = models.TextField(_("Copyright"), blank=True, default="")
tags = models.ManyToManyField(DocumentTag, verbose_name=_("Tags"), blank=True)
language = models.ForeignKey(
Language,
@@ -4439,6 +4502,13 @@ class Document(
null=True,
)
scale = models.CharField(_("Scale"), max_length=30, null=True, blank=True)
+ shooting_angle = models.ForeignKey(
+ ShootingAngle,
+ verbose_name=_("Shooting angle"),
+ on_delete=models.SET_NULL,
+ blank=True,
+ null=True,
+ )
authors = models.ManyToManyField(
Author, verbose_name=_("Authors"), related_name="documents",
blank=True