Skip to content

Commit

Permalink
include attachment counters for WorkComponentRewriter
Browse files Browse the repository at this point in the history
  • Loading branch information
goose-life committed Feb 6, 2025
1 parent b9e1e16 commit c38408b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions indigo/xmlutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,4 @@ def rewrite_all_attachment_work_components(xml_doc):
'a:FRBRExpression': lambda: frbr_uri.expression_uri(),
'a:FRBRManifestation': lambda: frbr_uri.manifestation_uri(),
}[part]()
return counter
12 changes: 7 additions & 5 deletions indigo_app/static/javascript/indigo/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,19 @@
// in provision mode, retain the eId of the parent element as the prefix
// and use the counters of all preceding provisions for context
let eidPrefix,
rewriter = new indigoAkn.EidRewriter();
eidRewriter = new indigoAkn.EidRewriter(),
workComponentRewriter = new indigoAkn.WorkComponentRewriter();
if (Indigo.Preloads.provisionEid && Indigo.Preloads.provisionEid.lastIndexOf('__') > -1) {
eidPrefix = Indigo.Preloads.provisionEid.substring(0, Indigo.Preloads.provisionEid.lastIndexOf('__'));
}
if (Indigo.Preloads.provisionEid) {
rewriter.counters = Indigo.Preloads.provisionCounters;
rewriter.eidCounter = Indigo.Preloads.eidCounter;
eidRewriter.counters = Indigo.Preloads.provisionCounters;
eidRewriter.eidCounter = Indigo.Preloads.eidCounter;
workComponentRewriter.counters = Indigo.Preloads.attachmentCounters;
}
rewriter.rewriteEid(this.xmlDocument.documentElement, eidPrefix);
eidRewriter.rewriteEid(this.xmlDocument.documentElement, eidPrefix);
// rewrite all attachment FRBR URI work components too
new indigoAkn.WorkComponentRewriter().rewriteAllAttachmentWorkComponents(this.xmlDocument.documentElement);
workComponentRewriter.rewriteAttachmentWorkComponent(this.xmlDocument.documentElement);
},

// serialise an XML node, or the entire document if node is not given, to a string
Expand Down
1 change: 1 addition & 0 deletions indigo_app/templates/indigo_api/document/show.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ <h5 class="main-header-title">
window.Indigo.Preloads.provisionEid = "{{ provision_eid }}";
window.Indigo.Preloads.provisionCounters = {% if provision_counters %}{{ provision_counters|safe }}{% else %}null{% endif %};
window.Indigo.Preloads.eidCounter = {% if eid_counter %}{{ eid_counter|safe }}{% else %}null{% endif %};
window.Indigo.Preloads.attachmentCounters = {% if attachment_counters %}{{ attachment_counters|safe }}{% else %}null{% endif %};
window.Indigo.Preloads.amendments = {{ amendments_json|safe }};
window.Indigo.Preloads.expressions = {{ expressions_json|safe }};
{% if pyodide_packages_json %}
Expand Down
7 changes: 5 additions & 2 deletions indigo_app/views/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import cobalt
from bluebell.xml import XmlGenerator
from indigo.plugins import plugins
from indigo.xmlutils import rewrite_all_attachment_work_components
from indigo_api.models import Document, Country, Subtype, Work
from indigo_api.serializers import DocumentSerializer, WorkSerializer, WorkAmendmentSerializer
from indigo_api.views.documents import DocumentViewSet
Expand Down Expand Up @@ -138,7 +139,7 @@ def get(self, request, *args, **kwargs):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['provision_eid'] = self.eid
context['provision_counters'], context['eid_counter'] = self.get_counters()
context['provision_counters'], context['eid_counter'], context['attachment_counters'] = self.get_counters()
return context

def get_document_content_json(self, document):
Expand Down Expand Up @@ -166,7 +167,9 @@ def get_counters(self):

generator = XmlGenerator(self.object.frbr_uri)
generator.generate_eids(root)
return json.dumps(generator.ids.counters), json.dumps(generator.ids.eid_counter)
doc = cobalt.StructuredDocument.for_document_type(self.object.work.work_uri.doctype)(etree.tostring(root, encoding='unicode'))
attachment_counters = {'__attachments': rewrite_all_attachment_work_components(doc)}
return json.dumps(generator.ids.counters), json.dumps(generator.ids.eid_counter), json.dumps(attachment_counters)


class DocumentPopupView(AbstractAuthedIndigoView, DetailView):
Expand Down

0 comments on commit c38408b

Please sign in to comment.