Skip to content

Commit

Permalink
Explicitly append new elements to the XML tree when updating
Browse files Browse the repository at this point in the history
This PR relies on nationalarchives/ds-caselaw-custom-api-client#35
being merged and a new release of the API client

If a metadata element does not exist in the XML document (as opposed to existing
but being empty) we were previously returning `None` from the API client and
the document was therefore uneditable. Now, we will return an empty element if
the element doesn't exist in the document. The element (new or existing) can
then be added to the element tree and re-saved back into the document.
  • Loading branch information
Laura Porter authored and Floppy committed Apr 22, 2022
1 parent f9baf96 commit 6b3656c
Showing 1 changed file with 18 additions and 0 deletions.
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

0 comments on commit 6b3656c

Please sign in to comment.