summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2016-09-05 17:05:03 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2016-09-05 17:05:03 +0200
commit10c8a694f2ffcfc001f5deddcb7d633d9f00b7cc (patch)
tree0fa618c50ef4dff1e59924f46d78548e9b714cb4
parent466195bd302ffcabdbcbbef882a269093584d865 (diff)
downloadIshtar-10c8a694f2ffcfc001f5deddcb7d633d9f00b7cc.tar.bz2
Ishtar-10c8a694f2ffcfc001f5deddcb7d633d9f00b7cc.zip
Operation: display statistics on the sheet (refs #2989)
-rw-r--r--archaeological_files/models.py1
-rw-r--r--archaeological_operations/models.py198
-rw-r--r--archaeological_operations/templates/ishtar/sheet_operation.html230
-rw-r--r--ishtar_common/models.py1
-rw-r--r--ishtar_common/static/media/style.css4
-rw-r--r--ishtar_common/templatetags/link_to_window.py2
-rw-r--r--ishtar_common/utils.py5
-rw-r--r--version.py2
8 files changed, 348 insertions, 95 deletions
diff --git a/archaeological_files/models.py b/archaeological_files/models.py
index 98223d7ff..eaa9d832e 100644
--- a/archaeological_files/models.py
+++ b/archaeological_files/models.py
@@ -73,6 +73,7 @@ class File(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,
ShortMenuItem, DashboardFormItem):
TABLE_COLS = ['numeric_reference', 'year', 'internal_reference',
'file_type', 'saisine_type', 'towns', ]
+ SHOW_URL = 'show-file'
year = models.IntegerField(_(u"Year"),
default=lambda: datetime.datetime.now().year)
numeric_reference = models.IntegerField(
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index 2db101104..ccafe5202 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -22,17 +22,18 @@ from itertools import groupby
from django.conf import settings
from django.contrib.gis.db import models
+from django.core.cache import cache
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, post_delete
from django.forms import ValidationError
from django.utils.translation import ugettext_lazy as _, ugettext
-from ishtar_common.utils import cached_label_changed
+from ishtar_common.utils import cached_label_changed, get_cache, mode
from ishtar_common.models import GeneralType, BaseHistorizedItem, \
HistoricalRecords, LightHistorizedItem, OwnPerms, Department, Source,\
- Person, Organization, Town, Dashboard, IshtarUser, ValueGetter, \
+ SourceType, Person, Organization, Town, Dashboard, IshtarUser, ValueGetter,\
DocumentTemplate, ShortMenuItem, DashboardFormItem, GeneralRelationType,\
GeneralRecordRelations, post_delete_record_relation, OperationType, \
get_external_id
@@ -459,6 +460,199 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,
self.operation_code = self.get_available_operation_code(self.year)
return super(Operation, self).save(*args, **kwargs)
+ @property
+ def nb_parcels(self):
+ nb = 0
+ if self.associated_file:
+ nb = self.associated_file.parcels.count()
+ if not nb:
+ nb = self.parcels.count()
+ return nb
+
+ def _get_or_set_stats(self, funcname, update):
+ key, val = get_cache(self.__class__, [funcname, self.pk])
+ if not update and val is not None:
+ return val
+ val = getattr(self, funcname)()
+ cache.set(key, val, settings.CACHE_TIMEOUT)
+ return val
+
+ @property
+ def nb_acts(self, update=False):
+ _(u"Number of administrative acts")
+ return self._get_or_set_stats('_nb_acts', update)
+
+ def _nb_acts(self):
+ return self.administrative_act.count()
+
+ @property
+ def nb_indexed_acts(self, update=False):
+ _(u"Number of indexed administrative acts")
+ return self._get_or_set_stats('_nb_indexed_acts', update)
+
+ def _nb_indexed_acts(self):
+ return self.administrative_act.filter(act_type__indexed=True).count()
+
+ @property
+ def nb_context_records(self, update=False):
+ _(u"Number of context records")
+ return self._get_or_set_stats('_nb_context_records', update)
+
+ def _nb_context_records(self):
+ return self.context_record.count()
+
+ @property
+ def nb_context_records_by_type(self, update=False):
+ return self._get_or_set_stats('_nb_context_records_by_type', update)
+
+ def _nb_context_records_by_type(self):
+ nbs = []
+ q = self.context_record.values(
+ 'unit', 'unit__label').distinct().order_by('label')
+ for res in q.all():
+ nbs.append((unicode(res['unit__label']),
+ self.context_record.filter(unit=res['unit']).count()))
+ return nbs
+
+ @property
+ def nb_context_records_by_periods(self, update=False):
+ return self._get_or_set_stats('_nb_context_records_by_periods', update)
+
+ def _nb_context_records_by_periods(self):
+ nbs = []
+ q = self.context_record.values(
+ 'datings__period', 'datings__period__label').distinct().order_by(
+ 'datings__period__order')
+ for res in q.all():
+ nbs.append((unicode(res['datings__period__label']),
+ self.context_record.filter(
+ datings__period=res['datings__period']).count()))
+ return nbs
+
+ @property
+ def nb_finds(self, update=False):
+ _(u"Number of finds")
+ return self._get_or_set_stats('_nb_finds', update)
+
+ def _nb_finds(self):
+ from archaeological_finds.models import Find
+ q = Find.objects.filter(
+ base_finds__context_record__operation=self)
+ return q.count()
+
+ @property
+ def nb_finds_by_material_type(self, update=False):
+ return self._get_or_set_stats('_nb_finds_by_material_type', update)
+
+ def _nb_finds_by_material_type(self):
+ from archaeological_finds.models import Find
+ nbs = []
+ q = Find.objects.filter(
+ base_finds__context_record__operation=self).values(
+ 'material_types__pk', 'material_types__label').distinct().order_by(
+ 'material_types__label')
+ for res in q.all():
+ nbs.append(
+ (unicode(res['material_types__label']),
+ Find.objects.filter(
+ material_types__pk=res['material_types__pk']).count()))
+ return nbs
+
+ @property
+ def nb_finds_by_types(self, update=False):
+ return self._get_or_set_stats('_nb_finds_by_types', update)
+
+ def _nb_finds_by_types(self):
+ from archaeological_finds.models import Find
+ nbs = []
+ q = Find.objects.filter(
+ base_finds__context_record__operation=self).values(
+ 'object_types', 'object_types__label').distinct().order_by(
+ 'object_types__label')
+ for res in q.all():
+ label = unicode(res['object_types__label'])
+ if label == 'None':
+ label = _(u"No type")
+ nbs.append(
+ (label,
+ Find.objects.filter(
+ object_types=res['object_types']).count()))
+ return nbs
+
+ @property
+ def nb_finds_by_periods(self, update=False):
+ return self._get_or_set_stats('_nb_finds_by_periods', update)
+
+ def _nb_finds_by_periods(self):
+ from archaeological_finds.models import Find
+ nbs = []
+ q = Find.objects.filter(
+ base_finds__context_record__operation=self).values(
+ 'datings__period', 'datings__period__label').distinct().order_by(
+ 'datings__period__order')
+ for res in q.all():
+ nbs.append(
+ (unicode(res['datings__period__label']),
+ Find.objects.filter(
+ datings__period=res['datings__period']).count()))
+ return nbs
+
+ @property
+ def nb_documents(self, update=False):
+ _(u"Number of sources")
+ return self._get_or_set_stats('_nb_documents', update)
+
+ def _nb_documents(self):
+ from archaeological_context_records.models import ContextRecordSource
+ from archaeological_finds.models import FindSource
+ nbs = self.source.count() + \
+ ContextRecordSource.objects.filter(
+ context_record__operation=self).count() + \
+ FindSource.objects.filter(
+ find__base_finds__context_record__operation=self).count()
+ return nbs
+
+ @property
+ def nb_documents_by_types(self, update=False):
+ return self._get_or_set_stats('_nb_documents_by_types', update)
+
+ def _nb_documents_by_types(self):
+ from archaeological_context_records.models import ContextRecordSource
+ from archaeological_finds.models import FindSource
+ docs = {}
+
+ qs = [
+ self.source,
+ ContextRecordSource.objects.filter(context_record__operation=self),
+ FindSource.objects.filter(
+ find__base_finds__context_record__operation=self)]
+ for q in qs:
+ for res in q.values('source_type').distinct():
+ st = res['source_type']
+ if st not in docs:
+ docs[st] = 0
+ docs[st] += q.filter(source_type=st).count()
+ docs = [(unicode(SourceType.objects.get(pk=k)), docs[k]) for k in docs]
+ return sorted(docs, key=lambda x: x[0])
+
+ @property
+ def nb_stats_finds_by_ue(self, update=False):
+ return self._get_or_set_stats('_nb_stats_finds_by_ue', update)
+
+ def _nb_stats_finds_by_ue(self):
+ _(u"Mean")
+ res, finds = {}, []
+ for cr in self.context_record.all():
+ finds.append(cr.base_finds.count())
+ if not finds:
+ return res
+ res['mean'] = float(sum(finds)) / max(len(finds), 1)
+ res['min'] = min(finds)
+ res['max'] = max(finds)
+ res['mode'] = u" ; ".join([str(m) for m in mode(finds)])
+ return res
+
+
m2m_changed.connect(cached_label_changed, sender=Operation.towns.through)
diff --git a/archaeological_operations/templates/ishtar/sheet_operation.html b/archaeological_operations/templates/ishtar/sheet_operation.html
index f0846f11f..f8421c830 100644
--- a/archaeological_operations/templates/ishtar/sheet_operation.html
+++ b/archaeological_operations/templates/ishtar/sheet_operation.html
@@ -6,110 +6,69 @@
{% block content %}
{% window_nav item window_id 'show-operation' 'operation_modify' 'show-historized-operation' 'revert-operation' previous next %}
-{% if previous or next %}
-<div class='tool'>
-{%if previous%}
-<a href="#" onclick='load_window("{% url show-historized-operation item.pk previous|date:"c"%}");$("#{{window_id}}").hide();return false;'>{%trans "Previous version"%} ({{previous}})</a>
-{% endif %}
-{% if previous and next %} - {% endif %}
-{%if next%}
-<a href="#" onclick='if(confirm("{%trans "Are you sure to rollback to this version?"%}")){load_url("{% url revert-operation item.pk item.history_date|date:"c"%}");closeAllWindows();load_window("{% url show-operation item.pk None %}");}'>Rollback</a> -
-<a href="#" onclick='load_window("{% url show-historized-operation item.pk next|date:"c" %}");$("#{{window_id}}").hide();return false;'>{%trans "Next version"%} ({{next}})</a>
-{% endif %}
-</div>
-{% endif %}
-
-<div class='tool'>{%trans "Export as:"%} <a href='{% url show-operation item.pk "odt" %}'>{%trans "OpenOffice.org file"%}</a>, <a href='{% url show-operation item.pk "pdf" %}'>{%trans "PDF file"%}</a></div>
-
-<div class='tool modify'><a href='{% url operation_modify item.pk %}'>{% trans "Modify" %}</a></div>
-
{% if item.virtual_operation %}
<p class='alert'><i class="fa fa-exclamation-triangle" aria-hidden="true"></i> {% trans "This operation is virtual." %}</p>
{% endif %}
-
-<h3>{% trans "General"%}</h3>
-{% if item.common_name %}<p><label>{%trans "Name:"%}</label> <span class='value'>{{ item.common_name }}</span></p>{% endif %}
-{% if item.year %}<p><label>{%trans "Year:"%}</label> <span class='value strong'>{{ item.year }}</span></p>{% endif %}
-{% if item.operation_code %}<p><label>{%trans "Numerical reference:"%}</label> <span class='value strong'>{{ item.operation_code }}</span></p>{% endif %}
-
-{% if item.code_patriarche %}<p><label>{%trans "Patriarche OA code:"%}</label> <span class='value'>OA{{ item.code_patriarche }}</span></p>{%else%}
-<p class='alert'><i class="fa fa-exclamation-triangle" aria-hidden="true"></i> {%trans "Patriarche OA code not yet recorded!"%}</p>{%endif%}
-{% field "Old code" item.old_code %}
-
-<p><label>{%trans "Last modification date:"%}</label> <span class='value'>{% if item.history_date %}{{ item.history_date }}{% else %}{{ item.history.all.0.history_date }}{% endif %}</span></p> <!-- date = now -->
-<p><label>{%trans "Created by:"%}</label> <span class='value'>{{ item.history_creator.ishtaruser.full_label }}</span></p>
-
-{% if item.start_date %}<p><label>{%trans "Begining date:"%}</label> <span class='value'>{{ item.start_date }}</span></p>
-<p><label>{%trans "Excavation end date:"%}</label> <span class='value'>{{ item.excavation_end_date|default:"-" }}</span></p>
-{%endif%}
-{% if item.scientist %}<p><label>{%trans "Head scientist:"%}</label> <span class='value'>{{ item.scientist.full_label }} <a href='#' onclick='load_window("{% url show-person item.scientist.pk ''%}");'><i class="fa fa-info-circle" aria-hidden="true"></i></a></span></p>{%endif%}
-{% if item.in_charge %}<p><label>{%trans "In charge:"%}</label> <span class='value'>{{ item.in_charge.full_label }}</span></p>{%endif%}
-{% if item.operator %}<p><label>{%trans "Operator:"%}</label> <span class='value'>{{ item.operator }} <a href='#' onclick='load_window("{% url show-organization item.operator.pk ''%}");'><i class="fa fa-info-circle" aria-hidden="true"></i></a></span></p>{% endif %}
-<p><label>{%trans "State:"%}</label> <span class='value'>{% if item.is_active %}{%trans "Active file"%}</span></p>
-{% else %}{%trans "Closed operation"%}</span></p>
-{% if item.closing.date %}<p><label>{%trans "Closing date:"%}</label> <span class='value'>{{ item.closing.date }} <strong>{%trans "by" %}</strong> {{ item.closing.user }}</span></p>{% endif %}
-{% endif %}
-{% field "Report delivery date" item.report_delivery_date %}
-{% field "Report processing" item.report_processing %}
-<p><label>{%trans "Type:"%}</label> <span class='value'>{{ item.operation_type }}</span></p>
-{% if item.surface %}<p><label>{%trans "Surface:"%}</label> <span class='value'>{{ item.surface }} m<sup>2</sup> ({{ item.surface_ha }} ha)</span></p>{% endif %}
-{% if item.cost %}<p><label>{%trans "Cost:"%}</label> <span class='value'>{{ item.cost }} &euro;{% if item.cost_by_m2 %}, ({{ item.cost_by_m2 }} &euro;/m<sup>2</sup>){%endif%}</span></p>{%endif%}
-{% if item.duration %}<p><label>{%trans "Duration:"%}</label> <span class='value'>{{ item.duration }} {%trans "Day"%}s</span></p>{%endif%}
-
-{% field_multiple "Remains" item.remains %}
-{% field_multiple "Periods" item.periods %}
-
-{% if item.QUALITY_DICT %}
-{% field "Record quality" item.record_quality|from_dict:item.QUALITY_DICT %}
+{% if not item.code_patriarche %}
+<p class='alert'><i class="fa fa-exclamation-triangle" aria-hidden="true"></i> {%trans "Patriarche OA code not yet recorded!"%}</p>
{% endif %}
-{% if item.history_object and item.history_object.QUALITY_DICT %}
-{% field "Record quality" item.record_quality|from_dict:item.history_object.QUALITY_DICT %}
-{% endif %}
-
-{% field "Abstract" item.abstract %}
-{% if item.associated_file %}
-<p><label>{%trans "Associated file:"%}</label> <span class='value'><a href='#' onclick='load_window("{% url show-file item.associated_file.pk ''%}")'>{{ item.associated_file }}</a></span></p><!-- Displayed as Year/index/Commune/Common_name This should be a link to the file sheet of the related file -->
-{% if item.associated_file.is_preventive %}
-{#{% if item.operator_reference_code %}<p><label>{%trans "Operator's reference code:"%}</label> <span class='value'>{{ item.operator_reference_code }}</span></p>{% endif %}#}
-
-{% field "Responsible for town planning service" item.associated_file.responsible_town_planning_service.full_address %}
+<h3>{% trans "General"%}</h3>
+<ul class='form-flex'>
+{% field_li "Name" item.common_name %}
+{% field_li "Year" item.year %}
+{% field_li "Numerical reference" item.operation_code %}
+{% field_li "Code patriarche" item.code_patriarche 'OA' %}
+{% field_li "Old code" item.old_code %}
+<li><label>{%trans "Last modification date:"%}</label> <span class='value'>{% if item.history_date %}{{ item.history_date }}{% else %}{{ item.history.all.0.history_date }}{% endif %}</span></li> <!-- date = now -->
+{% field_li "Created by" item.history_creator.ishtaruser.full_label %}
+{% field_li "Begining date" item.start_date %}
+{% field_li "Excavation end date" item.excavation_end_date|default:"-" %}
+{% field_li_detail "Head scientist" item.scientist %}
+{% field_li_detail "In charge" item.in_charge %}
+{% field_li_detail "Operator" item.operator %}
+<li><label>{%trans "State:"%}</label> <span class='value'>{% if item.is_active %}{%trans "Active file"%}</span></p>
+{% else %}{%trans "Closed operation"%}</span></li> {% endif %}
+{% if item.closing.date %}<li><label>{%trans "Closing date:"%}</label> <span class='value'>{{ item.closing.date }} <strong>{%trans "by" %}</strong> {{ item.closing.user }}</span></li>{% endif %}
+{% field_li "Report delivery date" item.report_delivery_date %}
+{% field_li "Report processing" item.report_processing %}
+{% field_li "Type" item.operation_type %}
+{% if item.surface %}<li><label>{%trans "Surface:"%}</label> <span class='value'>{{ item.surface }} m<sup>2</sup> ({{ item.surface_ha }} ha)</span></li>{% endif %}
+{% if item.cost %}<li><label>{%trans "Cost:"%}</label> <span class='value'>{{ item.cost }} &euro;{% if item.cost_by_m2 %}, ({{ item.cost_by_m2 }} &euro;/m<sup>2</sup>){%endif%}</span></li>{%endif%}
+{% if item.duration %}<li><label>{%trans "Duration:"%}</label> <span class='value'>{{ item.duration }} {%trans "Day"%}s</span></li>{%endif%}
+{% field_li_multiple "Remains" item.remains %}
+{% field_li_multiple "Periods" item.periods %}
+{% if item.QUALITY_DICT %}{% field_li "Record quality" item.record_quality|from_dict:item.QUALITY_DICT %}{% endif %}
+{% if item.history_object and item.history_object.QUALITY_DICT %}{% field_li "Record quality" item.record_quality|from_dict:item.history_object.QUALITY_DICT %}{% endif %}
+{% field_li "Abstract" item.abstract %}
+{% field_li_detail "Associated file" item.associated_file %}
+{% field_li "Responsible for town planning service" item.associated_file.responsible_town_planning_service.full_address %}
{% if item.associated_file.town_planning_service %}
- {% field "Town planning service organization" item.associated_file.town_planning_service.full_address %}
+ {% field_li "Town planning service organization" item.associated_file.town_planning_service.full_address %}
{% else %}
- {% field "Town planning service organization" item.associated_file.responsible_town_planning_service.attached_to.full_address %}
+ {% field_li "Town planning service organization" item.associated_file.responsible_town_planning_service.attached_to.full_address %}
{% endif %}
-
-{% if item.associated_file.permit_type %}<p><label>{%trans "Permit type:"%}</label> <span class='value'>{{ item.associated_file.permit_type }}</span></p>{% endif %}
-{% if item.associated_file.permit_reference %}<p><label>{%trans "Permit reference:"%}</label> <span class='value'>{{ item.associated_file.permit_reference }}</span></p>{% endif %}
-
-{% field "General contractor" item.associated_file.general_contractor.full_address %}
+{% field_li "Permit type" item.associated_file.permit_type %}
+{% field_li "Permit reference" item.associated_file.permit_reference %}
+{% field_li "General contractor" item.associated_file.general_contractor.full_address %}
{% if item.associated_file.corporation_general_contractor %}
- {% field "General contractor organization" item.associated_file.corporation_general_contractor.full_address %}
+ {% field_li "General contractor organization" item.associated_file.corporation_general_contractor.full_address %}
{% else%}
- {% field "General contractor organization" item.associated_file.general_contractor.attached_to.full_address %}
-{% endif %}
-
-{% endif %}
+ {% field_li "General contractor organization" item.associated_file.general_contractor.attached_to.full_address %}
{% endif %}
-
-{% field "Comment" item.comment "<pre>" "</pre>" %}
+{% field_li "Comment" item.comment "<pre>" "</pre>" %}
+</ul>
{% if item.towns.count %}
<h3>{% trans "Localisation"%}</h3>
-<p><label>{%trans "Towns:"%}</label> <span class='value'>{{ item.towns.all|join:", " }}</span></p>
+<ul class='form-flex'>
+{% field_li_multiple "Towns" item.towns %}
+{% field_li "Main address" item.associated_file.address %}
+{% field_li "Complement" item.associated_file.address_complement %}
+{% field_li "Postal code" item.associated_file.postal_code %}
+</ul>
{% endif %}
-{% if item.associated_file.address %}<p><label>{%trans "Main address:"%}</label> <span class='value'>{{ item.associated_file.address }}</span></p>
-{% if item.associated_file.address_complement %}<p><label>{%trans "Complement:"%}</label> <span class='value'>{{ item.associated_file.address_complement }}</span></p>{%endif%}
-{% if item.associated_file.postal_code %}<p><label>{%trans "Postal code:"%}</label> <span class='value'>{{ item.associated_file.postal_code }}</span></p>{%endif%}
-{%endif%}
-{% comment %}
-<p><label>{%trans "Lambert X:"%}</label> <span class='value'>{{ item.lambert_x }}</span></p>
-<p><label>{%trans "Lambert Y:"%}</label> <span class='value'>{{ item.lambert_y }}</span></p>
-<p><label>{%trans "Altitude (m NGF):"%}</label> <span class='value'>{{ item.altitude }}</span></p>
-{% endcomment %}
-
{% if item.right_relations.count %}
<h3>{% trans "Relations"%}</h3>
{% for rel in item.right_relations.all %}
@@ -130,8 +89,8 @@
{% include "ishtar/blocks/window_tables/parcels.html" %}
{% if item.administrative_act %}
-{% trans "Administrative acts" as administrativeacts_label %}
-{% table_administrativact administrativeacts_label item.administrative_act.all %}
+<h3>{% trans "Administrative acts" %}</h3>
+{% table_administrativact "" item.administrative_act.all %}
{% endif %}
{% trans "Document from this operation" as operation_docs %}
@@ -139,9 +98,9 @@
{% dynamic_table_document operation_docs 'operation_docs' 'operation' item.pk '' output %}
{% endif %}
-{% trans "Context records" as context_records %}
{% if item.context_record.count %}
-{% dynamic_table_document context_records 'context_records_for_ope' 'operation' item.pk 'TABLE_COLS_FOR_OPE' output %}
+<h3>{% trans "Context records" %}</h3>
+{% dynamic_table_document '' 'context_records_for_ope' 'operation' item.pk 'TABLE_COLS_FOR_OPE' output %}
{% endif %}
{% trans "Documents from associated context records" as cr_docs %}
@@ -159,4 +118,91 @@
{% dynamic_table_document finds_docs 'finds_docs' 'find__base_finds__context_record__operation' item.pk '' output %}
{% endif %}
+<h3>{% trans "Statistics" %}</h3>
+
+<h4>{% trans "Administrative acts" %}</h4>
+<ul class='form-flex'>
+{% field_li "Number of administrative acts" item.nb_acts %}
+{% field_li "Number of indexed administrative acts" item.nb_indexed_acts %}
+</ul>
+
+<h4>{% trans "Context records" %}</h4>
+<ul class='form-flex'>
+{% field_li "Number of context records" item.nb_context_records %}
+</ul>
+<ul class='form-flex'>
+{% if item.nb_context_records_by_type %}
+<li><table class='clean-table small'>
+ <tr><th>{% trans "Type" %}</th><th>{% trans "Number" %}</th></tr>
+{% for label, nb in item.nb_context_records_by_type %}
+ <tr><td>{{label}}</td><td>{{nb}}</td></tr>
+{% endfor %}
+</table></li>
+{% endif %}
+{% if item.nb_context_records_by_periods %}
+<li><table class='clean-table small'>
+ <tr><th>{% trans "Period" %}</th><th>{% trans "Number" %}</th></tr>
+{% for label, nb in item.nb_context_records_by_periods %}
+ <tr><td>{{label}}</td><td>{{nb}}</td></tr>
+{% endfor %}
+</table></li>
+{% endif %}
+</ul>
+
+<h4>{% trans "Finds" %}</h4>
+<ul class='form-flex'>
+{% field_li "Number of finds" item.nb_finds %}
+</ul>
+<ul class='form-flex'>
+{% if item.nb_finds_by_material_type %}
+<li><table class='clean-table small'>
+ <tr><th>{% trans "Material type" %}</th><th>{% trans "Number" %}</th></tr>
+{% for label, nb in item.nb_finds_by_material_type %}
+ <tr><td>{{label}}</td><td>{{nb}}</td></tr>
+{% endfor %}
+</table></li>
+{% endif %}
+{% if item.nb_finds_by_types %}
+<li><table class='clean-table small'>
+ <tr><th>{% trans "Object type" %}</th><th>{% trans "Number" %}</th></tr>
+{% for label, nb in item.nb_finds_by_types %}
+ <tr><td>{{label}}</td><td>{{nb}}</td></tr>
+{% endfor %}
+</table></li>
+{% endif %}
+{% if item.nb_finds_by_periods %}
+<li><table class='clean-table small'>
+ <tr><th>{% trans "Period" %}</th><th>{% trans "Number" %}</th></tr>
+{% for label, nb in item.nb_finds_by_periods %}
+ <tr><td>{{label}}</td><td>{{nb}}</td></tr>
+{% endfor %}
+</table></li>
+{% endif %}
+</ul>
+
+<h4>{% trans "Sources" %}</h4>
+<ul class='form-flex'>
+{% field_li "Number of sources" item.nb_documents %}
+</ul>
+<ul class='form-flex'>
+{% if item.nb_documents_by_types %}
+<li><table class='clean-table small'>
+ <tr><th>{% trans "Type" %}</th><th>{% trans "Number" %}</th></tr>
+{% for label, nb in item.nb_documents_by_types %}
+ <tr><td>{{label}}</td><td>{{nb}}</td></tr>
+{% endfor %}
+</table></li>
+{% endif %}
+</ul>
+
+{% if item.nb_stats_finds_by_ue %}
+<h4>{% trans "Finds by context records" %}</h4>
+<ul class='form-flex'>
+{% field_li "Mean" item.nb_stats_finds_by_ue.mean %}
+{% field_li "Min" item.nb_stats_finds_by_ue.min %}
+{% field_li "Max" item.nb_stats_finds_by_ue.max %}
+{% field_li "Mode" item.nb_stats_finds_by_ue.mode %}
+</ul>
+{% endif %}
+
{% endblock %}
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index c536b64ae..186d88f1a 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -2200,6 +2200,7 @@ pre_delete.connect(pre_delete_import, sender=Import)
class Organization(Address, Merge, OwnPerms, ValueGetter):
TABLE_COLS = ('name', 'organization_type',)
+ SHOW_URL = 'show-organization'
name = models.CharField(_(u"Name"), max_length=500)
organization_type = models.ForeignKey(OrganizationType,
verbose_name=_(u"Type"))
diff --git a/ishtar_common/static/media/style.css b/ishtar_common/static/media/style.css
index 02f4d930b..7dd424974 100644
--- a/ishtar_common/static/media/style.css
+++ b/ishtar_common/static/media/style.css
@@ -1276,6 +1276,10 @@ table.table-form td input{
border-color:#922;
}
+.clean-table.small {
+ width: auto;
+}
+
.clean-table {
margin: 10px 0 10px 0;
width: 100%;
diff --git a/ishtar_common/templatetags/link_to_window.py b/ishtar_common/templatetags/link_to_window.py
index 288bfcd8a..93924b77a 100644
--- a/ishtar_common/templatetags/link_to_window.py
+++ b/ishtar_common/templatetags/link_to_window.py
@@ -10,6 +10,8 @@ register = Library()
@register.filter
def link_to_window(item):
+ if not item:
+ return ""
return mark_safe(
u' <a class="display_details" href="#" '
u'onclick="load_window(\'{}\')">'
diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py
index 9fe7a3a00..d4973012e 100644
--- a/ishtar_common/utils.py
+++ b/ishtar_common/utils.py
@@ -56,3 +56,8 @@ def shortify(lbl, number=20):
if len(lbl) <= number:
return lbl
return lbl[:number - len(SHORTIFY_STR)] + SHORTIFY_STR
+
+
+def mode(array):
+ most = max(list(map(array.count, array)))
+ return list(set(filter(lambda x: array.count(x) == most, array)))
diff --git a/version.py b/version.py
index 0f4077755..424b4478e 100644
--- a/version.py
+++ b/version.py
@@ -1,4 +1,4 @@
-VERSION = (0, 97, 4)
+VERSION = (0, 97, 4, 1)
def get_version():