diff options
-rw-r--r-- | archaeological_context_records/templates/ishtar/sheet_contextrecord.html | 10 | ||||
-rw-r--r-- | archaeological_finds/templates/ishtar/sheet_find.html | 27 | ||||
-rw-r--r-- | archaeological_operations/templates/ishtar/sheet_operation.html | 14 | ||||
-rw-r--r-- | ishtar_common/models.py | 21 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/sheet_person.html | 18 | ||||
-rw-r--r-- | 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 @@ </div> {% 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 %} -<h3>{% trans "Documents"%}</h3> -<table id='{{window_id}}-docs' class="table table-striped"> - <caption>{%trans "Documents"%}</caption> - <tr> - <th> </th> - <th>{% trans "Title" %}</th> - <th>{% trans "Type" %}</th> - <th>{% trans "Authors" %}</th> - <th>{% trans "Link" %}</th> - </tr> - {% for doc in item.source.all %} - <tr> - <td><a class="display_details" href="#" - onclick="load_window('{% url 'show-findsource' doc.id %}/');"><i class="fa fa-info-circle" aria-hidden="true"></i> - </a></td> - <td class='string'>{{ doc.title }}</td> - <td class='string'>{{ doc.source_type }}</td> - <td class='string'>{{ doc.authors.all|join:", " }}</td> - <td class='string'>{% if doc.associated_url %}<a href='{{doc.associated_url}}' target="_blank">{{doc.associated_url}}</a>{% endif %}</td> - </tr> - {% empty %} - {% endfor %} -</table> +{% 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( |