From f9fbecca43b26a9ecb835478eeb7576666df5801 Mon Sep 17 00:00:00 2001 From: csae8092 Date: Mon, 11 Dec 2023 17:51:07 +0100 Subject: [PATCH] well, it saves the relation --- apis_core/apis_relations/forms2.py | 3 +++ .../templates/apis_relations/_ajax_form.html | 2 +- apis_core/apis_relations/views.py | 10 ++++++---- requirements.txt | 2 ++ 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/apis_core/apis_relations/forms2.py b/apis_core/apis_relations/forms2.py index 08b38b1..d206fad 100644 --- a/apis_core/apis_relations/forms2.py +++ b/apis_core/apis_relations/forms2.py @@ -78,6 +78,7 @@ def save(self, site_instance, instance=None, commit=True): :return: instance of relation """ cd = self.cleaned_data + print(cd) if instance: x = self.relation_form.objects.get(pk=instance) else: @@ -87,10 +88,12 @@ def save(self, site_instance, instance=None, commit=True): x.end_date_written = cd["end_date_written"] x.notes = cd["notes"] x.references = cd["references"] + print(self.rel_accessor) setattr(x, self.rel_accessor[3], site_instance) target = AbstractEntity.get_entity_class_of_name(self.rel_accessor[0]) t1 = target.get_or_create_uri(cd["target"]) if not t1: + print(self.rel_accessor) t1 = RDFParser(cd["target"], self.rel_accessor[0]).get_or_create() setattr(x, self.rel_accessor[2], t1) if commit: diff --git a/apis_core/apis_relations/templates/apis_relations/_ajax_form.html b/apis_core/apis_relations/templates/apis_relations/_ajax_form.html index bc71691..0195c8b 100644 --- a/apis_core/apis_relations/templates/apis_relations/_ajax_form.html +++ b/apis_core/apis_relations/templates/apis_relations/_ajax_form.html @@ -1,6 +1,6 @@
-
+ {% load crispy_forms_tags %} {% crispy form form.helper %}
diff --git a/apis_core/apis_relations/views.py b/apis_core/apis_relations/views.py index fbac98d..c59100f 100644 --- a/apis_core/apis_relations/views.py +++ b/apis_core/apis_relations/views.py @@ -2,6 +2,8 @@ import re import inspect +from icecream import ic + from django.template import loader from django.conf import settings @@ -177,7 +179,7 @@ def get_form_ajax(request): form_context = { "entity_type": entity_type_str, "form": form, - "type1": FormName, + "form_name": FormName, "url2": "save_ajax_" + FormName, "button_text": ButtonText, "ObjectID": ObjectID, @@ -201,6 +203,9 @@ def save_ajax_form(request, entity_type, kind_form, SiteID, ObjectID=False): instance_id = ObjectID entity_type_str = entity_type entity_type = AbstractEntity.get_entity_class_of_name(entity_type) + ic(entity_type) + ic(kind_form) + ic(SiteID) form_match = re.match(r"([A-Z][a-z]+)([A-Z][a-z]+)?(Highlighter)?Form", kind_form) form_dict = {"data": request.POST, "entity_type": entity_type, "request": request} @@ -222,9 +227,6 @@ def save_ajax_form(request, entity_type, kind_form, SiteID, ObjectID=False): else: form_class = form_class_dict[kind_form] form = form_class(**form_dict) - print("form.is_valid()#################") - print(form.is_valid()) - print(form.errors) if form.is_valid(): site_instance = entity_type.objects.get(pk=SiteID) hl_text = None diff --git a/requirements.txt b/requirements.txt index 886571e..247c843 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +apis-override-select2js-0.1 acdh-django-browsing acdh-id-reconciler>=0.2,<1 acdh-tei-pyutils>=0.34,<1 @@ -16,3 +17,4 @@ psycopg2 pyocclient==0.6 PyYAML>=6.0.1,<7 rdflib +icecream \ No newline at end of file