Skip to content

Commit

Permalink
Merge pull request #2098 from laws-africa/edit-with-ingestor
Browse files Browse the repository at this point in the history
Edit with ingestor
  • Loading branch information
longhotsummer authored Oct 14, 2024
2 parents fe113af + edb54ac commit 0868536
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 4 deletions.
4 changes: 4 additions & 0 deletions peachjam/adapters/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def handle_webhook(self, data):
"""Handle webhook from a remote server."""
pass

def get_edit_url(self, document):
"""Get an adapter-specific edit URL for this document."""
pass

@classmethod
def name(cls):
return cls.__name__
1 change: 1 addition & 0 deletions peachjam/adapters/gazettes.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def update_document(self, url):
"key": document["key"],
"created_at": document["created_at"],
"updated_at": document["updated_at"],
"ingestor": self.ingestor,
}
gazette, new = Gazette.objects.update_or_create(
expression_frbr_uri=document["expression_frbr_uri"],
Expand Down
5 changes: 5 additions & 0 deletions peachjam/adapters/indigo.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ def update_document(self, url):
"content_html": self.get_content_html(document),
"citation": document["numbered_title"],
"principal": document["principal"],
"ingestor": self.ingestor,
}

frbr_uri_data = {
Expand Down Expand Up @@ -652,3 +653,7 @@ def handle_webhook(self, data):
"expression_frbr_uri"
):
delete_document(self.ingestor.pk, data["data"]["expression_frbr_uri"])

def get_edit_url(self, document):
if self.settings.get("indigo_url"):
return f"{self.settings['indigo_url']}/works{document.work_frbr_uri}"
24 changes: 24 additions & 0 deletions peachjam/migrations/0166_coredocument_ingestor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.2.14 on 2024-10-10 13:31

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("peachjam", "0165_editactivity"),
]

operations = [
migrations.AddField(
model_name="coredocument",
name="ingestor",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to="peachjam.ingestor",
),
),
]
9 changes: 9 additions & 0 deletions peachjam/models/core_document_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,11 @@ class CoreDocument(PolymorphicModel):
frbr_uri_doctypes = FRBR_URI_DOCTYPES
labels = models.ManyToManyField(Label, verbose_name=_("labels"), blank=True)

# ingestor responsible for managing this document
ingestor = models.ForeignKey(
"peachjam.Ingestor", on_delete=models.SET_NULL, null=True, blank=True
)

class Meta:
ordering = ["doc_type", "title"]
permissions = [
Expand Down Expand Up @@ -768,6 +773,10 @@ def get_doc_type_display(self):
"""Human-friendly type of this document, which is always the nature, since that cannot be null."""
return self.nature.name

def ingestor_edit_url(self):
if self.ingestor:
return self.ingestor.get_edit_url(self)


def file_location(instance, filename):
if not instance.document.pk:
Expand Down
3 changes: 3 additions & 0 deletions peachjam/models/ingestors.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,6 @@ def queue_task(self):
run_ingestor(self.id, repeat=self.repeat, schedule=self.schedule)
else:
log.info(f"ingestor {self.name} disabled, ignoring")

def get_edit_url(self, document):
return self.get_adapter().get_edit_url(document)
21 changes: 19 additions & 2 deletions peachjam/templates/peachjam/_document_detail_toolbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,25 @@
aria-label="{% trans "Document toolbar" %}">
{% block edit-btn %}
{% if perms.peachjam.change_coredocument or perms.peachjam.can_edit_own_document %}
<a class="btn btn-outline-secondary btn-shrink-sm"
href="{{ document|admin_url:'change' }}">{% trans "Edit" %}</a>
{% if document.ingestor_edit_url %}
<div class="btn-group">
<a class="btn btn-outline-secondary btn-shrink-sm"
href="{{ document.ingestor_edit_url }}"
target="_blank">{% trans "Edit" %}</a>
<button type="button"
class="btn btn-outline-secondary btn-shrink-sm dropdown-toggle dropdown-toggle-split"
data-bs-toggle="dropdown">
</button>
<ul class="dropdown-menu">
<li>
<a class="dropdown-item" href="{{ document|admin_url:'change' }}">{% trans "Edit in admin area" %}</a>
</li>
</ul>
</div>
{% else %}
<a class="btn btn-outline-secondary btn-shrink-sm"
href="{{ document|admin_url:'change' }}">{% trans "Edit" %}</a>
{% endif %}
{% endif %}
{% endblock %}
{% block download-btn %}
Expand Down
3 changes: 2 additions & 1 deletion peachjam/templates/peachjam/saved_document_create.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
aria-expanded="false"
hx-post="{% url 'saved_document_create' %}?doc_id={{ form.document.value }}"
hx-target="#saveDocumentWrapper">
{% trans 'Save document' %}
<span class="d-sm-none">{% trans 'Save' %}</span>
<span class="d-none d-sm-inline">{% trans 'Save document' %}</span>
</button>
<div hx-swap-oob="true" id="saveDocumentModalDialog" class="modal-dialog">
<div class="modal-content">
Expand Down
3 changes: 2 additions & 1 deletion peachjam/templates/peachjam/saved_document_login.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
type="button"
aria-expanded="false"
data-bs-target="#saveDocumentModal">
{% trans 'Save document' %}
<span class="d-sm-none">{% trans 'Save' %}</span>
<span class="d-none d-sm-inline">{% trans 'Save document' %}</span>
</button>
<div hx-swap-oob="true" id="saveDocumentModalDialog" class="modal-dialog">
<div class="modal-content">
Expand Down

0 comments on commit 0868536

Please sign in to comment.