summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/templates/ishtar/blocks/window_tables/static_documents.html11
-rw-r--r--ishtar_common/templates/ishtar/sheet_person.html6
-rw-r--r--ishtar_common/templatetags/window_tables.py54
-rw-r--r--ishtar_common/views.py3
-rw-r--r--ishtar_common/widgets.py18
5 files changed, 77 insertions, 15 deletions
diff --git a/ishtar_common/templates/ishtar/blocks/window_tables/static_documents.html b/ishtar_common/templates/ishtar/blocks/window_tables/static_documents.html
new file mode 100644
index 000000000..d6686b553
--- /dev/null
+++ b/ishtar_common/templates/ishtar/blocks/window_tables/static_documents.html
@@ -0,0 +1,11 @@
+{% load i18n %}
+
+<table class='simple'>
+ <caption>{{caption}}</caption>
+ <tr>{% for col in col_names %}
+ <th>{% trans col %}</th>{% endfor %}
+ </tr>{% for item in data %}
+ <tr>{% for value in item %}
+ <td>{{value}}</td>{%endfor%}
+ </tr>{% endfor %}
+</table>
diff --git a/ishtar_common/templates/ishtar/sheet_person.html b/ishtar_common/templates/ishtar/sheet_person.html
index 2dfc4bbea..796fe2c4a 100644
--- a/ishtar_common/templates/ishtar/sheet_person.html
+++ b/ishtar_common/templates/ishtar/sheet_person.html
@@ -35,17 +35,17 @@
{% trans "Associated operations as scientist" as ao %}
{% if item.operation_scientist_responsability.count %}
-{% dynamic_table_document ao 'operations' 'scientist' item.pk %}
+{% dynamic_table_document ao 'operations' 'scientist' item.pk '' output %}
{% endif %}
{% trans "Associated operations as responsible" as ao %}
{% if item.operation_responsability.count %}
-{% dynamic_table_document ao 'operations' 'in_charge' item.pk %}
+{% dynamic_table_document ao 'operations' 'in_charge' item.pk '' output %}
{% endif %}
{% trans "Associated archaelogical files" as af %}
{% if item.file_responsability.count %}
-{% dynamic_table_document af 'files' 'in_charge' item.pk %}
+{% dynamic_table_document af 'files' 'in_charge' item.pk '' output %}
{% endif %}
<table>
diff --git a/ishtar_common/templatetags/window_tables.py b/ishtar_common/templatetags/window_tables.py
index a1aa735a7..687b2cf49 100644
--- a/ishtar_common/templatetags/window_tables.py
+++ b/ishtar_common/templatetags/window_tables.py
@@ -1,8 +1,11 @@
+import json
import time
from django import template
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.translation import ugettext_lazy as _
from ishtar_common.forms import reverse_lazy
@@ -52,16 +55,21 @@ except:
pass
-@register.inclusion_tag('ishtar/blocks/window_tables/dynamic_documents.html')
-def dynamic_table_document(caption, associated_model, key, value,
- table_cols='TABLE_COLS'):
+@register.simple_tag(takes_context=True)
+def dynamic_table_document(context, caption, associated_model, key, value,
+ table_cols='TABLE_COLS', output='html'):
+ if not table_cols:
+ table_cols = 'TABLE_COLS'
model, url, url_full = ASSOCIATED_MODELS[associated_model]
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 = '?{}={}'.format(key, value)
- col_names, extra_cols = grid.get_cols()
- return {'caption': caption,
+ if output == 'html':
+ col_names, extra_cols = grid.get_cols()
+ t = get_template('ishtar/blocks/window_tables/dynamic_documents.html')
+ context = template.Context({
+ 'caption': caption,
'name': slugify(caption) + '{}'.format(int(time.time())),
'source': source + source_attrs,
'source_full': source_full,
@@ -72,4 +80,38 @@ def dynamic_table_document(caption, associated_model, key, value,
'no_result': unicode(_("No results")),
'loading': unicode(_("Loading...")),
'encoding': settings.ENCODING or 'utf-8',
- }
+ })
+ return t.render(context)
+ else:
+ col_names, extra_cols = grid.get_cols(python=True)
+ view, args, kwargs = resolve(source)
+ request = context['request']
+ if source_attrs and source_attrs.startswith('?'):
+ source_attrs = source_attrs[1:]
+ dct = {}
+ for attr in source_attrs.split('&'):
+ if '=' in attr:
+ key, val = attr.split('=')
+ dct[key] = val
+ request.GET = dct
+ kwargs['request'] = request
+ page = view(*args, **kwargs)
+ data = []
+ if page.content:
+ res = json.loads(page.content)
+ if "rows" in res:
+ for r in res["rows"]:
+ d = []
+ for col in extra_cols:
+ if col in r:
+ d.append(r[col])
+ else:
+ d.append('')
+ data.append(d)
+ t = get_template('ishtar/blocks/window_tables/static_documents.html')
+ context = template.Context({
+ 'caption': caption,
+ 'col_names': col_names,
+ 'data': data
+ })
+ return t.render(context)
diff --git a/ishtar_common/views.py b/ishtar_common/views.py
index 1c944441f..5ea53374d 100644
--- a/ishtar_common/views.py
+++ b/ishtar_common/views.py
@@ -729,6 +729,7 @@ def show_item(model, name, extra_dct=None):
dct.update(extra_dct(request, item))
context_instance = RequestContext(request)
context_instance.update(dct)
+ context_instance['output'] = 'html'
filename = ""
if hasattr(item, 'history_object'):
filename = item.history_object.associated_filename
@@ -736,6 +737,7 @@ def show_item(model, name, extra_dct=None):
filename = item.associated_filename
if doc_type == "odt" and settings.ODT_TEMPLATE:
tpl = loader.get_template('ishtar/sheet_%s.html' % name)
+ context_instance['output'] = 'ODT'
content = tpl.render(context_instance)
try:
tidy_options = {'output-xhtml': 1, 'indent': 1,
@@ -775,6 +777,7 @@ def show_item(model, name, extra_dct=None):
return response
elif doc_type == 'pdf':
tpl = loader.get_template('ishtar/sheet_%s_pdf.html' % name)
+ context_instance['output'] = 'PDF'
content = tpl.render(context_instance)
result = StringIO.StringIO()
html = content.encode('utf-8')
diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py
index 688648e10..57aa8cf69 100644
--- a/ishtar_common/widgets.py
+++ b/ishtar_common/widgets.py
@@ -524,7 +524,7 @@ class JQueryJqGrid(forms.RadioSelect):
self.new, self.new_message = new, new_message
self.source_full = source_full
- def get_cols(self):
+ def get_cols(self, python=False):
jq_col_names, extra_cols = [], []
col_labels = {}
if hasattr(self.associated_model, self.table_cols + '_LBL'):
@@ -557,13 +557,19 @@ class JQueryJqGrid(forms.RadioSelect):
field_name += f_name
field_verbose_names.append(unicode(field_verbose_name))
if field_name in col_labels:
- jq_col_names.append(u'"%s"' % unicode(col_labels[field_name]))
+ jq_col_names.append(unicode(col_labels[field_name]))
else:
- jq_col_names.append(u'"%s"' % settings.JOINT.join(
+ jq_col_names.append(settings.JOINT.join(
[f for f in field_verbose_names if f]))
- extra_cols.append(self.COL_TPL % {'idx': field_name})
- jq_col_names = jq_col_names and ", ".join(jq_col_names) or ""
- extra_cols = extra_cols and ", ".join(extra_cols) or ""
+ if not python:
+ jq_col_names[-1] = u'"%s"' % jq_col_names[-1]
+ if python:
+ extra_cols.append(field_name)
+ else:
+ extra_cols.append(self.COL_TPL % {'idx': field_name})
+ if not python:
+ jq_col_names = jq_col_names and ", ".join(jq_col_names) or ""
+ extra_cols = extra_cols and ", ".join(extra_cols) or ""
return jq_col_names, extra_cols
def render(self, name, value=None, attrs=None):