From 7cd60d1e5bc691a86600ae44a95c795a3cbd3640 Mon Sep 17 00:00:00 2001 From: csae8092 Date: Wed, 20 Dec 2023 13:44:16 +0100 Subject: [PATCH 1/9] dirty fix for coloring of list views --- .env | 2 +- templates/partials/entity_styles.html | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/.env b/.env index 6225554..49dedd5 100644 --- a/.env +++ b/.env @@ -1,4 +1,4 @@ -POSTGRES_DB=pmb_play +POSTGRES_DB=pmb # NEW_PMB=True # POSTGRES_HOST=172.17.0.1 DEBUG=True diff --git a/templates/partials/entity_styles.html b/templates/partials/entity_styles.html index 08ac2ff..b73b3c8 100644 --- a/templates/partials/entity_styles.html +++ b/templates/partials/entity_styles.html @@ -18,4 +18,24 @@ transition: opacity 1s ease-out; } +{% else %} + {% endif %} \ No newline at end of file From e9ec00be6a53169b3fcb440712a948d6d7360481 Mon Sep 17 00:00:00 2001 From: csae8092 Date: Wed, 20 Dec 2023 17:11:02 +0100 Subject: [PATCH 2/9] run isort, wip merging views --- apis_core/apis_entities/api_renderers.py | 3 +- apis_core/apis_entities/autocomplete3.py | 4 +- apis_core/apis_entities/detail_views.py | 19 +- apis_core/apis_entities/filters.py | 8 +- apis_core/apis_entities/forms.py | 253 +++--------------- apis_core/apis_entities/list_view_event.py | 27 +- .../apis_entities/list_view_institution.py | 28 +- apis_core/apis_entities/list_view_person.py | 26 +- apis_core/apis_entities/list_view_place.py | 21 +- apis_core/apis_entities/list_view_uris.py | 10 +- apis_core/apis_entities/list_view_work.py | 25 +- apis_core/apis_entities/models.py | 16 +- .../templates/apis_entities/edit_view.html | 3 + apis_core/apis_entities/tests.py | 6 +- apis_core/apis_entities/urls.py | 14 +- apis_core/apis_entities/views.py | 23 +- 16 files changed, 133 insertions(+), 353 deletions(-) diff --git a/apis_core/apis_entities/api_renderers.py b/apis_core/apis_entities/api_renderers.py index 786a1b0..4c8a83b 100644 --- a/apis_core/apis_entities/api_renderers.py +++ b/apis_core/apis_entities/api_renderers.py @@ -1,8 +1,7 @@ +from apis_core.apis_tei.tei import TeiEntCreator from django.conf import settings from rest_framework import renderers -from apis_core.apis_tei.tei import TeiEntCreator - base_uri = getattr(settings, "APIS_BASE_URI", "http://apis.info") if base_uri.endswith("/"): base_uri = base_uri[:-1] diff --git a/apis_core/apis_entities/autocomplete3.py b/apis_core/apis_entities/autocomplete3.py index f48f63e..812b04c 100644 --- a/apis_core/apis_entities/autocomplete3.py +++ b/apis_core/apis_entities/autocomplete3.py @@ -7,6 +7,8 @@ import dateutil.parser import requests +from apis_core.apis_metainfo.models import Collection, Uri +from apis_core.apis_vocabularies.models import VocabsBaseClass from dal import autocomplete from django import http from django.conf import settings @@ -14,8 +16,6 @@ from django.core.exceptions import FieldError from django.db.models import Q -from apis_core.apis_metainfo.models import Uri, Collection -from apis_core.apis_vocabularies.models import VocabsBaseClass from .models import AbstractEntity diff --git a/apis_core/apis_entities/detail_views.py b/apis_core/apis_entities/detail_views.py index 996c7e9..85042d4 100644 --- a/apis_core/apis_entities/detail_views.py +++ b/apis_core/apis_entities/detail_views.py @@ -1,20 +1,17 @@ +from apis_core.apis_labels.models import Label +from apis_core.apis_metainfo.models import Uri +from apis_core.apis_relations.models import AbstractRelation +from apis_core.apis_relations.tables import (LabelTableBase, + get_generic_relations_table) from django.conf import settings from django.db.models import Q -from django.http import HttpResponse, Http404 -from django.shortcuts import get_object_or_404 +from django.http import Http404, HttpResponse +from django.shortcuts import get_object_or_404, redirect from django.template.loader import select_template from django.views import View from django_tables2 import RequestConfig -from django.shortcuts import redirect -from apis_core.apis_labels.models import Label -from apis_core.apis_metainfo.models import Uri -from apis_core.apis_relations.models import AbstractRelation -from apis_core.apis_relations.tables import ( - get_generic_relations_table, - LabelTableBase, -) -from .models import TempEntityClass, BASE_URI +from .models import BASE_URI, TempEntityClass def get_object_from_pk_or_uri(request, pk): diff --git a/apis_core/apis_entities/filters.py b/apis_core/apis_entities/filters.py index b52fd90..071660e 100644 --- a/apis_core/apis_entities/filters.py +++ b/apis_core/apis_entities/filters.py @@ -1,13 +1,11 @@ -from functools import reduce import importlib +from functools import reduce import django_filters -from django.conf import settings - from apis_core.apis_entities.models import * -from apis_core.apis_vocabularies.models import RelationBaseClass from apis_core.apis_metainfo.models import Collection - +from apis_core.apis_vocabularies.models import RelationBaseClass +from django.conf import settings # The following classes define the filter sets respective to their models. # Also by what was enabled in the global settings file (or disabled by not explicitley enabling it). diff --git a/apis_core/apis_entities/forms.py b/apis_core/apis_entities/forms.py index 282f881..6cca465 100644 --- a/apis_core/apis_entities/forms.py +++ b/apis_core/apis_entities/forms.py @@ -1,34 +1,58 @@ # -*- coding: utf-8 -*- +from apis_core.apis_metainfo.models import Collection +from apis_core.helper_functions import DateParser from crispy_forms.bootstrap import Accordion, AccordionGroup from crispy_forms.helper import FormHelper -from crispy_forms.layout import Layout, Fieldset -from crispy_forms.layout import Submit +from crispy_forms.layout import Fieldset, Layout, Submit from dal import autocomplete from django import forms from django.conf import settings from django.contrib.contenttypes.models import ContentType -from django.db.models.fields import BLANK_CHOICE_DASH -from django.forms import ModelMultipleChoiceField, ModelChoiceField +from django.forms import ModelChoiceField, ModelMultipleChoiceField from django.urls import reverse -from apis_core.apis_metainfo.models import Text, Uri, Collection -from apis_core.apis_vocabularies.models import TextType -from apis_core.helper_functions import DateParser from .fields import ListSelect2, Select2Multiple from .models import AbstractEntity -class SearchForm(forms.Form): - search = forms.CharField(label="Search") +class MergeForm(forms.Form): + def save(self, *args, **kwargs): + return self.entity + + def __init__(self, entity, *args, **kwargs): - @property - def helper(self): - helper = FormHelper() - helper.form_id = "searchForm" - helper.form_tag = False - helper.add_input(Submit("fieldn", "search")) - helper.form_method = "GET" - return helper + attrs = { + "data-placeholder": "Type to get suggestions", + "data-minimum-input-length": getattr(settings, "APIS_MIN_CHAR", 3), + "data-html": True, + "style": "width: auto", + } + ent_merge_pk = kwargs.pop("ent_merge_pk", False) + super(MergeForm, self).__init__(*args, **kwargs) + self.entity = entity + self.helper = FormHelper() + form_kwargs = {"entity": entity} + url = reverse( + "apis:apis_entities:generic_entities_autocomplete", + args=[entity.title(), "remove"], + ) + label = "Create {} from reference resources".format(entity.title()) + button_label = "Create" + if ent_merge_pk: + form_kwargs["ent_merge_pk"] = ent_merge_pk + url = reverse( + "apis:apis_entities:generic_entities_autocomplete", + args=[entity.title(), ent_merge_pk], + ) + label = "Search for {0} in reference resources or db".format(entity.title()) + button_label = "Merge" + self.helper.form_action = "hansi" + self.helper.add_input(Submit("submit", button_label)) + self.fields["entity"] = autocomplete.Select2ListCreateChoiceField( + label=label, + widget=ListSelect2(url=url, attrs=attrs), + # validators=[URLValidator], + ) def get_entities_form(entity): @@ -237,198 +261,3 @@ def save(self, *args, **kwargs): return obj return GenericEntitiesForm - - -class FullTextForm(forms.Form): - def save(self, entity): - cd = self.cleaned_data - text = None - for f in cd.keys(): - text_type = TextType.objects.get(pk=f.split("_")[1]) - text = Text.objects.filter(tempentityclass=entity, kind=text_type) - if text.count() == 1: - text = text[0] - text.text = cd[f] - text.save() - elif text.count() == 0: - text = Text(text=cd[f], kind=text_type) - text.save() - entity.text.add(text) - return text - - def __init__(self, *args, **kwargs): - if "entity" in kwargs.keys(): - entity = kwargs.pop("entity", None) - else: - entity = None - if "instance" in kwargs.keys(): - instance = kwargs.pop("instance", None) - else: - instance = None - super(FullTextForm, self).__init__(*args, **kwargs) - self.helper = FormHelper() - self.helper.form_class = "FullTextForm" - self.helper.form_tag = False - self.helper.help_text_inline = True - collections = [] - if instance: - for i in instance.collection.all(): - collections.append(i) - try: - if len(collections) > 0: - q = TextType.objects.filter( - entity__iexact=entity, collections__in=collections - ) - else: - q = TextType.objects.filter(entity__iexact=entity) - for txt in q: - self.fields["text_" + str(txt.pk)] = forms.CharField( - label=txt.name, - help_text=txt.description, - required=False, - widget=forms.Textarea, - ) - if instance: - for t in instance.text.all(): - if "text_" + str(t.kind.pk) in self.fields.keys(): - self.fields["text_" + str(t.kind.pk)].initial = t.text - except: - pass - - -class PersonResolveUriForm(forms.Form): - # person = forms.CharField(label=False, widget=al.TextWidget('PersonAutocomplete')) - person = forms.CharField(label=False) - person_uri = forms.CharField(required=False, widget=forms.HiddenInput()) - - def save(self, site_instance, instance=None, commit=True): - cd = self.cleaned_data - if cd["person"].startswith("http"): - uri = Uri.objects.create(uri=cd["person"], entity=site_instance) - else: - uri = Uri.objects.create(uri=cd["person_uri"], entity=site_instance) - return uri - - def __init__(self, *args, **kwargs): - entity_type = kwargs.pop("entity_type", False) - self.request = kwargs.pop("request", False) - super(PersonResolveUriForm, self).__init__(*args, **kwargs) - self.helper = FormHelper() - self.helper.form_tag = False - - def clean(self): - cleaned_data = super(PersonResolveUriForm, self).clean() - if Uri.objects.filter(uri=cleaned_data["person_uri"]).exists(): - self.add_error("person", "This Person has already been added to the DB.") - elif cleaned_data["person"].startswith("http"): - if Uri.objects.filter(uri=cleaned_data["person"]).exists(): - self.add_error("person", "This URI has already been added to the DB.") - - -class NetworkVizFilterForm(forms.Form): - ann_include_all = forms.BooleanField( - required=False, - label="Include general relations", - help_text="""Not all relations are connected to an annotation.\ - If checked relations that are not attached to an annotation are include.\ - This setting is only used when an Annotation project is specified.""", - ) - start_date = forms.CharField( - label="Start date", - required=False, - widget=forms.TextInput( - attrs={"data-provide": "datepicker", "data-date-format": "dd.mm.yyyy"} - ), - ) - end_date = forms.CharField( - label="End date", - required=False, - widget=forms.TextInput( - attrs={"data-provide": "datepicker", "data-date-format": "dd.mm.yyyy"} - ), - ) - - def __init__(self, *args, **kwargs): - rel_attrs = { - "data-placeholder": "Type to get suggestions", - "data-minimum-input-length": getattr(settings, "APIS_MIN_CHAR", 3), - "data-html": True, - } - attrs = { - "data-placeholder": "Type to get suggestions", - "data-minimum-input-length": getattr(settings, "APIS_MIN_CHAR", 3), - "data-html": True, - } - super(NetworkVizFilterForm, self).__init__(*args, **kwargs) - self.fields["select_relation"] = forms.ChoiceField( - label="Relation type", - choices=list( - ("-".join(x.name.split()), x.name) - for x in ContentType.objects.filter(app_label="apis_relations") - ), - help_text="Include only relations related to this annotation project \ - (See the include general relations checkbox)", - ) - self.fields["select_relation"].initial = ("person-place", "person place") - self.fields["search_source"] = autocomplete.Select2ListCreateChoiceField( - label="Search source", - widget=ListSelect2( - url=reverse( - "apis:apis_entities:generic_network_entities_autocomplete", - kwargs={"entity": "person"}, - ), - attrs=attrs, - ), - ) - self.fields["search_target"] = autocomplete.Select2ListCreateChoiceField( - label="Search target", - widget=ListSelect2( - url=reverse( - "apis:apis_entities:generic_network_entities_autocomplete", - kwargs={"entity": "place"}, - ), - attrs=attrs, - ), - ) - self.fields["select_kind"] = autocomplete.Select2ListCreateChoiceField( - label="Select kind", - widget=ListSelect2( - url=reverse( - "apis:apis_vocabularies:generic_vocabularies_autocomplete", - kwargs={"vocab": "personplacerelation", "direct": "normal"}, - ), - attrs=rel_attrs, - ), - ) - if "apis_highlighter" in settings.INSTALLED_APPS: - self.fields["annotation_proj"] = forms.ChoiceField( - label="Annotation Project", - choices=BLANK_CHOICE_DASH - + list((x.pk, x.name) for x in AnnotationProject.objects.all()), - required=False, - help_text="Include only relations related to this annotation project \ - (See the include general relations checkbox)", - ) - self.helper = FormHelper() - self.helper.form_class = "FilterNodesForm" - self.helper.form_action = reverse("apis:apis_core:NetJson-list") - self.helper.add_input(Submit("Submit", "Add nodes")) - self.order_fields( - ( - "select_relation", - "ann_include_all", - "annotation_proj", - "search_source", - "select_kind", - "search_target", - ) - ) - - -class GenericFilterFormHelper(FormHelper): - def __init__(self, *args, **kwargs): - super(GenericFilterFormHelper, self).__init__(*args, **kwargs) - self.helper = FormHelper() - self.form_class = "genericFilterForm" - self.form_method = "GET" - self.form_tag = False diff --git a/apis_core/apis_entities/list_view_event.py b/apis_core/apis_entities/list_view_event.py index 912979e..2d9c482 100644 --- a/apis_core/apis_entities/list_view_event.py +++ b/apis_core/apis_entities/list_view_event.py @@ -1,26 +1,19 @@ import django_filters import django_tables2 as tables +from apis_core.apis_entities.models import Event +from apis_core.apis_vocabularies.models import (EventEventRelation, EventType, + EventWorkRelation, + InstitutionEventRelation, + PersonEventRelation, + PlaceEventRelation) +from apis_core.helper_functions.utils import get_child_classes +from browsing.browsing_utils import GenericListView +from crispy_bootstrap5.bootstrap5 import BS5Accordion +from crispy_forms.bootstrap import AccordionGroup from crispy_forms.helper import FormHelper from crispy_forms.layout import Layout -from crispy_forms.bootstrap import AccordionGroup -from crispy_bootstrap5.bootstrap5 import BS5Accordion - from dal import autocomplete -from browsing.browsing_utils import GenericListView - -from apis_core.apis_entities.models import Event - -from apis_core.apis_vocabularies.models import ( - PlaceEventRelation, - InstitutionEventRelation, - PersonEventRelation, - EventEventRelation, - EventType, - EventWorkRelation, -) -from apis_core.helper_functions.utils import get_child_classes - excluded_cols = [ "start_start_date", "start_end_date", diff --git a/apis_core/apis_entities/list_view_institution.py b/apis_core/apis_entities/list_view_institution.py index 81d1667..f6fb1e2 100644 --- a/apis_core/apis_entities/list_view_institution.py +++ b/apis_core/apis_entities/list_view_institution.py @@ -1,26 +1,20 @@ import django_filters import django_tables2 as tables +from apis_core.apis_entities.models import Institution +from apis_core.apis_vocabularies.models import (InstitutionEventRelation, + InstitutionInstitutionRelation, + InstitutionPlaceRelation, + InstitutionType, + InstitutionWorkRelation, + PersonInstitutionRelation) +from apis_core.helper_functions.utils import get_child_classes +from browsing.browsing_utils import GenericListView +from crispy_bootstrap5.bootstrap5 import BS5Accordion +from crispy_forms.bootstrap import AccordionGroup from crispy_forms.helper import FormHelper from crispy_forms.layout import Layout -from crispy_forms.bootstrap import AccordionGroup -from crispy_bootstrap5.bootstrap5 import BS5Accordion - from dal import autocomplete -from browsing.browsing_utils import GenericListView - -from apis_core.apis_entities.models import Institution - -from apis_core.apis_vocabularies.models import ( - PersonInstitutionRelation, - InstitutionWorkRelation, - InstitutionPlaceRelation, - InstitutionInstitutionRelation, - InstitutionEventRelation, - InstitutionType, -) -from apis_core.helper_functions.utils import get_child_classes - excluded_cols = [ "start_start_date", "start_end_date", diff --git a/apis_core/apis_entities/list_view_person.py b/apis_core/apis_entities/list_view_person.py index 421af99..70f2504 100644 --- a/apis_core/apis_entities/list_view_person.py +++ b/apis_core/apis_entities/list_view_person.py @@ -1,25 +1,19 @@ import django_filters import django_tables2 as tables +from apis_core.apis_entities.models import Person +from apis_core.apis_vocabularies.models import (PersonInstitutionRelation, + PersonPersonRelation, + PersonPlaceRelation, + PersonWorkRelation, + ProfessionType) +from apis_core.helper_functions.utils import get_child_classes +from browsing.browsing_utils import GenericListView +from crispy_bootstrap5.bootstrap5 import BS5Accordion +from crispy_forms.bootstrap import AccordionGroup from crispy_forms.helper import FormHelper from crispy_forms.layout import Layout -from crispy_forms.bootstrap import AccordionGroup -from crispy_bootstrap5.bootstrap5 import BS5Accordion - from dal import autocomplete -from browsing.browsing_utils import GenericListView - -from apis_core.apis_entities.models import Person - -from apis_core.apis_vocabularies.models import ( - ProfessionType, - PersonPersonRelation, - PersonPlaceRelation, - PersonWorkRelation, - PersonInstitutionRelation, -) -from apis_core.helper_functions.utils import get_child_classes - excluded_cols = [ "start_start_date", "start_end_date", diff --git a/apis_core/apis_entities/list_view_place.py b/apis_core/apis_entities/list_view_place.py index f58c87f..073d4df 100644 --- a/apis_core/apis_entities/list_view_place.py +++ b/apis_core/apis_entities/list_view_place.py @@ -1,23 +1,16 @@ import django_filters import django_tables2 as tables +from apis_core.apis_entities.models import Place +from apis_core.apis_vocabularies.models import (PersonPlaceRelation, PlaceType, + PlaceWorkRelation) +from apis_core.helper_functions.utils import get_child_classes +from browsing.browsing_utils import GenericListView +from crispy_bootstrap5.bootstrap5 import BS5Accordion +from crispy_forms.bootstrap import AccordionGroup from crispy_forms.helper import FormHelper from crispy_forms.layout import Layout -from crispy_forms.bootstrap import AccordionGroup -from crispy_bootstrap5.bootstrap5 import BS5Accordion - from dal import autocomplete -from browsing.browsing_utils import GenericListView - -from apis_core.apis_entities.models import Place - -from apis_core.apis_vocabularies.models import ( - PlaceType, - PlaceWorkRelation, - PersonPlaceRelation, -) -from apis_core.helper_functions.utils import get_child_classes - excluded_cols = [ "start_start_date", "start_end_date", diff --git a/apis_core/apis_entities/list_view_uris.py b/apis_core/apis_entities/list_view_uris.py index f23389b..0b38932 100644 --- a/apis_core/apis_entities/list_view_uris.py +++ b/apis_core/apis_entities/list_view_uris.py @@ -1,13 +1,11 @@ import django_filters import django_tables2 as tables +from apis_core.apis_metainfo.models import Uri +from browsing.browsing_utils import GenericListView +from crispy_bootstrap5.bootstrap5 import BS5Accordion +from crispy_forms.bootstrap import AccordionGroup from crispy_forms.helper import FormHelper from crispy_forms.layout import Layout -from crispy_forms.bootstrap import AccordionGroup -from crispy_bootstrap5.bootstrap5 import BS5Accordion - -from browsing.browsing_utils import GenericListView - -from apis_core.apis_metainfo.models import Uri class UriTable(tables.Table): diff --git a/apis_core/apis_entities/list_view_work.py b/apis_core/apis_entities/list_view_work.py index 60509ce..8f0ed59 100644 --- a/apis_core/apis_entities/list_view_work.py +++ b/apis_core/apis_entities/list_view_work.py @@ -1,25 +1,18 @@ import django_filters import django_tables2 as tables +from apis_core.apis_entities.models import Work +from apis_core.apis_vocabularies.models import (InstitutionWorkRelation, + PersonWorkRelation, + PlaceWorkRelation, WorkType, + WorkWorkRelation) +from apis_core.helper_functions.utils import get_child_classes +from browsing.browsing_utils import GenericListView +from crispy_bootstrap5.bootstrap5 import BS5Accordion +from crispy_forms.bootstrap import AccordionGroup from crispy_forms.helper import FormHelper from crispy_forms.layout import Layout -from crispy_forms.bootstrap import AccordionGroup -from crispy_bootstrap5.bootstrap5 import BS5Accordion - from dal import autocomplete -from browsing.browsing_utils import GenericListView - -from apis_core.apis_entities.models import Work - -from apis_core.apis_vocabularies.models import ( - PlaceWorkRelation, - InstitutionWorkRelation, - PersonWorkRelation, - WorkWorkRelation, - WorkType, -) -from apis_core.helper_functions.utils import get_child_classes - excluded_cols = [ "start_start_date", "start_end_date", diff --git a/apis_core/apis_entities/models.py b/apis_core/apis_entities/models.py index 8cb447f..5a82bcc 100644 --- a/apis_core/apis_entities/models.py +++ b/apis_core/apis_entities/models.py @@ -3,23 +3,17 @@ import sys import unicodedata +from apis_core.apis_metainfo.models import TempEntityClass, Uri +from apis_core.apis_vocabularies.models import (EventType, InstitutionType, + PlaceType, ProfessionType, + Title, WorkType) +from apis_core.helper_functions import EntityRelationFieldGenerator from django.conf import settings from django.db import models from django.db.models import Q from django.db.models.signals import post_save from django.dispatch import receiver -from apis_core.apis_metainfo.models import TempEntityClass, Uri -from apis_core.apis_vocabularies.models import ( - EventType, - InstitutionType, - PlaceType, - ProfessionType, - Title, - WorkType, -) -from apis_core.helper_functions import EntityRelationFieldGenerator - BASE_URI = getattr(settings, "APIS_BASE_URI", "http://apis.info/") DOMAIN_DEFAULT = getattr(settings, "APIS_DEFAULT_DOMAIN", "apis default") diff --git a/apis_core/apis_entities/templates/apis_entities/edit_view.html b/apis_core/apis_entities/templates/apis_entities/edit_view.html index 353383d..b317663 100644 --- a/apis_core/apis_entities/templates/apis_entities/edit_view.html +++ b/apis_core/apis_entities/templates/apis_entities/edit_view.html @@ -33,6 +33,9 @@

