Skip to content

Commit

Permalink
Merge pull request #92 from arthur-schnitzler/main
Browse files Browse the repository at this point in the history
code update
  • Loading branch information
csae8092 authored Oct 9, 2024
2 parents de16b26 + 96c31c1 commit 91bfa91
Show file tree
Hide file tree
Showing 19 changed files with 357 additions and 101 deletions.
10 changes: 5 additions & 5 deletions apis_core/api_renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ def render(self, data, media_type=None, renderer_context=None):
for d in data["results"]:
d2 = OrderedDict(
[
("target", v)
if k == target
else ("source", v)
if k == source
else (k, v)
(
("target", v)
if k == target
else ("source", v) if k == source else (k, v)
)
for k, v in d.items()
]
)
Expand Down
18 changes: 9 additions & 9 deletions apis_core/api_routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ def __init__(self, *args, **kwargs):
many=ck_many, read_only=True
)

TemplateSerializer.__name__ = (
TemplateSerializer.__qualname__
) = f"{entity_str.title().replace(' ', '')}Serializer"
TemplateSerializer.__name__ = TemplateSerializer.__qualname__ = (
f"{entity_str.title().replace(' ', '')}Serializer"
)

class TemplateSerializerRetrieve(TemplateSerializer):
if entity_str.lower() == "text":
Expand Down Expand Up @@ -323,9 +323,9 @@ def __init__(self, *args, **kwargs):
"IntegerField",
"AutoField",
]:
filter_fields[
f"{field.name}__{f2.name}"
] = allowed_fields_filter[f2.__class__.__name__]
filter_fields[f"{field.name}__{f2.name}"] = (
allowed_fields_filter[f2.__class__.__name__]
)
continue
if field.__class__.__name__ in allowed_fields_filter.keys():
filter_fields[field.name] = allowed_fields_filter[
Expand Down Expand Up @@ -388,9 +388,9 @@ def retrieve(self, request, pk=None):
res = super(self.__class__, self).retrieve(request, pk=pk)
return res

TemplateViewSet.__name__ = (
TemplateViewSet.__qualname__
) = f"Generic{entity_str.title().replace(' ', '')}ViewSet"
TemplateViewSet.__name__ = TemplateViewSet.__qualname__ = (
f"Generic{entity_str.title().replace(' ', '')}ViewSet"
)

serializers_dict[TemplateSerializer.__name__] = TemplateSerializer
views[f"{entity_str.lower().replace(' ', '')}"] = TemplateViewSet
Expand Down
8 changes: 4 additions & 4 deletions apis_core/apis_entities/autocomplete3.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ def get(self, request, *args, **kwargs):
f["id"] = r.id
except:
continue
f[
"text"
] = "<span {}><small>db</small> <b>{}</b> <small>db-ID: {}</small> </span> ".format(
dataclass, str(r), str(r.id)
f["text"] = (
"<span {}><small>db</small> <b>{}</b> <small>db-ID: {}</small> </span> ".format(
dataclass, str(r), str(r.id)
)
)
choices.append(f)
if len(choices) < page_size:
Expand Down
12 changes: 6 additions & 6 deletions apis_core/apis_entities/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ def eliminate_unused_filters(default_filter_dict):
]

if "method" in enabled_filter_settings_dict:
default_filter_dict[
enabled_filter_key
].method = enabled_filter_settings_dict["method"]
default_filter_dict[enabled_filter_key].method = (
enabled_filter_settings_dict["method"]
)

if "label" in enabled_filter_settings_dict:
default_filter_dict[
enabled_filter_key
].label = enabled_filter_settings_dict["label"]
default_filter_dict[enabled_filter_key].label = (
enabled_filter_settings_dict["label"]
)

filter_dict_tmp[enabled_filter_key] = default_filter_dict[
enabled_filter_key
Expand Down
40 changes: 20 additions & 20 deletions apis_core/apis_entities/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,32 +227,32 @@ def sort_fields_list(list_unsorted, entity_label):
instance = getattr(self, "instance", None)
if instance != None:
if instance.start_date_written:
self.fields[
"start_date_written"
].help_text = DateParser.get_date_help_text_from_dates(
single_date=instance.start_date,
single_start_date=instance.start_start_date,
single_end_date=instance.start_end_date,
single_date_written=instance.start_date_written,
self.fields["start_date_written"].help_text = (
DateParser.get_date_help_text_from_dates(
single_date=instance.start_date,
single_start_date=instance.start_start_date,
single_end_date=instance.start_end_date,
single_date_written=instance.start_date_written,
)
)
else:
self.fields[
"start_date_written"
].help_text = DateParser.get_date_help_text_default()
self.fields["start_date_written"].help_text = (
DateParser.get_date_help_text_default()
)

if instance.end_date_written:
self.fields[
"end_date_written"
].help_text = DateParser.get_date_help_text_from_dates(
single_date=instance.end_date,
single_start_date=instance.end_start_date,
single_end_date=instance.end_end_date,
single_date_written=instance.end_date_written,
self.fields["end_date_written"].help_text = (
DateParser.get_date_help_text_from_dates(
single_date=instance.end_date,
single_start_date=instance.end_start_date,
single_end_date=instance.end_end_date,
single_date_written=instance.end_date_written,
)
)
else:
self.fields[
"end_date_written"
].help_text = DateParser.get_date_help_text_default()
self.fields["end_date_written"].help_text = (
DateParser.get_date_help_text_default()
)

def save(self, *args, **kwargs):
obj = super(GenericEntitiesForm, self).save(*args, **kwargs)
Expand Down
4 changes: 3 additions & 1 deletion apis_core/apis_metainfo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,9 @@ def merge_with(self, entities):
if not isinstance(entities, list) and not isinstance(entities, QuerySet):
entities = [entities]
entities = [
self_model_class.objects.get(pk=ent) if type(ent) == int else ent # noqa: E721
(
self_model_class.objects.get(pk=ent) if type(ent) == int else ent
) # noqa: E721
for ent in entities
]
rels = ContentType.objects.filter(
Expand Down
40 changes: 20 additions & 20 deletions apis_core/apis_relations/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,32 +51,32 @@ def __init__(self, siteID=None, *args, **kwargs):
instance = getattr(self, "instance", None)
if instance != None:
if instance.start_date_written:
self.fields[
"start_date_written"
].help_text = DateParser.get_date_help_text_from_dates(
single_date=instance.start_date,
single_start_date=instance.start_start_date,
single_end_date=instance.start_end_date,
single_date_written=instance.start_date_written,
self.fields["start_date_written"].help_text = (
DateParser.get_date_help_text_from_dates(
single_date=instance.start_date,
single_start_date=instance.start_start_date,
single_end_date=instance.start_end_date,
single_date_written=instance.start_date_written,
)
)
else:
self.fields[
"start_date_written"
].help_text = DateParser.get_date_help_text_default()
self.fields["start_date_written"].help_text = (
DateParser.get_date_help_text_default()
)

if instance.end_date_written:
self.fields[
"end_date_written"
].help_text = DateParser.get_date_help_text_from_dates(
single_date=instance.end_date,
single_start_date=instance.end_start_date,
single_end_date=instance.end_end_date,
single_date_written=instance.end_date_written,
self.fields["end_date_written"].help_text = (
DateParser.get_date_help_text_from_dates(
single_date=instance.end_date,
single_start_date=instance.end_start_date,
single_end_date=instance.end_end_date,
single_date_written=instance.end_date_written,
)
)
else:
self.fields[
"end_date_written"
].help_text = DateParser.get_date_help_text_default()
self.fields["end_date_written"].help_text = (
DateParser.get_date_help_text_default()
)


##############################################
Expand Down
40 changes: 20 additions & 20 deletions apis_core/apis_relations/forms2.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,29 +357,29 @@ def __init__(self, siteID=None, highlighter=False, *args, **kwargs):

if instance != None:
if instance.start_date_written:
self.fields[
"start_date_written"
].help_text = DateParser.get_date_help_text_from_dates(
single_date=instance.start_date,
single_start_date=instance.start_start_date,
single_end_date=instance.start_end_date,
single_date_written=instance.start_date_written,
self.fields["start_date_written"].help_text = (
DateParser.get_date_help_text_from_dates(
single_date=instance.start_date,
single_start_date=instance.start_start_date,
single_end_date=instance.start_end_date,
single_date_written=instance.start_date_written,
)
)
else:
self.fields[
"start_date_written"
].help_text = DateParser.get_date_help_text_default()
self.fields["start_date_written"].help_text = (
DateParser.get_date_help_text_default()
)

if instance.end_date_written:
self.fields[
"end_date_written"
].help_text = DateParser.get_date_help_text_from_dates(
single_date=instance.end_date,
single_start_date=instance.end_start_date,
single_end_date=instance.end_end_date,
single_date_written=instance.end_date_written,
self.fields["end_date_written"].help_text = (
DateParser.get_date_help_text_from_dates(
single_date=instance.end_date,
single_start_date=instance.end_start_date,
single_end_date=instance.end_end_date,
single_date_written=instance.end_date_written,
)
)
else:
self.fields[
"end_date_written"
].help_text = DateParser.get_date_help_text_default()
self.fields["end_date_written"].help_text = (
DateParser.get_date_help_text_default()
)
26 changes: 20 additions & 6 deletions apis_core/apis_relations/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import inspect
import sys

from icecream import ic
from apis_core.apis_entities.models import Person
from django.urls import reverse_lazy

from apis_core.apis_metainfo.models import TempEntityClass

#######################################################################
Expand Down Expand Up @@ -226,9 +226,9 @@ def add_relation_class_of_entity_class(cls, entity_class):

# save into the dictionary, which uses the entity class as key and the extended list above as value.
cls._relation_classes_of_entity_class[entity_class] = relation_class_list
cls._relation_classes_of_entity_name[
entity_class.__name__.lower()
] = relation_class_list
cls._relation_classes_of_entity_name[entity_class.__name__.lower()] = (
relation_class_list
)

@classmethod
def get_relation_field_names_of_entity_class(cls, entity_class):
Expand Down Expand Up @@ -341,7 +341,21 @@ class PersonPerson(AbstractRelation):


class PersonPlace(AbstractRelation):
pass
@classmethod
def get_listview_url(self):
return reverse_lazy("apis:apis_relations:person_place")

@classmethod
def get_icon(self):
return "bi bi-people apis-person"

@classmethod
def get_second_icon(self):
return "bi bi-map apis-place"

@classmethod
def get_color(self):
return "#720e07"


class PersonInstitution(AbstractRelation):
Expand Down
Loading

0 comments on commit 91bfa91

Please sign in to comment.