summaryrefslogtreecommitdiff
path: root/ishtar_common/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/views.py')
-rw-r--r--ishtar_common/views.py25
1 files changed, 18 insertions, 7 deletions
diff --git a/ishtar_common/views.py b/ishtar_common/views.py
index 4a1a656d9..641ca8046 100644
--- a/ishtar_common/views.py
+++ b/ishtar_common/views.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-# Copyright (C) 2010-2012 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
+# Copyright (C) 2010-2013 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
@@ -170,10 +170,10 @@ def format_val(val):
return unicode(val)
HIERARCHIC_LEVELS = 5
-HIERARCHIC_FIELDS = ['period', 'unit', 'material_type']
+HIERARCHIC_FIELDS = ['periods', 'period', 'unit', 'material_type']
PRIVATE_FIELDS = ('id', 'history_modifier', 'order')
def get_item(model, func_name, default_name, extra_request_keys=[],
- base_request={}, bool_fields=[]):
+ base_request={}, bool_fields=[], dated_fields=[]):
"""
Generic treatment of tables
"""
@@ -213,7 +213,18 @@ def get_item(model, func_name, default_name, extra_request_keys=[],
dct.pop(k)
else:
dct[k] = dct[k] == u"2" and True or False
-
+ for k in dated_fields:
+ if k in dct:
+ if not dct[k]:
+ dct.pop(k)
+ try:
+ items = dct[k].split('/')
+ assert len(items) == 3
+ dct[k] = datetime.date(*map(lambda x: int(x),
+ reversed(items))
+ ).strftime('%Y-%m-%d')
+ except AssertionError:
+ dct.pop(k)
# manage hierarchic conditions
or_reqs = []
for req in dct.copy():
@@ -373,7 +384,7 @@ def show_item(model, name):
n.strftime('%Y%m%d-%H%M%S'))
if doc_type == "odt" and settings.XHTML2ODT_PATH and \
settings.ODT_TEMPLATE:
- tpl = loader.get_template('sheet_%s.html' % name)
+ tpl = loader.get_template('ishtar/sheet_%s.html' % name)
content = tpl.render(context_instance)
try:
tidy_options = dict(output_xhtml=1, add_xml_decl=1, indent=1,
@@ -413,7 +424,7 @@ def show_item(model, name):
response.write(odtfile)
return response
elif doc_type == 'pdf':
- tpl = loader.get_template('sheet_%s_pdf.html' % name)
+ tpl = loader.get_template('ishtar/sheet_%s_pdf.html' % name)
content = tpl.render(context_instance)
result = StringIO.StringIO()
html = content.encode('utf-8')
@@ -427,7 +438,7 @@ def show_item(model, name):
return response
return HttpResponse(content, content_type="application/xhtml")
else:
- tpl = loader.get_template('sheet_%s_window.html' % name)
+ tpl = loader.get_template('ishtar/sheet_%s_window.html' % name)
content = tpl.render(context_instance)
return HttpResponse(content, content_type="application/xhtml")
return func