Delete +
+

Merge

+ {% crispy form_merge_with form_merge_with.helper %}

Edit the Relations

diff --git a/apis_core/apis_entities/tests.py b/apis_core/apis_entities/tests.py index b870579..e3a7331 100644 --- a/apis_core/apis_entities/tests.py +++ b/apis_core/apis_entities/tests.py @@ -1,9 +1,7 @@ +from apis_core.apis_entities.models import Person from django.apps import apps -from django.test import TestCase, Client from django.contrib.auth.models import User - -from apis_core.apis_entities.models import Person - +from django.test import Client, TestCase client = Client() USER = {"username": "testuser", "password": "somepassword"} diff --git a/apis_core/apis_entities/urls.py b/apis_core/apis_entities/urls.py index 244a91f..0c38e56 100644 --- a/apis_core/apis_entities/urls.py +++ b/apis_core/apis_entities/urls.py @@ -1,16 +1,12 @@ from django.urls import path -from . import views, detail_views, merge_views -from .autocomplete3 import ( - GenericEntitiesAutocomplete, -) - +from . import detail_views, merge_views, views +from .autocomplete3 import GenericEntitiesAutocomplete +from .list_view_event import EventListView +from .list_view_institution import InstitutionListView from .list_view_person import PersonListView -from .list_view_work import WorkListView from .list_view_place import PlaceListView -from .list_view_institution import InstitutionListView -from .list_view_event import EventListView - +from .list_view_work import WorkListView app_name = "apis_entities" diff --git a/apis_core/apis_entities/views.py b/apis_core/apis_entities/views.py index ce434f7..ae0f30a 100644 --- a/apis_core/apis_entities/views.py +++ b/apis_core/apis_entities/views.py @@ -1,8 +1,15 @@ +import importlib + +from apis_core.apis_entities.models import AbstractEntity +from apis_core.apis_labels.models import Label +from apis_core.apis_relations.models import AbstractRelation +from apis_core.apis_relations.tables import (LabelTableEdit, + get_generic_relations_table) from django.conf import settings from django.contrib.auth.decorators import login_required from django.db.models import Q from django.http import HttpResponse -from django.shortcuts import redirect, get_object_or_404 +from django.shortcuts import get_object_or_404, redirect from django.template.loader import select_template from django.template.response import TemplateResponse from django.urls import reverse @@ -10,13 +17,8 @@ from django.views import View from django.views.generic import DeleteView from django_tables2 import RequestConfig -import importlib -from apis_core.apis_entities.models import AbstractEntity -from apis_core.apis_labels.models import Label -from apis_core.apis_relations.models import AbstractRelation -from apis_core.apis_relations.tables import get_generic_relations_table, LabelTableEdit -from .forms import get_entities_form, FullTextForm +from .forms import get_entities_form, MergeForm @method_decorator(login_required, name="dispatch") @@ -65,6 +67,7 @@ def get(self, request, *args, **kwargs): ) form = get_entities_form(entity.title()) form = form(instance=instance) + form_merge_with = MergeForm(entity, ent_merge_pk=pk) object_labels = Label.objects.filter(temp_entity=instance) tb_label = LabelTableEdit(data=object_labels, prefix=entity.title()[:2] + "L-") tb_label_open = request.GET.get("PL-page", None) @@ -78,6 +81,7 @@ def get(self, request, *args, **kwargs): context = { "entity_type": entity, "form": form, + "form_merge_with": form_merge_with, "instance": instance, "right_card": side_bar, } @@ -90,10 +94,8 @@ def post(self, request, *args, **kwargs): instance = get_object_or_404(entity_model, pk=pk) form = get_entities_form(entity.title()) form = form(request.POST, instance=instance) - form_text = FullTextForm(request.POST, entity=entity.title()) - if form.is_valid() and form_text.is_valid(): + if form.is_valid(): entity_2 = form.save() - form_text.save(entity_2) return redirect( reverse( "apis:apis_entities:generic_entities_edit_view", @@ -110,7 +112,6 @@ def post(self, request, *args, **kwargs): context = { "form": form, "entity_type": entity, - "form_text": form_text, "instance": instance, } if entity.lower() != "place": From f70da98a703743fee1e330f5dd10bed241d8cd22 Mon Sep 17 00:00:00 2001 From: csae8092 Date: Thu, 21 Dec 2023 07:58:23 +0100 Subject: [PATCH 3/9] merge workflow working again --- apis_core/apis_entities/forms.py | 11 ++++-- .../templates/apis_entities/edit_view.html | 9 +++-- apis_core/apis_entities/urls.py | 5 +++ apis_core/apis_entities/views.py | 37 ++++++++++++++++++- apis_core/apis_metainfo/models.py | 2 + 5 files changed, 55 insertions(+), 9 deletions(-) diff --git a/apis_core/apis_entities/forms.py b/apis_core/apis_entities/forms.py index 6cca465..9a61f44 100644 --- a/apis_core/apis_entities/forms.py +++ b/apis_core/apis_entities/forms.py @@ -23,7 +23,7 @@ def __init__(self, entity, *args, **kwargs): attrs = { "data-placeholder": "Type to get suggestions", - "data-minimum-input-length": getattr(settings, "APIS_MIN_CHAR", 3), + "data-minimum-input-length": 1, "data-html": True, "style": "width: auto", } @@ -44,9 +44,11 @@ def __init__(self, entity, *args, **kwargs): "apis:apis_entities:generic_entities_autocomplete", args=[entity.title(), ent_merge_pk], ) - label = "Search for {0} in reference resources or db".format(entity.title()) + label = f"Suche nach Objekten vom Type: {entity.title()}" button_label = "Merge" - self.helper.form_action = "hansi" + self.helper.form_action = reverse( + "apis:apis_entities:merge_view", kwargs=form_kwargs + ) self.helper.add_input(Submit("submit", button_label)) self.fields["entity"] = autocomplete.Select2ListCreateChoiceField( label=label, @@ -144,7 +146,8 @@ def __init__(self, *args, **kwargs): except ValueError: res = "" if f not in acc_grp2: - # append to unsorted list, so that it can be sorted and afterwards attached to accordion group acc_grp1 + # append to unsorted list, so that it can be sorted and + # afterwards attached to accordion group acc_grp1 fields_list_unsorted.append(f) def sort_fields_list(list_unsorted, entity_label): diff --git a/apis_core/apis_entities/templates/apis_entities/edit_view.html b/apis_core/apis_entities/templates/apis_entities/edit_view.html index b317663..dac7da5 100644 --- a/apis_core/apis_entities/templates/apis_entities/edit_view.html +++ b/apis_core/apis_entities/templates/apis_entities/edit_view.html @@ -30,11 +30,14 @@

{% crispy form %} - - Delete +
+ + Delete +

-

Merge

+

Merge Entity

+

Die aktuelle Entität {{ instance }} wird gelöscht, deren Eigenschaften/Verbindungen aber auf die ausgewählten Entität übertragen.

{% crispy form_merge_with form_merge_with.helper %}
diff --git a/apis_core/apis_entities/urls.py b/apis_core/apis_entities/urls.py index 0c38e56..beacd81 100644 --- a/apis_core/apis_entities/urls.py +++ b/apis_core/apis_entities/urls.py @@ -56,6 +56,11 @@ EventListView.as_view(), name="event_list_view", ), + path( + "merge///", + views.MergeEntitiesView.as_view(), + name="merge_view", + ), path( "autocomplete///", GenericEntitiesAutocomplete.as_view(), diff --git a/apis_core/apis_entities/views.py b/apis_core/apis_entities/views.py index ae0f30a..19a25ac 100644 --- a/apis_core/apis_entities/views.py +++ b/apis_core/apis_entities/views.py @@ -1,12 +1,13 @@ import importlib from apis_core.apis_entities.models import AbstractEntity +from apis_core.apis_metainfo.models import Uri from apis_core.apis_labels.models import Label from apis_core.apis_relations.models import AbstractRelation -from apis_core.apis_relations.tables import (LabelTableEdit, - get_generic_relations_table) +from apis_core.apis_relations.tables import LabelTableEdit, get_generic_relations_table from django.conf import settings from django.contrib.auth.decorators import login_required +from django.contrib.contenttypes.models import ContentType from django.db.models import Q from django.http import HttpResponse from django.shortcuts import get_object_or_404, redirect @@ -18,6 +19,7 @@ from django.views.generic import DeleteView from django_tables2 import RequestConfig +from icecream import ic from .forms import get_entities_form, MergeForm @@ -187,3 +189,34 @@ def dispatch(self, request, *args, **kwargs): "apis_core:apis_entities:generic_entities_list", kwargs={"entity": entity} ) return super(GenericEntitiesDeleteView, self).dispatch(request, *args, **kwargs) + + +@method_decorator(login_required, name="dispatch") +class MergeEntitiesView(View): + def post(self, request, *args, **kwargs): + entity = kwargs["entity"] + ent_merge_pk = kwargs.get("ent_merge_pk", False) + form = MergeForm(entity, request.POST, ent_merge_pk=ent_merge_pk) + if form.is_valid(): + uri = form.data["entity"] + if ent_merge_pk: + uri_obj = Uri.objects.get(uri=uri) + target = uri_obj.entity + entity_model_class = ContentType.objects.get( + app_label="apis_entities", model__iexact=entity + ).model_class() + target_obj = entity_model_class.objects.get(id=target.id) + target_obj.merge_with(int(ent_merge_pk)) + return redirect( + reverse( + "apis:apis_entities:generic_entities_detail_view", + kwargs={"pk": target.pk, "entity": entity}, + ) + ) + else: + return redirect( + reverse( + "apis:apis_entities:generic_entities_edit_view", + kwargs={"pk": ent_merge_pk, "entity": entity}, + ) + ) diff --git a/apis_core/apis_metainfo/models.py b/apis_core/apis_metainfo/models.py index 2ab391e..251ae75 100644 --- a/apis_core/apis_metainfo/models.py +++ b/apis_core/apis_metainfo/models.py @@ -9,6 +9,7 @@ from django.db.models.query import QuerySet from django.urls import reverse from model_utils.managers import InheritanceManager +from icecream import ic from apis_core.apis_labels.models import Label from apis_core.apis_vocabularies.models import CollectionType, LabelType, TextType @@ -220,6 +221,7 @@ def get_delete_url(self): def merge_with(self, entities): e_a_pk = self.pk e_a = type(self).__name__ + ic(e_a) self_model_class = ContentType.objects.get( app_label="apis_entities", model__iexact=e_a ).model_class() From acb27d63d81e0c8efe5e666857891da703d0cbd4 Mon Sep 17 00:00:00 2001 From: csae8092 Date: Thu, 21 Dec 2023 08:02:10 +0100 Subject: [PATCH 4/9] title for list views --- apis_core/apis_entities/templates/apis_entities/list_view.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apis_core/apis_entities/templates/apis_entities/list_view.html b/apis_core/apis_entities/templates/apis_entities/list_view.html index f1d534b..2aaeb2d 100644 --- a/apis_core/apis_entities/templates/apis_entities/list_view.html +++ b/apis_core/apis_entities/templates/apis_entities/list_view.html @@ -4,7 +4,7 @@ {% load browsing_extras %} {% load crispy_forms_field %} {% load crispy_forms_tags %} - +{% block title %} Alle {{ verbose_name }} {% endblock %} {% block content %} {% include "partials/entity_styles.html" %} From bbeec5985ecfac321b536a20952688b09d1f2a9b Mon Sep 17 00:00:00 2001 From: csae8092 Date: Thu, 21 Dec 2023 08:03:20 +0100 Subject: [PATCH 5/9] isort --- apis_core/api_routers.py | 13 ++- apis_core/apis_entities/api_renderers.py | 3 +- apis_core/apis_entities/autocomplete3.py | 5 +- apis_core/apis_entities/detail_views.py | 11 +-- apis_core/apis_entities/filters.py | 3 +- apis_core/apis_entities/forms.py | 6 +- apis_core/apis_entities/list_view_event.py | 11 +-- .../apis_entities/list_view_institution.py | 11 +-- apis_core/apis_entities/list_view_person.py | 11 +-- apis_core/apis_entities/list_view_place.py | 11 +-- apis_core/apis_entities/list_view_uris.py | 5 +- apis_core/apis_entities/list_view_work.py | 11 +-- apis_core/apis_entities/models.py | 11 +-- apis_core/apis_entities/tests.py | 3 +- apis_core/apis_entities/views.py | 16 ++-- apis_core/apis_labels/admin.py | 3 +- apis_core/apis_labels/serializers.py | 1 + apis_core/apis_labels/views.py | 1 - apis_core/apis_metainfo/admin.py | 2 +- apis_core/apis_metainfo/api_views.py | 12 +-- apis_core/apis_metainfo/models.py | 6 +- apis_core/apis_metainfo/tables.py | 1 - apis_core/apis_metainfo/urls.py | 3 +- apis_core/apis_metainfo/views.py | 4 +- .../autocomplete_light_registry.py | 9 +- apis_core/apis_relations/forms.py | 1 - apis_core/apis_relations/forms2.py | 3 +- apis_core/apis_relations/models.py | 1 - apis_core/apis_relations/serializers.py | 30 ++----- apis_core/apis_relations/tables.py | 10 +-- apis_core/apis_relations/views.py | 45 +++------- apis_core/apis_tei/tei.py | 13 ++- apis_core/apis_tei/tei_urls.py | 4 +- apis_core/apis_tei/tei_utils.py | 5 +- apis_core/apis_tei/views.py | 9 +- apis_core/apis_vis/api_views.py | 2 +- apis_core/apis_vis/urls.py | 2 +- apis_core/apis_vis/views.py | 1 + apis_core/apis_vocabularies/admin.py | 2 +- apis_core/apis_vocabularies/api_renderers.py | 6 +- apis_core/apis_vocabularies/api_views.py | 84 +++++++------------ apis_core/apis_vocabularies/serializers.py | 38 +++------ apis_core/apis_vocabularies/urls.py | 3 +- apis_core/helper_functions/ContentType.py | 1 + apis_core/openrefine/views.py | 13 +-- apis_core/urls.py | 6 +- 46 files changed, 190 insertions(+), 262 deletions(-) diff --git a/apis_core/api_routers.py b/apis_core/api_routers.py index a93e4d0..f10f9d0 100644 --- a/apis_core/api_routers.py +++ b/apis_core/api_routers.py @@ -1,17 +1,16 @@ from functools import reduce -from django.conf import settings +from django.conf import settings from django.urls import reverse -from rest_framework import pagination, serializers, viewsets -from rest_framework import renderers +from django_filters import rest_framework as filters +from rest_framework import pagination, renderers, serializers, viewsets +from rest_framework.filters import OrderingFilter from rest_framework.response import Response +from apis_core.helper_functions.ContentType import GetContentTypes -from django_filters import rest_framework as filters -from rest_framework.filters import OrderingFilter -from .apis_metainfo.models import TempEntityClass from .api_renderers import NetJsonRenderer -from apis_core.helper_functions.ContentType import GetContentTypes +from .apis_metainfo.models import TempEntityClass try: MAX_AGE = settings.MAX_AGE diff --git a/apis_core/apis_entities/api_renderers.py b/apis_core/apis_entities/api_renderers.py index 4c8a83b..786a1b0 100644 --- a/apis_core/apis_entities/api_renderers.py +++ b/apis_core/apis_entities/api_renderers.py @@ -1,7 +1,8 @@ -from apis_core.apis_tei.tei import TeiEntCreator from django.conf import settings from rest_framework import renderers +from apis_core.apis_tei.tei import TeiEntCreator + base_uri = getattr(settings, "APIS_BASE_URI", "http://apis.info") if base_uri.endswith("/"): base_uri = base_uri[:-1] diff --git a/apis_core/apis_entities/autocomplete3.py b/apis_core/apis_entities/autocomplete3.py index 812b04c..b8e611e 100644 --- a/apis_core/apis_entities/autocomplete3.py +++ b/apis_core/apis_entities/autocomplete3.py @@ -7,8 +7,6 @@ import dateutil.parser import requests -from apis_core.apis_metainfo.models import Collection, Uri -from apis_core.apis_vocabularies.models import VocabsBaseClass from dal import autocomplete from django import http from django.conf import settings @@ -16,6 +14,9 @@ from django.core.exceptions import FieldError from django.db.models import Q +from apis_core.apis_metainfo.models import Collection, Uri +from apis_core.apis_vocabularies.models import VocabsBaseClass + from .models import AbstractEntity diff --git a/apis_core/apis_entities/detail_views.py b/apis_core/apis_entities/detail_views.py index 85042d4..3ca0b32 100644 --- a/apis_core/apis_entities/detail_views.py +++ b/apis_core/apis_entities/detail_views.py @@ -1,8 +1,3 @@ -from apis_core.apis_labels.models import Label -from apis_core.apis_metainfo.models import Uri -from apis_core.apis_relations.models import AbstractRelation -from apis_core.apis_relations.tables import (LabelTableBase, - get_generic_relations_table) from django.conf import settings from django.db.models import Q from django.http import Http404, HttpResponse @@ -11,6 +6,12 @@ from django.views import View from django_tables2 import RequestConfig +from apis_core.apis_labels.models import Label +from apis_core.apis_metainfo.models import Uri +from apis_core.apis_relations.models import AbstractRelation +from apis_core.apis_relations.tables import (LabelTableBase, + get_generic_relations_table) + from .models import BASE_URI, TempEntityClass diff --git a/apis_core/apis_entities/filters.py b/apis_core/apis_entities/filters.py index 071660e..7908aba 100644 --- a/apis_core/apis_entities/filters.py +++ b/apis_core/apis_entities/filters.py @@ -2,10 +2,11 @@ from functools import reduce import django_filters +from django.conf import settings + from apis_core.apis_entities.models import * from apis_core.apis_metainfo.models import Collection from apis_core.apis_vocabularies.models import RelationBaseClass -from django.conf import settings # The following classes define the filter sets respective to their models. # Also by what was enabled in the global settings file (or disabled by not explicitley enabling it). diff --git a/apis_core/apis_entities/forms.py b/apis_core/apis_entities/forms.py index 9a61f44..af9fb7f 100644 --- a/apis_core/apis_entities/forms.py +++ b/apis_core/apis_entities/forms.py @@ -1,6 +1,4 @@ # -*- coding: utf-8 -*- -from apis_core.apis_metainfo.models import Collection -from apis_core.helper_functions import DateParser from crispy_forms.bootstrap import Accordion, AccordionGroup from crispy_forms.helper import FormHelper from crispy_forms.layout import Fieldset, Layout, Submit @@ -11,6 +9,9 @@ from django.forms import ModelChoiceField, ModelMultipleChoiceField from django.urls import reverse +from apis_core.apis_metainfo.models import Collection +from apis_core.helper_functions import DateParser + from .fields import ListSelect2, Select2Multiple from .models import AbstractEntity @@ -20,7 +21,6 @@ def save(self, *args, **kwargs): return self.entity def __init__(self, entity, *args, **kwargs): - attrs = { "data-placeholder": "Type to get suggestions", "data-minimum-input-length": 1, diff --git a/apis_core/apis_entities/list_view_event.py b/apis_core/apis_entities/list_view_event.py index 2d9c482..dbd84d7 100644 --- a/apis_core/apis_entities/list_view_event.py +++ b/apis_core/apis_entities/list_view_event.py @@ -1,5 +1,11 @@ import django_filters import django_tables2 as tables +from crispy_bootstrap5.bootstrap5 import BS5Accordion +from crispy_forms.bootstrap import AccordionGroup +from crispy_forms.helper import FormHelper +from crispy_forms.layout import Layout +from dal import autocomplete + from apis_core.apis_entities.models import Event from apis_core.apis_vocabularies.models import (EventEventRelation, EventType, EventWorkRelation, @@ -8,11 +14,6 @@ PlaceEventRelation) from apis_core.helper_functions.utils import get_child_classes from browsing.browsing_utils import GenericListView -from crispy_bootstrap5.bootstrap5 import BS5Accordion -from crispy_forms.bootstrap import AccordionGroup -from crispy_forms.helper import FormHelper -from crispy_forms.layout import Layout -from dal import autocomplete excluded_cols = [ "start_start_date", diff --git a/apis_core/apis_entities/list_view_institution.py b/apis_core/apis_entities/list_view_institution.py index f6fb1e2..d979008 100644 --- a/apis_core/apis_entities/list_view_institution.py +++ b/apis_core/apis_entities/list_view_institution.py @@ -1,5 +1,11 @@ import django_filters import django_tables2 as tables +from crispy_bootstrap5.bootstrap5 import BS5Accordion +from crispy_forms.bootstrap import AccordionGroup +from crispy_forms.helper import FormHelper +from crispy_forms.layout import Layout +from dal import autocomplete + from apis_core.apis_entities.models import Institution from apis_core.apis_vocabularies.models import (InstitutionEventRelation, InstitutionInstitutionRelation, @@ -9,11 +15,6 @@ PersonInstitutionRelation) from apis_core.helper_functions.utils import get_child_classes from browsing.browsing_utils import GenericListView -from crispy_bootstrap5.bootstrap5 import BS5Accordion -from crispy_forms.bootstrap import AccordionGroup -from crispy_forms.helper import FormHelper -from crispy_forms.layout import Layout -from dal import autocomplete excluded_cols = [ "start_start_date", diff --git a/apis_core/apis_entities/list_view_person.py b/apis_core/apis_entities/list_view_person.py index 70f2504..3b3b893 100644 --- a/apis_core/apis_entities/list_view_person.py +++ b/apis_core/apis_entities/list_view_person.py @@ -1,5 +1,11 @@ import django_filters import django_tables2 as tables +from crispy_bootstrap5.bootstrap5 import BS5Accordion +from crispy_forms.bootstrap import AccordionGroup +from crispy_forms.helper import FormHelper +from crispy_forms.layout import Layout +from dal import autocomplete + from apis_core.apis_entities.models import Person from apis_core.apis_vocabularies.models import (PersonInstitutionRelation, PersonPersonRelation, @@ -8,11 +14,6 @@ ProfessionType) from apis_core.helper_functions.utils import get_child_classes from browsing.browsing_utils import GenericListView -from crispy_bootstrap5.bootstrap5 import BS5Accordion -from crispy_forms.bootstrap import AccordionGroup -from crispy_forms.helper import FormHelper -from crispy_forms.layout import Layout -from dal import autocomplete excluded_cols = [ "start_start_date", diff --git a/apis_core/apis_entities/list_view_place.py b/apis_core/apis_entities/list_view_place.py index 073d4df..12bfc23 100644 --- a/apis_core/apis_entities/list_view_place.py +++ b/apis_core/apis_entities/list_view_place.py @@ -1,16 +1,17 @@ import django_filters import django_tables2 as tables -from apis_core.apis_entities.models import Place -from apis_core.apis_vocabularies.models import (PersonPlaceRelation, PlaceType, - PlaceWorkRelation) -from apis_core.helper_functions.utils import get_child_classes -from browsing.browsing_utils import GenericListView from crispy_bootstrap5.bootstrap5 import BS5Accordion from crispy_forms.bootstrap import AccordionGroup from crispy_forms.helper import FormHelper from crispy_forms.layout import Layout from dal import autocomplete +from apis_core.apis_entities.models import Place +from apis_core.apis_vocabularies.models import (PersonPlaceRelation, PlaceType, + PlaceWorkRelation) +from apis_core.helper_functions.utils import get_child_classes +from browsing.browsing_utils import GenericListView + excluded_cols = [ "start_start_date", "start_end_date", diff --git a/apis_core/apis_entities/list_view_uris.py b/apis_core/apis_entities/list_view_uris.py index 0b38932..89af860 100644 --- a/apis_core/apis_entities/list_view_uris.py +++ b/apis_core/apis_entities/list_view_uris.py @@ -1,12 +1,13 @@ import django_filters import django_tables2 as tables -from apis_core.apis_metainfo.models import Uri -from browsing.browsing_utils import GenericListView from crispy_bootstrap5.bootstrap5 import BS5Accordion from crispy_forms.bootstrap import AccordionGroup from crispy_forms.helper import FormHelper from crispy_forms.layout import Layout +from apis_core.apis_metainfo.models import Uri +from browsing.browsing_utils import GenericListView + class UriTable(tables.Table): id = tables.LinkColumn() diff --git a/apis_core/apis_entities/list_view_work.py b/apis_core/apis_entities/list_view_work.py index 8f0ed59..fa5947b 100644 --- a/apis_core/apis_entities/list_view_work.py +++ b/apis_core/apis_entities/list_view_work.py @@ -1,5 +1,11 @@ import django_filters import django_tables2 as tables +from crispy_bootstrap5.bootstrap5 import BS5Accordion +from crispy_forms.bootstrap import AccordionGroup +from crispy_forms.helper import FormHelper +from crispy_forms.layout import Layout +from dal import autocomplete + from apis_core.apis_entities.models import Work from apis_core.apis_vocabularies.models import (InstitutionWorkRelation, PersonWorkRelation, @@ -7,11 +13,6 @@ WorkWorkRelation) from apis_core.helper_functions.utils import get_child_classes from browsing.browsing_utils import GenericListView -from crispy_bootstrap5.bootstrap5 import BS5Accordion -from crispy_forms.bootstrap import AccordionGroup -from crispy_forms.helper import FormHelper -from crispy_forms.layout import Layout -from dal import autocomplete excluded_cols = [ "start_start_date", diff --git a/apis_core/apis_entities/models.py b/apis_core/apis_entities/models.py index 5a82bcc..fe7cfa1 100644 --- a/apis_core/apis_entities/models.py +++ b/apis_core/apis_entities/models.py @@ -3,17 +3,18 @@ import sys import unicodedata -from apis_core.apis_metainfo.models import TempEntityClass, Uri -from apis_core.apis_vocabularies.models import (EventType, InstitutionType, - PlaceType, ProfessionType, - Title, WorkType) -from apis_core.helper_functions import EntityRelationFieldGenerator from django.conf import settings from django.db import models from django.db.models import Q from django.db.models.signals import post_save from django.dispatch import receiver +from apis_core.apis_metainfo.models import TempEntityClass, Uri +from apis_core.apis_vocabularies.models import (EventType, InstitutionType, + PlaceType, ProfessionType, + Title, WorkType) +from apis_core.helper_functions import EntityRelationFieldGenerator + BASE_URI = getattr(settings, "APIS_BASE_URI", "http://apis.info/") DOMAIN_DEFAULT = getattr(settings, "APIS_DEFAULT_DOMAIN", "apis default") diff --git a/apis_core/apis_entities/tests.py b/apis_core/apis_entities/tests.py index e3a7331..0d06f85 100644 --- a/apis_core/apis_entities/tests.py +++ b/apis_core/apis_entities/tests.py @@ -1,8 +1,9 @@ -from apis_core.apis_entities.models import Person from django.apps import apps from django.contrib.auth.models import User from django.test import Client, TestCase +from apis_core.apis_entities.models import Person + client = Client() USER = {"username": "testuser", "password": "somepassword"} BAHR = {"name": "Bahr", "first_name": "Hermann", "start_date_written": "1900"} diff --git a/apis_core/apis_entities/views.py b/apis_core/apis_entities/views.py index 19a25ac..d807ef1 100644 --- a/apis_core/apis_entities/views.py +++ b/apis_core/apis_entities/views.py @@ -1,10 +1,5 @@ import importlib -from apis_core.apis_entities.models import AbstractEntity -from apis_core.apis_metainfo.models import Uri -from apis_core.apis_labels.models import Label -from apis_core.apis_relations.models import AbstractRelation -from apis_core.apis_relations.tables import LabelTableEdit, get_generic_relations_table from django.conf import settings from django.contrib.auth.decorators import login_required from django.contrib.contenttypes.models import ContentType @@ -18,9 +13,16 @@ from django.views import View from django.views.generic import DeleteView from django_tables2 import RequestConfig - from icecream import ic -from .forms import get_entities_form, MergeForm + +from apis_core.apis_entities.models import AbstractEntity +from apis_core.apis_labels.models import Label +from apis_core.apis_metainfo.models import Uri +from apis_core.apis_relations.models import AbstractRelation +from apis_core.apis_relations.tables import (LabelTableEdit, + get_generic_relations_table) + +from .forms import MergeForm, get_entities_form @method_decorator(login_required, name="dispatch") diff --git a/apis_core/apis_labels/admin.py b/apis_core/apis_labels/admin.py index 9901b47..878d43f 100644 --- a/apis_core/apis_labels/admin.py +++ b/apis_core/apis_labels/admin.py @@ -1,6 +1,5 @@ -from django.contrib import admin from csvexport.actions import csvexport - +from django.contrib import admin from .models import Label diff --git a/apis_core/apis_labels/serializers.py b/apis_core/apis_labels/serializers.py index a314c0a..6a57115 100644 --- a/apis_core/apis_labels/serializers.py +++ b/apis_core/apis_labels/serializers.py @@ -1,6 +1,7 @@ from rest_framework import serializers from apis_core.apis_vocabularies.serializers import LabelTypeMinimalSerializer + from .models import Label diff --git a/apis_core/apis_labels/views.py b/apis_core/apis_labels/views.py index 7e65352..f3935a5 100644 --- a/apis_core/apis_labels/views.py +++ b/apis_core/apis_labels/views.py @@ -1,7 +1,6 @@ from django.contrib.auth.decorators import login_required from django.http import HttpResponse - from .models import Label diff --git a/apis_core/apis_metainfo/admin.py b/apis_core/apis_metainfo/admin.py index 729662e..36a8db5 100644 --- a/apis_core/apis_metainfo/admin.py +++ b/apis_core/apis_metainfo/admin.py @@ -1,6 +1,6 @@ from django.contrib import admin -from .models import Source, Collection, Text, Uri +from .models import Collection, Source, Text, Uri admin.site.register(Source) admin.site.register(Collection) diff --git a/apis_core/apis_metainfo/api_views.py b/apis_core/apis_metainfo/api_views.py index 8ecfde5..4776d89 100644 --- a/apis_core/apis_metainfo/api_views.py +++ b/apis_core/apis_metainfo/api_views.py @@ -1,13 +1,9 @@ from rest_framework import viewsets -from .models import Collection, Text, Source, Uri, TempEntityClass -from .serializers import ( - CollectionSerializer, - TextSerializer, - SourceSerializer, - UriSerializer, - TempEntityClassSerializer, -) +from .models import Collection, Source, TempEntityClass, Text, Uri +from .serializers import (CollectionSerializer, SourceSerializer, + TempEntityClassSerializer, TextSerializer, + UriSerializer) class CollectionViewSet(viewsets.ModelViewSet): diff --git a/apis_core/apis_metainfo/models.py b/apis_core/apis_metainfo/models.py index 251ae75..3534e5c 100644 --- a/apis_core/apis_metainfo/models.py +++ b/apis_core/apis_metainfo/models.py @@ -8,12 +8,12 @@ from django.db import models from django.db.models.query import QuerySet from django.urls import reverse -from model_utils.managers import InheritanceManager from icecream import ic +from model_utils.managers import InheritanceManager from apis_core.apis_labels.models import Label -from apis_core.apis_vocabularies.models import CollectionType, LabelType, TextType - +from apis_core.apis_vocabularies.models import (CollectionType, LabelType, + TextType) from apis_core.helper_functions import DateParser diff --git a/apis_core/apis_metainfo/tables.py b/apis_core/apis_metainfo/tables.py index a86606a..2f83b4f 100644 --- a/apis_core/apis_metainfo/tables.py +++ b/apis_core/apis_metainfo/tables.py @@ -1,7 +1,6 @@ from django.db.models import F from django.utils.html import format_html - # generic order_FOO methods for start_date_written and end_date_written to be used in all kinds of tables where a queryset is loaded # whose model has start_date_written and end_date_written. These methods order the *_date_written by their corresponding # parsed date objects. diff --git a/apis_core/apis_metainfo/urls.py b/apis_core/apis_metainfo/urls.py index da2e366..be9df1d 100644 --- a/apis_core/apis_metainfo/urls.py +++ b/apis_core/apis_metainfo/urls.py @@ -1,8 +1,9 @@ from django.urls import path -from . import views from apis_core.apis_entities.list_view_uris import UriListView +from . import views + app_name = "apis_metainfo" urlpatterns = [ diff --git a/apis_core/apis_metainfo/views.py b/apis_core/apis_metainfo/views.py index b1dae15..f316805 100644 --- a/apis_core/apis_metainfo/views.py +++ b/apis_core/apis_metainfo/views.py @@ -1,16 +1,16 @@ +from django.conf import settings from django.contrib.auth.decorators import login_required from django.http import HttpResponse from django.urls import reverse_lazy -from django.conf import settings from django.utils.decorators import method_decorator from django.views.generic.detail import DetailView from django.views.generic.edit import DeleteView from browsing.browsing_utils import BaseCreateView, BaseUpdateView + from .forms import UriForm from .models import Uri - PROJECT_NAME = settings.PROJECT_NAME diff --git a/apis_core/apis_relations/autocomplete_light_registry.py b/apis_core/apis_relations/autocomplete_light_registry.py index 3335ba2..7348904 100644 --- a/apis_core/apis_relations/autocomplete_light_registry.py +++ b/apis_core/apis_relations/autocomplete_light_registry.py @@ -9,10 +9,13 @@ import requests from django.db.models import Q -from apis_core.apis_entities.models import Place, Person, Institution, Event, Work +from apis_core.apis_entities.models import (Event, Institution, Person, Place, + Work) from apis_core.apis_metainfo.models import Uri -from apis_core.apis_relations.models import PersonPerson, PersonPlace, PersonInstitution -from apis_core.default_settings.NER_settings import autocomp_settings as ac_settings +from apis_core.apis_relations.models import (PersonInstitution, PersonPerson, + PersonPlace) +from apis_core.default_settings.NER_settings import \ + autocomp_settings as ac_settings class StanbolAutocompleteBase(al.AutocompleteListTemplate): diff --git a/apis_core/apis_relations/forms.py b/apis_core/apis_relations/forms.py index 45cb71c..d327af1 100644 --- a/apis_core/apis_relations/forms.py +++ b/apis_core/apis_relations/forms.py @@ -8,7 +8,6 @@ from apis_core.apis_labels.models import Label from apis_core.helper_functions import DateParser - ############################################## # Generic ############################################## diff --git a/apis_core/apis_relations/forms2.py b/apis_core/apis_relations/forms2.py index 01d670c..09b0206 100644 --- a/apis_core/apis_relations/forms2.py +++ b/apis_core/apis_relations/forms2.py @@ -11,13 +11,14 @@ from django.db.models import Q from django.urls import reverse from django.utils.translation import gettext_lazy as _ + from apis_core.apis_entities.fields import ListSelect2 from apis_core.apis_entities.models import AbstractEntity - # from dal.autocomplete import ListSelect2 from apis_core.apis_metainfo.models import TempEntityClass, Uri from apis_core.apis_relations.models import AbstractRelation from apis_core.helper_functions import DateParser + from .tables import get_generic_relations_table # from dal.autocomplete import ListSelect2 diff --git a/apis_core/apis_relations/models.py b/apis_core/apis_relations/models.py index e98411e..8e93253 100644 --- a/apis_core/apis_relations/models.py +++ b/apis_core/apis_relations/models.py @@ -8,7 +8,6 @@ from apis_core.apis_entities.models import Person from apis_core.apis_metainfo.models import TempEntityClass - ####################################################################### # # AbstractRelation diff --git a/apis_core/apis_relations/serializers.py b/apis_core/apis_relations/serializers.py index beedd01..e13a3f6 100644 --- a/apis_core/apis_relations/serializers.py +++ b/apis_core/apis_relations/serializers.py @@ -1,26 +1,14 @@ from rest_framework import serializers -from apis_core.apis_entities.serializers import PersonSerializer, PlaceSerializer -from apis_core.apis_vocabularies.serializers import ( - PersonPlaceRelationSerializer, -) -from .models import ( - InstitutionInstitution, - PersonInstitution, - PersonPlace, - PersonPerson, - PersonEvent, - PersonWork, - InstitutionPlace, - InstitutionEvent, - InstitutionWork, - PlaceEvent, - PlaceWork, - PlacePlace, - EventWork, - EventEvent, - WorkWork, -) +from apis_core.apis_entities.serializers import (PersonSerializer, + PlaceSerializer) +from apis_core.apis_vocabularies.serializers import \ + PersonPlaceRelationSerializer + +from .models import (EventEvent, EventWork, InstitutionEvent, + InstitutionInstitution, InstitutionPlace, InstitutionWork, + PersonEvent, PersonInstitution, PersonPerson, PersonPlace, + PersonWork, PlaceEvent, PlacePlace, PlaceWork, WorkWork) class InstitutionInstitutionSerializer(serializers.HyperlinkedModelSerializer): diff --git a/apis_core/apis_relations/tables.py b/apis_core/apis_relations/tables.py index e0d1a3f..3d12f1e 100644 --- a/apis_core/apis_relations/tables.py +++ b/apis_core/apis_relations/tables.py @@ -4,12 +4,10 @@ from apis_core.apis_labels.models import Label from apis_core.apis_metainfo.models import Uri -from apis_core.apis_metainfo.tables import ( - generic_order_start_date_written, - generic_order_end_date_written, - generic_render_start_date_written, - generic_render_end_date_written, -) +from apis_core.apis_metainfo.tables import (generic_order_end_date_written, + generic_order_start_date_written, + generic_render_end_date_written, + generic_render_start_date_written) from apis_core.apis_relations.models import AbstractRelation empty_text_default = "There are currently no relations" diff --git a/apis_core/apis_relations/views.py b/apis_core/apis_relations/views.py index 4318984..d4af809 100644 --- a/apis_core/apis_relations/views.py +++ b/apis_core/apis_relations/views.py @@ -1,43 +1,22 @@ -import re import inspect - -from apis_core.apis_metainfo.models import TempEntityClass -from django.template import loader +import re from django.contrib.auth.decorators import login_required from django.contrib.contenttypes.models import ContentType -from django.http import HttpResponse, Http404 -from apis_core.apis_relations import forms as relation_form_module +from django.http import Http404, HttpResponse +from django.template import loader -from apis_core.apis_entities.models import ( - Person, - Institution, - Place, - Event, - Work, - AbstractEntity, -) +from apis_core.apis_entities.models import (AbstractEntity, Event, Institution, + Person, Place, Work) from apis_core.apis_labels.models import Label -from apis_core.apis_metainfo.models import Uri -from .forms2 import GenericRelationForm -from .models import ( - PersonPlace, - PersonPerson, - PersonInstitution, - InstitutionPlace, - InstitutionInstitution, - PlacePlace, - PersonEvent, - InstitutionEvent, - PlaceEvent, - PersonWork, - InstitutionWork, - PlaceWork, - EventWork, - WorkWork, - EventEvent, -) +from apis_core.apis_metainfo.models import TempEntityClass, Uri +from apis_core.apis_relations import forms as relation_form_module +from .forms2 import GenericRelationForm +from .models import (EventEvent, EventWork, InstitutionEvent, + InstitutionInstitution, InstitutionPlace, InstitutionWork, + PersonEvent, PersonInstitution, PersonPerson, PersonPlace, + PersonWork, PlaceEvent, PlacePlace, PlaceWork, WorkWork) from .tables import LabelTableEdit form_module_list = [relation_form_module] diff --git a/apis_core/apis_tei/tei.py b/apis_core/apis_tei/tei.py index 91d251e..720bd62 100644 --- a/apis_core/apis_tei/tei.py +++ b/apis_core/apis_tei/tei.py @@ -1,19 +1,16 @@ +import pprint +from collections import defaultdict from xml.sax.saxutils import escape, unescape import lxml.etree as ET - from django.conf import settings from django.utils.text import slugify -from .partials import TEI_NSMAP, tei_gen_header - +from apis_core.apis_entities.models import (Event, Institution, Person, Place, + Work) from apis_core.apis_metainfo.models import Text -from apis_core.apis_entities.models import Person, Place, Event, Work, Institution - -from collections import defaultdict - -import pprint +from .partials import TEI_NSMAP, tei_gen_header pp = pprint.PrettyPrinter(indent=4) diff --git a/apis_core/apis_tei/tei_urls.py b/apis_core/apis_tei/tei_urls.py index 1c2ce6b..fecd00f 100644 --- a/apis_core/apis_tei/tei_urls.py +++ b/apis_core/apis_tei/tei_urls.py @@ -1,9 +1,9 @@ from django.urls import path -from .tei_ac import TeiEntAc, TeiCompleterAc - from apis_core.apis_tei import views +from .tei_ac import TeiCompleterAc, TeiEntAc + app_name = "apis_tei" urlpatterns = [ diff --git a/apis_core/apis_tei/tei_utils.py b/apis_core/apis_tei/tei_utils.py index 8f33130..e2ed397 100644 --- a/apis_core/apis_tei/tei_utils.py +++ b/apis_core/apis_tei/tei_utils.py @@ -1,8 +1,9 @@ import lxml.etree as ET from django.conf import settings from django.template.loader import get_template -from apis_core.apis_entities.models import Work, Place, Person, Institution -from apis_core.apis_relations.models import PlacePlace, PersonWork + +from apis_core.apis_entities.models import Institution, Person, Place, Work +from apis_core.apis_relations.models import PersonWork, PlacePlace from apis_core.apis_vocabularies.models import PersonWorkRelation from apis_core.helper_functions.utils import get_child_classes diff --git a/apis_core/apis_tei/views.py b/apis_core/apis_tei/views.py index eea869e..be72f10 100644 --- a/apis_core/apis_tei/views.py +++ b/apis_core/apis_tei/views.py @@ -1,13 +1,12 @@ import lxml.etree as ET - from django.http import HttpResponse from django.shortcuts import get_object_or_404, redirect -from .tei_utils import get_node_from_template - -from apis_core.apis_metainfo.models import Uri -from apis_core.apis_entities.models import Person, Place, Institution, Work from apis_core.apis_entities.detail_views import get_object_from_pk_or_uri +from apis_core.apis_entities.models import Institution, Person, Place, Work +from apis_core.apis_metainfo.models import Uri + +from .tei_utils import get_node_from_template def person_as_tei(request, pk): diff --git a/apis_core/apis_vis/api_views.py b/apis_core/apis_vis/api_views.py index f313e22..55bc07d 100644 --- a/apis_core/apis_vis/api_views.py +++ b/apis_core/apis_vis/api_views.py @@ -1,9 +1,9 @@ -from rest_framework.generics import ListAPIView from django_filters.rest_framework import DjangoFilterBackend from rest_framework import filters from rest_framework.generics import ListAPIView from apis_core.apis_relations.models import AbstractRelation + from .serializers import * diff --git a/apis_core/apis_vis/urls.py b/apis_core/apis_vis/urls.py index c0c411b..1586fa0 100644 --- a/apis_core/apis_vis/urls.py +++ b/apis_core/apis_vis/urls.py @@ -1,6 +1,6 @@ from django.conf.urls import url -from . import views, api_views +from . import api_views, views app_name = "apis_vis" diff --git a/apis_core/apis_vis/views.py b/apis_core/apis_vis/views.py index 408feba..ef8db63 100644 --- a/apis_core/apis_vis/views.py +++ b/apis_core/apis_vis/views.py @@ -4,6 +4,7 @@ from django.views.generic import TemplateView from apis_core.apis_relations.models import * + from .utils import calculate_age diff --git a/apis_core/apis_vocabularies/admin.py b/apis_core/apis_vocabularies/admin.py index bfa027b..ef8073a 100644 --- a/apis_core/apis_vocabularies/admin.py +++ b/apis_core/apis_vocabularies/admin.py @@ -1,9 +1,9 @@ +from csvexport.actions import csvexport from dal import autocomplete from django.apps import apps from django.conf import settings from django.contrib import admin from django.urls import reverse -from csvexport.actions import csvexport class BaseAdminVocabularies(admin.ModelAdmin): diff --git a/apis_core/apis_vocabularies/api_renderers.py b/apis_core/apis_vocabularies/api_renderers.py index 18393bd..e948f02 100644 --- a/apis_core/apis_vocabularies/api_renderers.py +++ b/apis_core/apis_vocabularies/api_renderers.py @@ -1,8 +1,8 @@ +import skosify from django.conf import settings -from rdflib import Graph, URIRef, Literal -from rdflib.namespace import SKOS, RDF, DC, RDFS +from rdflib import Graph, Literal, URIRef +from rdflib.namespace import DC, RDF, RDFS, SKOS from rest_framework import renderers -import skosify try: from webpage.metadata import PROJECT_METADATA diff --git a/apis_core/apis_vocabularies/api_views.py b/apis_core/apis_vocabularies/api_views.py index 57539c8..f2443b9 100644 --- a/apis_core/apis_vocabularies/api_views.py +++ b/apis_core/apis_vocabularies/api_views.py @@ -1,60 +1,36 @@ from django.contrib.auth.models import User from rest_framework import viewsets -from .models import ( - InstitutionInstitutionRelation, - TextType, - CollectionType, - VocabsBaseClass, - InstitutionType, - ProfessionType, - PlaceType, - PersonInstitutionRelation, - PersonPlaceRelation, - PersonPersonRelation, - VocabNames, - InstitutionPlaceRelation, - PersonEventRelation, - PersonWorkRelation, - InstitutionEventRelation, - InstitutionWorkRelation, - PlaceWorkRelation, - PlaceEventRelation, - PlacePlaceRelation, - EventWorkRelation, - EventEventRelation, - WorkWorkRelation, - EventType, - WorkType, -) -from .serializers import ( - InstitutionInstitutionRelationSerializer, - TextTypeSerializer, - CollectionTypeSerializer, - VocabsBaseClassSerializer, - InstitutionTypeSerializer, - ProfessionTypeSerializer, - InstitutionPlaceRelationSerializer, - PlaceTypeSerializer, - PersonInstitutionRelationSerializer, - PersonPlaceRelationSerializer, - UserAccSerializer, - VocabNamesSerializer, - PersonPersonRelationSerializer, - PersonEventRelationSerializer, - PersonWorkRelationSerializer, - InstitutionEventRelationSerializer, - InstitutionWorkRelationSerializer, - PlaceEventRelationSerializer, - PlaceWorkRelationSerializer, - PlacePlaceRelationSerializer, - EventWorkRelationSerializer, - EventEventRelationSerializer, - WorkWorkRelationSerializer, - EventTypeSerializer, - WorkTypeSerializer, -) - +from .models import (CollectionType, EventEventRelation, EventType, + EventWorkRelation, InstitutionEventRelation, + InstitutionInstitutionRelation, InstitutionPlaceRelation, + InstitutionType, InstitutionWorkRelation, + PersonEventRelation, PersonInstitutionRelation, + PersonPersonRelation, PersonPlaceRelation, + PersonWorkRelation, PlaceEventRelation, + PlacePlaceRelation, PlaceType, PlaceWorkRelation, + ProfessionType, TextType, VocabNames, VocabsBaseClass, + WorkType, WorkWorkRelation) +from .serializers import (CollectionTypeSerializer, + EventEventRelationSerializer, EventTypeSerializer, + EventWorkRelationSerializer, + InstitutionEventRelationSerializer, + InstitutionInstitutionRelationSerializer, + InstitutionPlaceRelationSerializer, + InstitutionTypeSerializer, + InstitutionWorkRelationSerializer, + PersonEventRelationSerializer, + PersonInstitutionRelationSerializer, + PersonPersonRelationSerializer, + PersonPlaceRelationSerializer, + PersonWorkRelationSerializer, + PlaceEventRelationSerializer, + PlacePlaceRelationSerializer, PlaceTypeSerializer, + PlaceWorkRelationSerializer, + ProfessionTypeSerializer, TextTypeSerializer, + UserAccSerializer, VocabNamesSerializer, + VocabsBaseClassSerializer, WorkTypeSerializer, + WorkWorkRelationSerializer) ########################################################### # diff --git a/apis_core/apis_vocabularies/serializers.py b/apis_core/apis_vocabularies/serializers.py index c8ea150..07e8e79 100644 --- a/apis_core/apis_vocabularies/serializers.py +++ b/apis_core/apis_vocabularies/serializers.py @@ -2,34 +2,16 @@ from django.db.models.query import QuerySet from rest_framework import serializers -from .models import ( - InstitutionInstitutionRelation, - TextType, - CollectionType, - VocabsBaseClass, - InstitutionType, - ProfessionType, - PlaceType, - PersonInstitutionRelation, - InstitutionPlaceRelation, - PersonPlaceRelation, - VocabNames, - PersonPersonRelation, - PersonEventRelation, - PersonWorkRelation, - InstitutionEventRelation, - InstitutionWorkRelation, - PlaceEventRelation, - PlaceWorkRelation, - PlacePlaceRelation, - EventWorkRelation, - EventEventRelation, - WorkWorkRelation, - EventType, - WorkType, - LabelType, -) - +from .models import (CollectionType, EventEventRelation, EventType, + EventWorkRelation, InstitutionEventRelation, + InstitutionInstitutionRelation, InstitutionPlaceRelation, + InstitutionType, InstitutionWorkRelation, LabelType, + PersonEventRelation, PersonInstitutionRelation, + PersonPersonRelation, PersonPlaceRelation, + PersonWorkRelation, PlaceEventRelation, + PlacePlaceRelation, PlaceType, PlaceWorkRelation, + ProfessionType, TextType, VocabNames, VocabsBaseClass, + WorkType, WorkWorkRelation) ########################################################### # diff --git a/apis_core/apis_vocabularies/urls.py b/apis_core/apis_vocabularies/urls.py index e840527..d4ae9e8 100644 --- a/apis_core/apis_vocabularies/urls.py +++ b/apis_core/apis_vocabularies/urls.py @@ -1,6 +1,7 @@ from django.urls import path -from apis_core.apis_entities.autocomplete3 import GenericVocabulariesAutocomplete +from apis_core.apis_entities.autocomplete3 import \ + GenericVocabulariesAutocomplete from apis_core.apis_vocabularies import views app_name = "apis_vocabularies" diff --git a/apis_core/helper_functions/ContentType.py b/apis_core/helper_functions/ContentType.py index bad0671..e9f96d0 100644 --- a/apis_core/helper_functions/ContentType.py +++ b/apis_core/helper_functions/ContentType.py @@ -1,5 +1,6 @@ import importlib import inspect + from django.contrib.contenttypes.models import ContentType from django.db.models.base import ModelBase diff --git a/apis_core/openrefine/views.py b/apis_core/openrefine/views.py index d1421c8..87fe1dd 100644 --- a/apis_core/openrefine/views.py +++ b/apis_core/openrefine/views.py @@ -1,18 +1,13 @@ import json + from django.db.models import Q from django.http import JsonResponse from django.views.decorators.csrf import csrf_exempt +from apis_core.apis_entities.models import (Event, Institution, Person, Place, + TempEntityClass, Work) -from apis_core.apis_entities.models import ( - Person, - Place, - Institution, - Work, - Event, - TempEntityClass, -) -from .utils import get_service_mainfest, get_properties +from .utils import get_properties, get_service_mainfest @csrf_exempt diff --git a/apis_core/urls.py b/apis_core/urls.py index 4f37615..b0b6b87 100644 --- a/apis_core/urls.py +++ b/apis_core/urls.py @@ -1,13 +1,13 @@ import os -from django.urls import path + from django.conf.urls import include +from django.urls import path from rest_framework import routers from apis_core.api_routers import views - +from apis_core.apis_metainfo.views import beacon from apis_core.apis_vocabularies.api_views import UserViewSet from apis_core.helper_functions.ContentType import GetContentTypes -from apis_core.apis_metainfo.views import beacon app_name = "apis_core" From e6a562360b17f4aa9656e9c3a96c8cedd4e06218 Mon Sep 17 00:00:00 2001 From: csae8092 Date: Thu, 21 Dec 2023 09:21:04 +0100 Subject: [PATCH 6/9] * test for merge view * removed not needed merge view (from list view) --- apis_core/apis_entities/forms.py | 3 +- apis_core/apis_entities/merge_views.py | 58 -------------------------- apis_core/apis_entities/tests.py | 34 +++++++++++++-- apis_core/apis_entities/urls.py | 3 +- apis_core/apis_metainfo/models.py | 9 ++-- 5 files changed, 39 insertions(+), 68 deletions(-) delete mode 100644 apis_core/apis_entities/merge_views.py diff --git a/apis_core/apis_entities/forms.py b/apis_core/apis_entities/forms.py index af9fb7f..6587005 100644 --- a/apis_core/apis_entities/forms.py +++ b/apis_core/apis_entities/forms.py @@ -203,7 +203,8 @@ def sort_fields_list(list_unsorted, entity_label): raise Exception( "An item of the entity setting 'form_order' list was not used. \n" - "This propably indicates that the 'form_order' settings is out of sync with the effective django models.\n" + "This propably indicates that the 'form_order' settings is out \n" + "of sync with the effective django models.\n" f"The relevant entity is: {entity_label}\n" f"And the differences between used list and settings list are: {differences}" ) diff --git a/apis_core/apis_entities/merge_views.py b/apis_core/apis_entities/merge_views.py deleted file mode 100644 index 467d903..0000000 --- a/apis_core/apis_entities/merge_views.py +++ /dev/null @@ -1,58 +0,0 @@ -from django.contrib.auth.decorators import login_required -from django.contrib.contenttypes.models import ContentType -from django.core.exceptions import ObjectDoesNotExist -from django.http import HttpResponseRedirect - - -@login_required -def merge_objects(request): - go_back = request.META.get("HTTP_REFERER") - print("go back: {}".format(go_back)) - if request.method == "POST": - keep = request.POST.get("keep", None) - remove = request.POST.getlist("remove", None) - model_name = request.POST.get("model_name", None) - app_name = request.POST.get("app_name", None) - print("##############################") - print(keep, remove, model_name, app_name) - if keep and remove and model_name and app_name: - print("all good, let's merge") - try: - ct = ContentType.objects.get( - app_label=app_name, model=model_name - ).model_class() - except ObjectDoesNotExist: - ct = None - print('no "keep" object found') - return HttpResponseRedirect(go_back) - if ct: - try: - keep_obj = ct.objects.filter(pk=keep)[0] - except IndexError: - print("No matching object to keep found") - return HttpResponseRedirect(go_back) - remove_objs = ct.objects.filter(pk__in=remove) - keep_obj.merge_with(remove_objs) - return HttpResponseRedirect(go_back) - else: - return HttpResponseRedirect(go_back) - elif remove and model_name and app_name: - print("all good, let's delete") - try: - ct = ContentType.objects.get( - app_label=app_name, model=model_name - ).model_class() - except ObjectDoesNotExist: - ct = None - if ct: - remove_objs = ct.objects.filter(pk__in=remove) - if len(remove_objs) > 0: - for x in remove_objs: - x.delete() - print("deleted: {}".format(x)) - return HttpResponseRedirect(go_back) - else: - return HttpResponseRedirect(go_back) - else: - print("ui, something went wrong") - return HttpResponseRedirect(go_back) diff --git a/apis_core/apis_entities/tests.py b/apis_core/apis_entities/tests.py index 0d06f85..beeb7f4 100644 --- a/apis_core/apis_entities/tests.py +++ b/apis_core/apis_entities/tests.py @@ -1,8 +1,10 @@ from django.apps import apps from django.contrib.auth.models import User from django.test import Client, TestCase +from django.urls import reverse from apis_core.apis_entities.models import Person +from apis_core.apis_entities.forms import get_entities_form client = Client() USER = {"username": "testuser", "password": "somepassword"} @@ -65,16 +67,42 @@ def test_004_createviews_logged_in(self): response = client.get(url, {"pk": item.id}) self.assertEqual(response.status_code, 200) - def test_004_check_fixtures(self): + def test_005_check_fixtures(self): items = Person.objects.all().count() self.assertEqual(items, 2) - def test_005_create_person(self): + def test_006_create_person(self): item, created = Person.objects.get_or_create(**BAHR) self.assertTrue(created) self.assertEqual(item.name, "Bahr") - def test_006_delete_person(self): + def test_007_delete_person(self): item, _ = Person.objects.get_or_create(**BAHR) self.assertEqual(item.name, "Bahr") item.delete() + + def test_008_get_entities_form(self): + for x in ["person", "place", "event", "work", "institution"]: + data = {"name": f"{x}__hansi", "start_date_written": "1900"} + form_class = get_entities_form(x.title()) + form = form_class(data=data) + self.assertTrue(form.is_valid()) + created_object = form.save() + self.assertTrue(created_object.id > 0) + + def test_009_merge_view(self): + client.login(**USER) + before = Person.objects.all().count() + source = Person.objects.all().first() + target = Person.objects.all().last() + target_uri = target.uri_set.all().first() + form_kwargs = {"entity": "person"} + form_kwargs["ent_merge_pk"] = source.id + url = reverse( + "apis:apis_entities:merge_view", + kwargs={"entity": "person", "ent_merge_pk": source.id}, + ) + response = client.post(url, {"entity": target_uri}) + self.assertEqual(response.status_code, 302) + after = Person.objects.all().count() + self.assertTrue(before > after) diff --git a/apis_core/apis_entities/urls.py b/apis_core/apis_entities/urls.py index beacd81..c5d6b00 100644 --- a/apis_core/apis_entities/urls.py +++ b/apis_core/apis_entities/urls.py @@ -1,6 +1,6 @@ from django.urls import path -from . import detail_views, merge_views, views +from . import detail_views, views from .autocomplete3 import GenericEntitiesAutocomplete from .list_view_event import EventListView from .list_view_institution import InstitutionListView @@ -76,5 +76,4 @@ GenericEntitiesAutocomplete.as_view(), name="generic_entities_autocomplete", ), - path("merge-objects/", merge_views.merge_objects, name="merge_objects"), ] diff --git a/apis_core/apis_metainfo/models.py b/apis_core/apis_metainfo/models.py index 3534e5c..25117bd 100644 --- a/apis_core/apis_metainfo/models.py +++ b/apis_core/apis_metainfo/models.py @@ -8,12 +8,14 @@ from django.db import models from django.db.models.query import QuerySet from django.urls import reverse -from icecream import ic from model_utils.managers import InheritanceManager from apis_core.apis_labels.models import Label -from apis_core.apis_vocabularies.models import (CollectionType, LabelType, - TextType) +from apis_core.apis_vocabularies.models import ( + CollectionType, + LabelType, + TextType, +) from apis_core.helper_functions import DateParser @@ -221,7 +223,6 @@ def get_delete_url(self): def merge_with(self, entities): e_a_pk = self.pk e_a = type(self).__name__ - ic(e_a) self_model_class = ContentType.objects.get( app_label="apis_entities", model__iexact=e_a ).model_class() From f8e62cdf999109ec61c05d0ac998538dfa70b971 Mon Sep 17 00:00:00 2001 From: csae8092 Date: Thu, 21 Dec 2023 15:07:04 +0100 Subject: [PATCH 7/9] delete views are working (but there is an issue with db migrated from sql) --- .env | 2 +- .gitignore | 1 + .../apis_entities/confirm_delete.html | 48 +++++++++---------- apis_core/apis_entities/views.py | 7 +-- apis_core/apis_relations/models.py | 4 -- 5 files changed, 28 insertions(+), 34 deletions(-) diff --git a/.env b/.env index 49dedd5..6225554 100644 --- a/.env +++ b/.env @@ -1,4 +1,4 @@ -POSTGRES_DB=pmb +POSTGRES_DB=pmb_play # NEW_PMB=True # POSTGRES_HOST=172.17.0.1 DEBUG=True diff --git a/.gitignore b/.gitignore index a1cc8c3..44de1ae 100644 --- a/.gitignore +++ b/.gitignore @@ -168,3 +168,4 @@ pmb_dump.sql .secret play.ipynb pmb_play_dump.sql +notes.sql diff --git a/apis_core/apis_entities/templates/apis_entities/confirm_delete.html b/apis_core/apis_entities/templates/apis_entities/confirm_delete.html index deb0052..a616931 100644 --- a/apis_core/apis_entities/templates/apis_entities/confirm_delete.html +++ b/apis_core/apis_entities/templates/apis_entities/confirm_delete.html @@ -1,28 +1,28 @@ -{% extends "webpage/base.html" %} +{% extends "base.html" %} +{% block title %} Lösche: {{ object }} ?{% endblock %} + {% block content %} -