summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archaeological_context_records/templates/ishtar/sheet_contextrecord.html10
-rw-r--r--archaeological_operations/templates/ishtar/sheet_operation.html10
-rw-r--r--ishtar_common/templates/ishtar/blocks/window_tables/dynamic_documents.html8
-rw-r--r--ishtar_common/templatetags/window_tables.py58
-rw-r--r--ishtar_common/views.py5
-rw-r--r--ishtar_common/widgets.py2
6 files changed, 44 insertions, 49 deletions
diff --git a/archaeological_context_records/templates/ishtar/sheet_contextrecord.html b/archaeological_context_records/templates/ishtar/sheet_contextrecord.html
index f7296848b..ecd80e36f 100644
--- a/archaeological_context_records/templates/ishtar/sheet_contextrecord.html
+++ b/archaeological_context_records/templates/ishtar/sheet_contextrecord.html
@@ -124,14 +124,18 @@
{% endif %}
{% trans "Document from this context record" as cr_docs %}
-{% if item.source.count %} {% table_document cr_docs item.source.all %}{% endif %}
+{% if item.source.count %}
+{% dynamic_table_document cr_docs 'context_records_docs' 'context_record' item.pk '' output %}
+{% endif %}
{% 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 %}
-{% trans "Documents from associated finds" as find_docs %}
-{% if item.find_docs_q.count %} {% table_document find_docs item.find_docs_q.all %}{% endif %}
+{% 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 %}
+{% endif %}
{% endblock %}
diff --git a/archaeological_operations/templates/ishtar/sheet_operation.html b/archaeological_operations/templates/ishtar/sheet_operation.html
index 14210046b..d1cd1578c 100644
--- a/archaeological_operations/templates/ishtar/sheet_operation.html
+++ b/archaeological_operations/templates/ishtar/sheet_operation.html
@@ -145,21 +145,19 @@
{% dynamic_table_document context_records 'context_records_for_ope' 'operation' item.pk 'TABLE_COLS_FOR_OPE' output %}
{% endif %}
-{% comment %}
{% trans "Documents from associated context records" as cr_docs %}
{% if item.context_record_docs_q.count %}
{% dynamic_table_document cr_docs 'context_records_docs' 'context_record__operation' item.pk '' output %}
{% endif %}
-{% endcomment %}
{% trans "Finds" as finds %}
{% if item.finds %}
{% dynamic_table_document finds 'finds_for_ope' 'base_finds__context_record__operation' item.pk 'TABLE_COLS_FOR_OPE' output %}
{% endif %}
-{% comment %}
-{% trans "Documents from associated finds" as find_docs %}
-{% if item.find_docs_q.count %} {% table_document find_docs item.find_docs_q.all %}{% endif %}
-{% endcomment %}
+{% 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__operation' item.pk '' output %}
+{% endif %}
{% endblock %}
diff --git a/ishtar_common/templates/ishtar/blocks/window_tables/dynamic_documents.html b/ishtar_common/templates/ishtar/blocks/window_tables/dynamic_documents.html
index 76172d3ac..7239b64fc 100644
--- a/ishtar_common/templates/ishtar/blocks/window_tables/dynamic_documents.html
+++ b/ishtar_common/templates/ishtar/blocks/window_tables/dynamic_documents.html
@@ -7,10 +7,10 @@
<div id='foot_{{name}}' class='gridfooter'>
{% if source_full %}
{% trans "Export as CSV" %} ({{encoding}})
-<a href='{{simple_source}}csv{{ source_attrs }}' target='_blank'>{% trans "simple" %}</a> -
-<a href='{{source_full}}csv{{ source_attrs }}' target='_blank'>{% trans "full" %}</a>
+<a href='{{simple_source}}csv{{ source_attrs|safe }}' target='_blank'>{% trans "simple" %}</a> -
+<a href='{{source_full}}csv{{ source_attrs|safe }}' target='_blank'>{% trans "full" %}</a>
{% else %}
-<a href="{{simple_source}}csv{{ source_attrs }}" target="_blank">{% trans "Export as CSV" %} ({{encoding}})</a>
+<a href="{{simple_source}}csv{{ source_attrs|safe }}" target="_blank">{% trans "Export as CSV" %} ({{encoding}})</a>
{% endif %}
</div>
@@ -19,7 +19,7 @@
setTimeout(
function(){
$("#grid_{{name}}").jqGrid({
- url:'{{source}}',
+ url:'{{source|safe}}',
datatype: "json",
mtype: 'GET',
colNames:['id', '', {{col_names|safe}}],
diff --git a/ishtar_common/templatetags/window_tables.py b/ishtar_common/templatetags/window_tables.py
index 53075b20e..cdd681b52 100644
--- a/ishtar_common/templatetags/window_tables.py
+++ b/ishtar_common/templatetags/window_tables.py
@@ -6,11 +6,18 @@ from django.conf import settings
from django.core.urlresolvers import resolve
from django.template.defaultfilters import slugify
from django.template.loader import get_template
+from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
from ishtar_common.forms import reverse_lazy
from ishtar_common.widgets import JQueryJqGrid
+from archaeological_files.models import File
+from archaeological_operations.models import OperationSource, Operation
+from archaeological_context_records.models import ContextRecord, \
+ ContextRecordSource
+from archaeological_finds.models import Find, FindSource
+
register = template.Library()
@@ -19,40 +26,21 @@ def table_document(caption, data):
return {'caption': caption, 'data': data}
ASSOCIATED_MODELS = {}
-try:
- from archaeological_files.models import File
- ASSOCIATED_MODELS['files'] = (File, 'get-file', '')
-except:
- pass
-
-try:
- from archaeological_operations.models import OperationSource, Operation
- ASSOCIATED_MODELS['operation_docs'] = (OperationSource,
- 'get-operationsource', '')
- ASSOCIATED_MODELS['operations'] = (Operation, 'get-operation', '')
-except:
- pass
-
-try:
- from archaeological_context_records.models import ContextRecord, \
- ContextRecordSource
- ASSOCIATED_MODELS['context_records'] = (ContextRecord, 'get-contextrecord',
- 'get-contextrecord-full')
- ASSOCIATED_MODELS['context_records_for_ope'] = (
- ContextRecord,
- 'get-contextrecord-for-ope', 'get-contextrecord-full')
- ASSOCIATED_MODELS['context_records_docs'] = (ContextRecordSource,
- 'get-contextrecordsource', '')
-except:
- pass
-
-try:
- from archaeological_finds.models import Find
- ASSOCIATED_MODELS['finds'] = (Find, 'get-find', 'get-find-full')
- ASSOCIATED_MODELS['finds_for_ope'] = (
- Find, 'get-find-for-ope', 'get-find-full')
-except:
- pass
+ASSOCIATED_MODELS['files'] = (File, 'get-file', '')
+ASSOCIATED_MODELS['operation_docs'] = (OperationSource,
+ 'get-operationsource', '')
+ASSOCIATED_MODELS['operations'] = (Operation, 'get-operation', '')
+ASSOCIATED_MODELS['context_records'] = (ContextRecord, 'get-contextrecord',
+ 'get-contextrecord-full')
+ASSOCIATED_MODELS['context_records_for_ope'] = (
+ ContextRecord,
+ 'get-contextrecord-for-ope', 'get-contextrecord-full')
+ASSOCIATED_MODELS['context_records_docs'] = (ContextRecordSource,
+ 'get-contextrecordsource', '')
+ASSOCIATED_MODELS['finds'] = (Find, 'get-find', 'get-find-full')
+ASSOCIATED_MODELS['finds_for_ope'] = (
+ Find, 'get-find-for-ope', 'get-find-full')
+ASSOCIATED_MODELS['finds_docs'] = (FindSource, 'get-findsource', '')
@register.simple_tag(takes_context=True)
@@ -64,7 +52,7 @@ def dynamic_table_document(context, caption, associated_model, key, value,
grid = JQueryJqGrid(None, None, model, table_cols=table_cols)
source = unicode(reverse_lazy(url))
source_full = unicode(reverse_lazy(url_full)) if url_full else ''
- source_attrs = '?submited=1&{}={}'.format(key, value)
+ source_attrs = mark_safe('?submited=1&{}={}'.format(key, value))
if output == 'html':
col_names, extra_cols = grid.get_cols()
t = get_template('ishtar/blocks/window_tables/dynamic_documents.html')
diff --git a/ishtar_common/views.py b/ishtar_common/views.py
index 5ea53374d..54eb9164f 100644
--- a/ishtar_common/views.py
+++ b/ishtar_common/views.py
@@ -572,7 +572,12 @@ def get_item(model, func_name, default_name, extra_request_keys=[],
datas = []
if old:
items = [item.get_previous(old) for item in items]
+ c_ids = []
for item in items:
+ # manual deduplicate when distinct is not enough
+ if item.pk in c_ids:
+ continue
+ c_ids.append(item.pk)
data = [item.pk]
for keys in table_cols:
if type(keys) not in (list, tuple):
diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py
index 57aa8cf69..b8b104a61 100644
--- a/ishtar_common/widgets.py
+++ b/ishtar_common/widgets.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-# Copyright (C) 2010-2015 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
+# Copyright (C) 2010-2016 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
# Copyright (C) 2007 skam <massimo dot scamarcia at gmail.com>
# (http://djangosnippets.org/snippets/233/)