From d7ee68b2bd2207faf4e419cce5fcfd0e9f11506c Mon Sep 17 00:00:00 2001 From: Greg Kempe Date: Fri, 21 Jul 2023 18:11:07 +0200 Subject: [PATCH] add document XML field, in case XML needs to be stored --- .../0092_documentcontent_content_xml.py | 18 ++++++++++++++++++ peachjam/models/core_document_model.py | 13 ++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 peachjam/migrations/0092_documentcontent_content_xml.py diff --git a/peachjam/migrations/0092_documentcontent_content_xml.py b/peachjam/migrations/0092_documentcontent_content_xml.py new file mode 100644 index 000000000..d929f0213 --- /dev/null +++ b/peachjam/migrations/0092_documentcontent_content_xml.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.16 on 2023-07-21 16:10 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("peachjam", "0091_peachjamsettings_mailchimp_form_url"), + ] + + operations = [ + migrations.AddField( + model_name="documentcontent", + name="content_xml", + field=models.TextField(blank=True, null=True, verbose_name="document XML"), + ), + ] diff --git a/peachjam/models/core_document_model.py b/peachjam/models/core_document_model.py index 0cba8f42e..e329c1e5a 100644 --- a/peachjam/models/core_document_model.py +++ b/peachjam/models/core_document_model.py @@ -5,7 +5,7 @@ import tempfile import magic -from cobalt.akn import datestring +from cobalt.akn import StructuredDocument, datestring from cobalt.uri import FrbrUri from countries_plus.models import Country from django.conf import settings @@ -813,11 +813,22 @@ class DocumentContent(models.Model): content_text = models.TextField( blank=True, null=True, verbose_name=_("document text") ) + # option XML content of the document + content_xml = models.TextField( + blank=True, null=True, verbose_name=_("document XML") + ) class Meta: verbose_name = _("document content") verbose_name_plural = _("document contents") + def akn_doc(self): + """Get a cobalt StructureDocument instance for this document's XML, assuming it is AKN XML.""" + if self.content_xml: + return StructuredDocument.for_document_type(self.document.frbr_uri_doctype)( + self.content_xml + ) + @classmethod def update_or_create_for_document(cls, document): """Extract the content from a document, whatever its format is."""