summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@peacefrogs.net>2013-10-28 19:31:45 +0100
committerÉtienne Loks <etienne.loks@peacefrogs.net>2013-10-28 19:31:45 +0100
commit5889915d68867862c2f37866e8f8bf949c01e06e (patch)
treee2d718346323d03543af43ec1b32e5d38621866e
parent6b5ac2a50430316d82cf1758c895757b50232917 (diff)
downloadIshtar-5889915d68867862c2f37866e8f8bf949c01e06e.tar.bz2
Ishtar-5889915d68867862c2f37866e8f8bf949c01e06e.zip
Templates: list all dependant documents
New template tags for displaying table of documents
-rw-r--r--archaeological_context_records/models.py12
-rw-r--r--archaeological_context_records/templates/ishtar/sheet_contextrecord.html26
-rw-r--r--archaeological_finds/models.py17
-rw-r--r--archaeological_operations/models.py29
-rw-r--r--archaeological_operations/templates/ishtar/sheet_operation.html31
-rw-r--r--ishtar_common/templates/ishtar/blocks/window_tables/documents.html21
-rw-r--r--ishtar_common/templatetags/window_tables.py12
7 files changed, 106 insertions, 42 deletions
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py
index 0a970b8ce..b33b86e8c 100644
--- a/archaeological_context_records/models.py
+++ b/archaeological_context_records/models.py
@@ -19,6 +19,7 @@
from django.conf import settings
from django.contrib.gis.db import models
+from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _, ugettext, pgettext
from ishtar_common.models import GeneralType, BaseHistorizedItem, \
@@ -157,6 +158,10 @@ class ContextRecord(BaseHistorizedItem, OwnPerms):
return settings.JOINT.join([unicode(item) for item in [self.parcel,
self.label] if item])
+ @property
+ def show_url(self):
+ return reverse('show-contextrecord', args=[self.pk, ''])
+
def full_label(self):
if not self.operation:
return unicode(self)
@@ -218,6 +223,10 @@ class ContextRecord(BaseHistorizedItem, OwnPerms):
def get_total_number(cls):
return cls.objects.filter(operation__start_date__isnull=False).count()
+ def find_docs_q(self):
+ from archaeological_finds.models import FindSource
+ return FindSource.objects.filter(find__base_finds__context_record=self)
+
class ContextRecordSource(Source):
class Meta:
verbose_name = _(u"Context record documentation")
@@ -225,3 +234,6 @@ class ContextRecordSource(Source):
context_record = models.ForeignKey(ContextRecord,
verbose_name=_(u"Context record"), related_name="source")
+ @property
+ def owner(self):
+ return self.context_record
diff --git a/archaeological_context_records/templates/ishtar/sheet_contextrecord.html b/archaeological_context_records/templates/ishtar/sheet_contextrecord.html
index 741201daa..4284b7eef 100644
--- a/archaeological_context_records/templates/ishtar/sheet_contextrecord.html
+++ b/archaeological_context_records/templates/ishtar/sheet_contextrecord.html
@@ -1,5 +1,5 @@
{% extends "ishtar/sheet.html" %}
-{% load i18n %}
+{% load i18n window_tables %}
{% block head_sheet %}
{{block.super}}
@@ -92,25 +92,8 @@
{% else %}<p class='alert'><label>{%trans "No operation linked to this context unit!"%}</label></p>
{% endif %}
-<table>
- <caption>{%trans "Documents"%}</caption>
- <tr>
- <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 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}}'>{% trans "Link"%}</a>{% endif %}</td>
- </tr>
- {% empty %}
- <tr><td colspan="4" class='no_items'>{% trans "No document associated to this context record" %}</td></tr>
- {% endfor %}
-</table>
+{% trans "Document from this context record" as cr_docs %}
+{% if item.source.count %} {% table_document cr_docs item.source.all %}{% endif %}
<table>
<caption>{%trans "Finds"%}</caption>
@@ -151,4 +134,7 @@
{% endfor %}
</table>
+{% trans "Documents from associated finds" as find_docs %}
+{% if item.find_docs_q.count %} {% table_document find_docs item.find_docs_q.all %}{% endif %}
+
{% endblock %}
diff --git a/archaeological_finds/models.py b/archaeological_finds/models.py
index f694ed562..53af78f8b 100644
--- a/archaeological_finds/models.py
+++ b/archaeological_finds/models.py
@@ -19,6 +19,7 @@
from django.conf import settings
from django.contrib.gis.db import models
+from django.core.urlresolvers import reverse
from django.db.models import Max
from django.utils.translation import ugettext_lazy as _, ugettext
@@ -197,6 +198,14 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms):
def __unicode__(self):
return self.label
+ @property
+ def short_label(self):
+ return self.reference
+
+ @property
+ def show_url(self):
+ return reverse('show-find', args=[self.pk, ''])
+
def get_first_base_find(self):
q= self.base_finds
if not q.count():
@@ -300,6 +309,10 @@ class FindSource(Source):
find = models.ForeignKey(Find, verbose_name=_(u"Find"),
related_name="source")
+ @property
+ def owner(self):
+ return self.find
+
class TreatmentType(GeneralType):
virtual = models.BooleanField(_(u"Virtual"))
class Meta:
@@ -346,6 +359,10 @@ class TreatmentSource(Source):
treatment = models.ForeignKey(Treatment, verbose_name=_(u"Treatment"),
related_name="source")
+ @property
+ def owner(self):
+ return self.treatment
+
class Property(LightHistorizedItem):
find = models.ForeignKey(Find, verbose_name=_(u"Find"))
administrative_act = models.ForeignKey(AdministrativeAct,
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index c805f9a3d..3d6eaa15a 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -22,6 +22,7 @@ from itertools import groupby
from django.conf import settings
from django.contrib.gis.db import models
+from django.core.urlresolvers import reverse
from django.db.models import Q, Count, Sum, Max, Avg
from django.db.models.signals import post_save, m2m_changed
from django.utils.translation import ugettext_lazy as _, ugettext
@@ -157,6 +158,16 @@ class Operation(BaseHistorizedItem, OwnPerms):
return _(u"OPE")
@property
+ def short_label(self):
+ if settings.COUNTRY == 'fr':
+ return self.code_patriarche
+ return unicode(self)
+
+ @property
+ def show_url(self):
+ return reverse('show-operation', args=[self.pk, ''])
+
+ @property
def reference(self):
if self.code_patriarche:
return unicode(self.code_patriarche)
@@ -187,7 +198,19 @@ class Operation(BaseHistorizedItem, OwnPerms):
def grouped_parcels(self):
return Parcel.grouped_parcels(list(self.parcels.all()))
- associated_file_short_label_lbl = _(u"Archaelogical file")
+ def context_record_docs_q(self):
+ from archaeological_context_records.models import ContextRecordSource
+ return ContextRecordSource.objects.filter(
+ context_record__operation=self)
+
+ def find_docs_q(self):
+ from archaeological_finds.models import FindSource
+ print FindSource.objects.filter(
+ find__base_finds__context_record__operation=self).query
+ return FindSource.objects.filter(
+ find__base_finds__context_record__operation=self)
+
+ associated_file_short_label_lbl = _(u"Archaeological file")
@property
def associated_file_short_label(self):
if not self.associated_file:
@@ -309,6 +332,10 @@ class OperationSource(Source):
TABLE_COLS = ['operation.year', 'operation.operation_code'] + \
Source.TABLE_COLS
+ @property
+ def owner(self):
+ return self.operation
+
class ActType(GeneralType):
TYPE = (('F', _(u'Archaelogical file')),
('O', _(u'Operation')),
diff --git a/archaeological_operations/templates/ishtar/sheet_operation.html b/archaeological_operations/templates/ishtar/sheet_operation.html
index 0672cf22f..2768fd96c 100644
--- a/archaeological_operations/templates/ishtar/sheet_operation.html
+++ b/archaeological_operations/templates/ishtar/sheet_operation.html
@@ -1,5 +1,5 @@
{% extends "ishtar/sheet.html" %}
-{% load i18n %}
+{% load i18n window_tables %}
{% block head_sheet %}
{{block.super}}
@@ -117,26 +117,8 @@
{% endfor %}
</table>
-<h3>{% trans "Scientific documentation"%}</h3>
-<table>
- <caption>{%trans "Documents"%}</caption>
- <tr>
- <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 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}}'>{% trans "Link"%}</a>{% endif %}</td>
- </tr>
- {% empty %}
- <tr><td colspan="4" class='no_items'>{% trans "No scientific document associated to this operation" %}</td></tr>
- {% endfor %}
-</table>
+{% trans "Document from this operation" as operation_docs %}
+{% if item.source.count %} {% table_document operation_docs item.source.all %}{% endif %}
<table>
<caption>{%trans "Context records"%}</caption>
@@ -161,6 +143,10 @@
<tr><td colspan="6" class='no_items'>{% trans "No context record associated to this operation" %}</td></tr>
{% endfor %}
</table>
+
+{% trans "Documents from associated context records" as cr_docs %}
+{% if item.context_record_docs_q.count %} {% table_document cr_docs item.context_record_docs_q.all %}{% endif %}
+
<div class='table'>
<table>
<caption>{%trans "Finds"%}</caption>
@@ -206,4 +192,7 @@
</table>
</div>
+{% trans "Documents from associated finds" as find_docs %}
+{% if item.find_docs_q.count %} {% table_document find_docs item.find_docs_q.all %}{% endif %}
+
{% endblock %}
diff --git a/ishtar_common/templates/ishtar/blocks/window_tables/documents.html b/ishtar_common/templates/ishtar/blocks/window_tables/documents.html
new file mode 100644
index 000000000..9405bc3e8
--- /dev/null
+++ b/ishtar_common/templates/ishtar/blocks/window_tables/documents.html
@@ -0,0 +1,21 @@
+{% load i18n %}
+<table>
+ <caption>{{caption}}</caption>
+ <tr>
+ <th>{% trans "Title" %}</th>
+ <th>{% trans "Type" %}</th>
+ <th>{% trans "Authors" %}</th>
+ <th>{% trans "Related to" %}</th>
+ <th>{% trans "Link" %}</th>
+ </tr>
+ {% for doc in data %}
+ <tr>
+ <td class='string'>{{ doc.title }}</td>
+ <td class='string'>{{doc.source_type}}</td>
+ <td class='string'>{{ doc.authors.all|join:", " }}</td>
+ <td class='string'><a href="#" onclick='load_window("{{doc.owner.show_url}}")'>{{doc.owner.short_label}}</a></td>
+ <td class='string'>{% if doc.associated_url %}<a href='{{doc.associated_url}}'>{% trans "Link"%}</a>{% endif %}</td>
+ </tr>
+ {% endfor %}
+</table>
+
diff --git a/ishtar_common/templatetags/window_tables.py b/ishtar_common/templatetags/window_tables.py
new file mode 100644
index 000000000..5c19eb6df
--- /dev/null
+++ b/ishtar_common/templatetags/window_tables.py
@@ -0,0 +1,12 @@
+
+from django import template
+from django.utils.translation import ugettext as _
+import re
+
+register = template.Library()
+
+@register.inclusion_tag('ishtar/blocks/window_tables/documents.html')
+def table_document(caption, data):
+ return {'caption':caption, 'data':data}
+
+