diff --git a/app/apps/core/models.py b/app/apps/core/models.py index aad2b42151b11b7c417bfdcdafa843a1ab8731c5..680f26f313b5a88b18c3f5133f0737c4cf062fef 100644 --- a/app/apps/core/models.py +++ b/app/apps/core/models.py @@ -244,6 +244,13 @@ class Document(models.Model): else: return 'ltr' + @cached_property + def last_edited_part(self): + try: + return self.parts.order_by('-updated_at')[0] + except IndexError: + return None + @property def training_model(self): return self.ocr_models.filter(training=True).first() diff --git a/app/escriptorium/templates/core/document_list.html b/app/escriptorium/templates/core/document_list.html index 9def635d703d38aa19d5fc5c7288fc3a1aa0ee28..4b881cf8e630f07076da04d33cc8e680ecabc498 100644 --- a/app/escriptorium/templates/core/document_list.html +++ b/app/escriptorium/templates/core/document_list.html @@ -49,11 +49,18 @@ <td class="text-right"> {# <a href="{% url 'document-detail' pk=document.pk %}" class="btn btn-info disabled" title="{% trans 'View' %}"><i class="fas fa-eye"></i></a> #} {# Note that doing one query per row is a lot faster than a subquery for some reason #} - <a href="{% url 'document-part-edit' pk=document.pk part_pk=document.parts.last.pk %}" + {% if document.last_edited_part %} + <a href="{% url 'document-part-edit' pk=document.pk part_pk=document.last_edited_part.pk %}" class="btn btn-info" title="{% trans 'Edit last updated Element' %}"> - <i class="fas fa-edit"></i> + <i class="fas fa-edit"></i> </a> + {% endif %} + + <form method="post" class="inline-form" action="{% url 'document-publish' pk=document.pk %}" onsubmit="return confirm('{% trans "Do you really want to delete the document?" %}');">{% csrf_token %} + <input type="hidden" name="workflow_state" value="{{ document.WORKFLOW_STATE_ARCHIVED }}"> + <button type="submit" value="" class="nav-item btn btn-danger" title="{% trans 'Delete' %}"><i class="fas fa-trash"></i></button> + </form> </td> </tr> {% endfor %}