diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2026-03-10 17:26:54 +0100 |
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2026-03-25 15:10:32 +0100 |
| commit | 14f2a0a368a00a217b5657c0ed903be897d58294 (patch) | |
| tree | b9e1e1aa11afc6687e73854e175441b0f3b3e3e2 /ishtar_common/models.py | |
| parent | e79327d84c8e18b83e8528b707d064a89259b1eb (diff) | |
| download | Ishtar-14f2a0a368a00a217b5657c0ed903be897d58294.tar.bz2 Ishtar-14f2a0a368a00a217b5657c0ed903be897d58294.zip | |
✨ qualified biographical note - models
Diffstat (limited to 'ishtar_common/models.py')
| -rw-r--r-- | ishtar_common/models.py | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 65dddc051..90e8a8d8d 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -4667,6 +4667,86 @@ def author_post_save(sender, **kwargs): post_save.connect(author_post_save, sender=Author) +class QualifiedBiographicalNoteType(OrderedHierarchicalType): + order = models.IntegerField(_("Order"), default=10) + + class Meta: + verbose_name = _("Qualification type") + verbose_name_plural = _("Qualification types") + ordering = ["order", "label"] + ADMIN_SECTION = _("Directory") + + +post_save.connect(post_save_cache, sender=QualifiedBiographicalNoteType) +post_delete.connect(post_save_cache, sender=QualifiedBiographicalNoteType) + + +class QualifiedBiographicalNote(BaseHistorizedItem, ValueGetter, MainItem): + SLUG = "qualifiedbiographicalnote" + PARENT_SEARCH_VECTORS = ["biographical_note"] + + uuid = models.UUIDField(default=uuid.uuid4) + biographical_note = models.ForeignKey( + BiographicalNote, + verbose_name=_("Biographical note"), + related_name="qualified_biographicalnote", + on_delete=models.CASCADE, + ) + qualification_type = models.ForeignKey( + QualifiedBiographicalNoteType, verbose_name=_("Qualification type"), + on_delete=models.PROTECT + ) + cached_label = models.TextField( + _("Cached name"), blank=True, default="", db_index=True + ) + objects = UUIDModelManager() + + class Meta: + verbose_name = _("Qualified biographical note") + verbose_name_plural = _("Qualified biographical notes") + ordering = ("qualification_type__order", "biographical_note__denomination") + permissions = ( + ("view_own_qualifiedbiographicalnote", "Can view own Qualified biographical note"), + ("change_own_qualifiedbiographicalnote", "Can change own Qualified biographical note"), + ("delete_own_qualifiedbiographicalnote", "Can delete own Qualified biographical note"), + ) + ADMIN_SECTION = _("Directory") + + def __str__(self): + return self.cached_label or "" + + def natural_key(self): + return (self.uuid,) + + def _generate_cached_label(self): + return f"{self.biographical_note} ({self.qualification_type})" + + def public_representation(self): + return {"type": str(self.qualification_type), + "biographical_note": str(self.biographical_note)} + + def merge(self, item, keep_old=False): + merge_model_objects(self, item, keep_old=keep_old) + + +def qualified_post_save(sender, **kwargs): + if not kwargs.get("instance"): + return + cached_label_changed(sender, **kwargs) + instance = kwargs.get("instance") + q = QualifiedBiographicalNote.objects.filter( + biographical_note=instance.biographical_note, + qualification_type=instance.qualification_type) + if q.count() <= 1: + return + qualified_persons = list(q.all()) + for qualified_person in qualified_persons[1:]: + qualified_persons[0].merge(qualified_person) + + +post_save.connect(qualified_post_save, sender=QualifiedBiographicalNote) + + class SourceType(OrderedHierarchicalType): coins_type = models.CharField( _("COInS export - type"), default="document", max_length=100 |
