diff options
Diffstat (limited to 'ishtar')
| -rw-r--r-- | ishtar/furnitures/models.py | 8 | ||||
| -rw-r--r-- | ishtar/furnitures/views.py | 26 | ||||
| -rw-r--r-- | ishtar/templates/sheet_file.html | 3 | 
3 files changed, 28 insertions, 9 deletions
diff --git a/ishtar/furnitures/models.py b/ishtar/furnitures/models.py index ce94e4042..08790018f 100644 --- a/ishtar/furnitures/models.py +++ b/ishtar/furnitures/models.py @@ -361,9 +361,11 @@ class File(BaseHistorizedItem, OwnPerms):              return self.total_developed_surface/10000.0      def operation_acts(self): -        return [act for act in -                [ope.administrative_act.all() for ope in self.operations.all()] -               ] +        acts = [] +        for ope in self.operations.all(): +            for act in ope.administrative_act.all(): +                acts.append(act) +        return acts      def is_preventive(self):          return FileType.is_preventive(self.file_type.pk) diff --git a/ishtar/furnitures/views.py b/ishtar/furnitures/views.py index 34d5c4655..b6e6f91eb 100644 --- a/ishtar/furnitures/views.py +++ b/ishtar/furnitures/views.py @@ -25,7 +25,9 @@ import csv  import json  import datetime  import optparse +import cStringIO as StringIO  from tempfile import NamedTemporaryFile +import ho.pisa as pisa  from django.http import HttpResponse, Http404  from django.template import RequestContext, loader @@ -238,9 +240,12 @@ def show_item(model, name):          except ObjectDoesNotExist:              return HttpResponse(None)          doc_type = 'type' in dct and dct.pop('type') -        dct['item'] = item +        dct['item'], dct['item_name'] = item, name          context_instance = RequestContext(request)          context_instance.update(dct) +        n = datetime.datetime.now() +        filename = u'%s_%s_%s' % (name, slugify(unicode(item)), +                                  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) @@ -276,12 +281,23 @@ def show_item(model, name):                  return HttpResponse(content, content_type="application/xhtml")              response = HttpResponse(                              mimetype='application/vnd.oasis.opendocument.text') -            n = datetime.datetime.now() -            filename = u'%s_%s_%s.odt' % (name, slugify(unicode(item)), -                                          n.strftime('%Y%m%d-%H%M%S')) -            response['Content-Disposition'] = 'attachment; filename=%s'%filename +            response['Content-Disposition'] = 'attachment; filename=%s.odt' % \ +                                                                       filename              response.write(hop)              return response +        elif doc_type == 'pdf': +            tpl = loader.get_template('sheet_%s.html' % name) +            content = tpl.render(context_instance) +            result = StringIO.StringIO() +            pdf = pisa.pisaDocument(StringIO.StringIO(content.encode("utf-8")), +                                    result) +            response = HttpResponse(result.getvalue(), +                                    mimetype='application/pdf') +            response['Content-Disposition'] = 'attachment; filename=%s.pdf' % \ +                                                                       filename +            if not pdf.err: +                return response +            return HttpResponse(content, content_type="application/xhtml")          else:              tpl = loader.get_template('sheet_%s_window.html' % name)              content = tpl.render(context_instance) diff --git a/ishtar/templates/sheet_file.html b/ishtar/templates/sheet_file.html index ea0fc20bd..5ec77a28b 100644 --- a/ishtar/templates/sheet_file.html +++ b/ishtar/templates/sheet_file.html @@ -1,6 +1,7 @@  {% extends "sheet.html" %}  {% load i18n %}  {% block content %} +<div class='tool'>{%trans "Export as:"%} <a href='{% url show-file item.pk "odt" %}'>{%trans "OpenOffice.org file"%} (experimental)</a>, <a href='{% url show-file item.pk "pdf" %}'>{%trans "PDF file"%} (experimental)</a></div>  <h3>{% trans "General"%}</h3>  <p><label>{%trans "Year:"%}</label><span class='value'>{{ item.year }}</span></p>  <p><label>{%trans "Numerical reference:"%}</label><span class='value'>{{ item.numeric_reference }}</span></p> @@ -24,7 +25,7 @@  <p><label>{%trans "Type:"%}</label><span class='value'>{{ item.file_type }}</span></p> -{% if item.related_file %}<p><label>{%trans "Related file:"%}</label><span class='value'><a href='{% url show-file item.related_file.pk %}'>{{ item.related_file }}</a></span></p>{% endif %} <!-- Displayed as Year/index/Commune/Common_name This should be a link to the file sheet of the related file --> +{% if item.related_file %}<p><label>{%trans "Related file:"%}</label><span class='value'><a href='{% url show-file item.related_file.pk ''%}'>{{ item.related_file }}</a></span></p>{% endif %} <!-- Displayed as Year/index/Commune/Common_name This should be a link to the file sheet of the related file -->  {% if item.comment %}<p><label>{%trans "Comment:"%}</label><span class='value'>{{ item.comment }}</span></p>{%endif%}  <h3>{% trans "Localisation"%}</h3>  | 
