Skip to content

Commit

Permalink
well, it saves the relation
Browse files Browse the repository at this point in the history
  • Loading branch information
csae8092 committed Dec 11, 2023
1 parent 50d62a4 commit f9fbecc
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
3 changes: 3 additions & 0 deletions apis_core/apis_relations/forms2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

<div id="div_{{type1}}{{InstanceID}}">
<form action="/apis/relations/ajax/save/place/PlacePlaceForm/{{ SiteID }}/" enctype="multipart/form-data" method="post" id="form_{{type1}}" class="form ajax_form {{url2}}" data-replace="#message-form">
<form action="/apis/relations/ajax/save/{{ entity_type }}/{{ form_name }}/{{ SiteID }}/" enctype="multipart/form-data" method="post" id="form_{{type1}}" class="form ajax_form {{url2}}" data-replace="#message-form">
{% load crispy_forms_tags %}
{% crispy form form.helper %}
<div class="form-actions">
Expand Down
10 changes: 6 additions & 4 deletions apis_core/apis_relations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import re
import inspect

from icecream import ic

from django.template import loader

from django.conf import settings
Expand Down Expand Up @@ -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,
Expand All @@ -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}
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
apis-override-select2js-0.1
acdh-django-browsing
acdh-id-reconciler>=0.2,<1
acdh-tei-pyutils>=0.34,<1
Expand All @@ -16,3 +17,4 @@ psycopg2
pyocclient==0.6
PyYAML>=6.0.1,<7
rdflib
icecream

0 comments on commit f9fbecc

Please sign in to comment.