Coverage for apis_core/apis_entities/abc.py: 83%
70 statements
« prev ^ index » next coverage.py v7.5.3, created at 2026-02-19 10:33 +0000
« prev ^ index » next coverage.py v7.5.3, created at 2026-02-19 10:33 +0000
1from django.db import models
2from django.utils.encoding import force_str
3from django.utils.translation import gettext_lazy as _
5from apis_core.apis_entities.rdfconfigs import group, person, place
6from apis_core.generic.utils.rdf_namespace import CRM
7from apis_core.utils.rdf import load_uri_using_path
9#########################
10# Abstract base classes #
11#########################
14# These abstract base classes are named after
15# CIDOC CRM entities, but we are *NOT*(!)
16# trying to implement CIDOC CRM in Django.
19class E21_Person(models.Model):
20 forename = models.CharField(
21 blank=True, default="", max_length=4096, verbose_name=_("forename")
22 )
23 surname = models.CharField(
24 blank=True, default="", max_length=4096, verbose_name=_("surname")
25 )
26 gender = models.CharField(
27 blank=True, default="", max_length=4096, verbose_name=_("gender")
28 )
29 date_of_birth = models.DateField(
30 blank=True, null=True, verbose_name=_("date of birth")
31 )
32 date_of_death = models.DateField(
33 blank=True, null=True, verbose_name=_("date of death")
34 )
36 class Meta:
37 abstract = True
38 verbose_name = _("person")
39 verbose_name_plural = _("persons")
40 ordering = ["surname", "forename"]
42 def __str__(self):
43 if self.forename and self.surname:
44 return f"{self.forename} {self.surname}"
45 return self.forename or self.surname or force_str(_("No name"))
47 import_definitions = {
48 "https://d-nb.info/*|/.*.rdf": lambda x: load_uri_using_path(
49 x, person.E21_PersonFromDNB
50 ),
51 "http://www.wikidata.org/*|/.*.rdf": lambda x: load_uri_using_path(
52 x, person.E21_PersonFromWikidata
53 ),
54 }
56 @classmethod
57 def get_rdf_types(cls):
58 return [CRM.E21_Person]
61class E53_Place(models.Model):
62 """
63 The feature_code field refers to the geonames feature codes, as
64 listed on https://www.geonames.org/export/codes.html
65 """
67 label = models.CharField(
68 blank=True, default="", max_length=4096, verbose_name=_("label")
69 )
70 latitude = models.FloatField(blank=True, null=True, verbose_name=_("latitude"))
71 longitude = models.FloatField(blank=True, null=True, verbose_name=_("longitude"))
72 feature_code = models.CharField(
73 blank=True,
74 default="",
75 max_length=16,
76 verbose_name=_("feature code"),
77 help_text='<a href="https://www.geonames.org/export/codes.html" target="_blank">Geonames Feature Code List</a>',
78 )
80 class Meta:
81 abstract = True
82 verbose_name = _("place")
83 verbose_name_plural = _("places")
84 ordering = ["label"]
86 def __str__(self):
87 return self.label or force_str(_("No label"))
89 import_definitions = {
90 "https://d-nb.info/*|/.*.rdf": lambda x: load_uri_using_path(
91 x, place.E53_PlaceFromDNB
92 ),
93 "https://sws.geonames.org/*|/.*.rdf*": lambda x: load_uri_using_path(
94 x, place.E53_PlaceFromGeonames
95 ),
96 "http://www.wikidata.org/*|/.*.rdf": lambda x: load_uri_using_path(
97 x, place.E53_PlaceFromWikidata
98 ),
99 }
101 @classmethod
102 def get_rdf_types(cls):
103 return [CRM.E53_Place]
105 @classmethod
106 def create_from_string(cls, string):
107 return cls.objects.create(label=string)
110class E74_Group(models.Model):
111 label = models.CharField(
112 blank=True, default="", max_length=4096, verbose_name=_("label")
113 )
115 class Meta:
116 abstract = True
117 verbose_name = _("group")
118 verbose_name_plural = _("groups")
119 ordering = ["label"]
121 def __str__(self):
122 return self.label or force_str(_("No label"))
124 import_definitions = {
125 "https://d-nb.info/*|/.*.rdf": lambda x: load_uri_using_path(
126 x, group.E74_GroupFromDNB
127 ),
128 "http://www.wikidata.org/*|/.*.rdf": lambda x: load_uri_using_path(
129 x, group.E74_GroupFromWikidata
130 ),
131 }
133 @classmethod
134 def get_rdf_types(cls):
135 return [CRM.E74_Group]
137 @classmethod
138 def create_from_string(cls, string):
139 return cls.objects.create(label=string)
142class SimpleLabelModel(models.Model):
143 label = models.CharField(
144 blank=True, default="", max_length=4096, verbose_name=_("label")
145 )
147 class Meta:
148 abstract = True
149 ordering = ["label"]
151 def __str__(self):
152 return self.label or force_str(_("No label"))
154 @classmethod
155 def create_from_string(cls, string):
156 return cls.objects.create(label=string)