Skip to content

Commit

Permalink
Merge pull request #98 from nationalarchives/fix/allow-editing-when-m…
Browse files Browse the repository at this point in the history
…etadata-is-missing

Explicitly append new elements to the XML tree when updating
  • Loading branch information
Floppy authored Apr 22, 2022
2 parents 2d6e542 + b74ecca commit 7794e44
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions judgments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
from judgments.models import SearchResult, SearchResults

env = environ.Env()
akn_namespace = {"akn": "http://docs.oasis-open.org/legaldocml/ns/akn/3.0"}
uk_namespace = {"uk": "https://caselaw.nationalarchives.gov.uk/akn"}


def detail(request):
Expand Down Expand Up @@ -99,18 +101,34 @@ def update(request):
name = xml_tools.get_metadata_name_element(xml)
new_name = request.POST["metadata_name"]
name.set("value", new_name)
frbrwork_parent = xml.find(
".//akn:FRBRWork",
namespaces=akn_namespace,
)
if frbrwork_parent:
frbrwork_parent.append(name)
# Set neutral citation
citation = xml_tools.get_neutral_citation_element(xml)
new_citation = request.POST["neutral_citation"]
citation.text = new_citation
uk_parent = xml.find(
".//uk:proprietary",
namespaces=uk_namespace,
)
if uk_parent:
uk_parent.append(name)
# Set court
court = xml_tools.get_court_element(xml)
new_court = request.POST["court"]
court.text = new_court
if uk_parent:
uk_parent.append(name)
# Date
date = xml_tools.get_judgment_date_element(xml)
new_date = request.POST["judgment_date"]
date.set("date", new_date)
if frbrwork_parent:
frbrwork_parent.append(date)
# Save
api_client.save_judgment_xml(judgment_uri, xml)
context["published"] = published
Expand Down
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ requests-toolbelt~=0.9.1
lxml~=4.8.0
django-xml~=3.0.0
wsgi-basic-auth~=1.1.0
ds-caselaw-marklogic-api-client~=4.3
ds-caselaw-marklogic-api-client~=4.4
rollbar
django-stronghold==0.4.0
boto3==1.21.45
Expand Down

0 comments on commit 7794e44

Please sign in to comment.