From 228275f656142f0df065d9036f03c84f62af9aa6 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 13 Jun 2018 14:10:25 +0200 Subject: Sheet: display documents tables --- .../templates/ishtar/sheet_contextrecord.html | 10 +++----- .../templates/ishtar/sheet_find.html | 27 +++------------------- .../templates/ishtar/sheet_operation.html | 14 ++++------- ishtar_common/models.py | 21 ++++++++++++++--- ishtar_common/templates/ishtar/sheet_person.html | 18 +++------------ ishtar_common/templatetags/window_tables.py | 3 +++ 6 files changed, 34 insertions(+), 59 deletions(-) diff --git a/archaeological_context_records/templates/ishtar/sheet_contextrecord.html b/archaeological_context_records/templates/ishtar/sheet_contextrecord.html index c2666d615..6137e6be8 100644 --- a/archaeological_context_records/templates/ishtar/sheet_contextrecord.html +++ b/archaeological_context_records/templates/ishtar/sheet_contextrecord.html @@ -158,23 +158,19 @@ {% endif %} -{% comment %} {% trans "Document from this context record" as cr_docs %} -{% if item.source.count %} -{% dynamic_table_document cr_docs 'context_records_docs' 'context_record' item.pk '' output %} +{% if item.documents.count %} +{% dynamic_table_document cr_docs 'documents' 'context_records' item.pk '' output %} {% endif %} -{% endcomment %} {% trans "Finds" as finds %} {% if item.base_finds.count %} {% dynamic_table_document finds 'finds_for_ope' 'base_finds__context_record' item.pk 'TABLE_COLS_FOR_OPE' output %} {% endif %} -{% comment %} {% trans "Documents from associated finds" as finds_docs %} {% if item.find_docs_q.count %} -{% dynamic_table_document finds_docs 'finds_docs' 'find__base_finds__context_record' item.pk '' output %} +{% dynamic_table_document finds_docs 'documents' 'finds__base_finds__context_record' item.pk '' output %} {% endif %} -{% endcomment %} {% endblock %} diff --git a/archaeological_finds/templates/ishtar/sheet_find.html b/archaeological_finds/templates/ishtar/sheet_find.html index f22c17137..aa1f9bb12 100644 --- a/archaeological_finds/templates/ishtar/sheet_find.html +++ b/archaeological_finds/templates/ishtar/sheet_find.html @@ -296,30 +296,9 @@ {% endif %} -{% if item.source.count %} -

{% trans "Documents"%}

- - - - - - - - - - {% for doc in item.source.all %} - - - - - - - - {% empty %} - {% endfor %} -
{%trans "Documents"%}
 {% trans "Title" %}{% trans "Type" %}{% trans "Authors" %}{% trans "Link" %}
