Skip to content

Commit

Permalink
Merge pull request #1389 from laws-africa/xml
Browse files Browse the repository at this point in the history
add document XML field, in case XML needs to be stored
  • Loading branch information
longhotsummer authored Jul 21, 2023
2 parents 19b99a2 + d7ee68b commit 82ffc07
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
18 changes: 18 additions & 0 deletions peachjam/migrations/0092_documentcontent_content_xml.py
Original file line number Diff line number Diff line change
@@ -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"),
),
]
13 changes: 12 additions & 1 deletion peachjam/models/core_document_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand Down

0 comments on commit 82ffc07

Please sign in to comment.