- {{ doc.title }}{{ doc.source_type }}{{ doc.authors.all|join:", " }}{% if doc.associated_url %}{{doc.associated_url}}{% endif %}
+{% trans "Associated documents" as finds_docs %} +{% if item.documents.count %} +{% dynamic_table_document finds_docs 'documents' 'finds' item.pk '' output %} {% endif %} {% endblock %} diff --git a/archaeological_operations/templates/ishtar/sheet_operation.html b/archaeological_operations/templates/ishtar/sheet_operation.html index 7a6c36a11..231db2ae8 100644 --- a/archaeological_operations/templates/ishtar/sheet_operation.html +++ b/archaeological_operations/templates/ishtar/sheet_operation.html @@ -189,12 +189,10 @@ {% table_administrativact "" item.administrative_act.all %} {% endif %} -{% comment %} {% trans "Document from this operation" as operation_docs %} -{% if item.source.count %} -{% dynamic_table_document operation_docs 'operation_docs' 'operation' item.pk '' output %} +{% if item.documents.count %} +{% dynamic_table_document operation_docs 'documents' 'operations' item.pk '' output %} {% endif %} -{% endcomment %} {% if item.context_record.count %} {% trans "Context records" as cr_lab %} @@ -206,24 +204,20 @@ {% dynamic_table_document cr_rels 'context_records_relations_detail' 'left_record__operation' item.pk '' output %} {% endif %} -{% comment %} {% if item.context_record_docs_q.count %} {% trans "Documents from associated context records" as cr_docs %} -{% dynamic_table_document cr_docs 'context_records_docs' 'context_record__operation' item.pk '' output %} +{% dynamic_table_document cr_docs 'documents' 'context_records__operation' item.pk '' output %} {% endif %} -{% endcomment %} {% if item.finds %} {% trans "Finds" as finds %} {% dynamic_table_document finds 'finds_for_ope' 'base_finds__context_record__operation' item.pk 'TABLE_COLS_FOR_OPE' output %} {% endif %} -{% comment %} {% if item.find_docs_q.count %} {% trans "Documents from associated finds" as finds_docs %} -{% dynamic_table_document finds_docs 'finds_docs' 'find__base_finds__context_record__operation' item.pk '' output %} +{% dynamic_table_document finds_docs 'documents' 'finds__base_finds__context_record__operation' item.pk '' output %} {% endif %} -{% endcomment %} {% if item.containers_q.count %} {% trans "Associated containers" as containers_lbl %} diff --git a/ishtar_common/models.py b/ishtar_common/models.py index e1c4e825d..02c19e011 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -1214,7 +1214,8 @@ class DocumentItem(object): def images(self): if not hasattr(self, 'documents'): return Document.objects.none() - return self.documents.filter(image__isnull=False).exclude(image="") + return self.documents.filter( + image__isnull=False).exclude(image="").order_by("pk") def get_extra_actions(self, request): """ @@ -2735,6 +2736,9 @@ class Person(Address, Merge, OwnPerms, ValueGetter): if getattr(self, attr)] return slugify(u"-".join(values)) + def docs_q(self): + return Document.objects.filter(authors__person=self) + def operation_docs_q(self): return Document.objects.filter( authors__person=self, operations__pk__isnull=False) @@ -3105,6 +3109,17 @@ class Document(OwnPerms, ImageModel, FullSearch): BOOL_FIELDS = ['duplicate'] CACHED_LABELS = ['cache_related_label'] + EXTRA_REQUEST_KEYS = { + "operations": "operations__pk", + "context_records": "context_records__pk", + "context_records__operation": "context_records__operation__pk", + "finds": "finds__pk", + "finds__base_finds__context_record": + "finds__base_finds__context_record__pk", + "finds__base_finds__context_record__operation": + "finds__base_finds__context_record__operation__pk", + "authors__person": "authors__person__pk" + } title = models.TextField(_(u"Title"), blank=True, default='') associated_file = models.FileField( @@ -3183,8 +3198,8 @@ class Document(OwnPerms, ImageModel, FullSearch): @property def images(self): # mimic a queryset pointing to himself - return Document.objects.filter(pk=self.pk, - image__isnull=False).exclude(image='') + return Document.objects.filter( + pk=self.pk, image__isnull=False).exclude(image='') @property def has_related(self): diff --git a/ishtar_common/templates/ishtar/sheet_person.html b/ishtar_common/templates/ishtar/sheet_person.html index a37193572..f84b80d83 100644 --- a/ishtar_common/templates/ishtar/sheet_person.html +++ b/ishtar_common/templates/ishtar/sheet_person.html @@ -103,22 +103,10 @@ {% dynamic_table_document af 'files' 'responsible_town_planning_service' item.pk '' output %} {% endif %} -{% comment %} -{% if item.operation_docs_q.count %} -{% trans "Documents associated to operations" as operation_docs %} -{% dynamic_table_document operation_docs 'operation_docs' 'person' item.pk '' output %} +{% if item.docs_q.count %} +{% trans "Documents" as docs %} +{% dynamic_table_document docs 'documents' 'authors__person' item.pk '' output %} {% endif %} -{% if item.contextrecord_docs_q.count %} -{% trans "Documents associated to context records" as context_records %} -{% dynamic_table_document context_records 'context_records_docs' 'person' item.pk '' output %} -{% endif %} - -{% if item.find_docs_q.count %} -{% trans "Documents associated to finds" as finds_docs %} -{% dynamic_table_document finds_docs 'finds_docs' 'person' item.pk '' output %} -{% endif %} -{% endcomment %} - {% endblock %} diff --git a/ishtar_common/templatetags/window_tables.py b/ishtar_common/templatetags/window_tables.py index b442b4353..ce767e1ac 100644 --- a/ishtar_common/templatetags/window_tables.py +++ b/ishtar_common/templatetags/window_tables.py @@ -12,6 +12,7 @@ from django.utils.translation import ugettext_lazy as _ from ishtar_common.forms import reverse_lazy from ishtar_common.widgets import DataTable +from ishtar_common.models import Document from archaeological_files.models import File from archaeological_operations.models import Operation, ArchaeologicalSite from archaeological_context_records.models import ContextRecord, \ @@ -56,6 +57,8 @@ ASSOCIATED_MODELS['treatments'] = ( ASSOCIATED_MODELS['containers'] = ( Container, 'get-container', '') +ASSOCIATED_MODELS['documents'] = (Document, 'get-document', '') + @register.simple_tag(takes_context=True) def dynamic_table_document( -- cgit v1.2.3