From 18d121d62ef401dda9b76e43589b605f932504fb Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 25 Feb 2011 16:32:35 +0100 Subject: Work on file sheet and pdf export (refs #227) --- ishtar/furnitures/models.py | 8 +++++--- ishtar/furnitures/views.py | 26 +++++++++++++++++++++----- ishtar/templates/sheet_file.html | 3 ++- static/media/style.css | 12 +++++++++++- 4 files changed, 39 insertions(+), 10 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 %} +
{%trans "Export as:"%} {%trans "OpenOffice.org file"%} (experimental), {%trans "PDF file"%} (experimental)

{% trans "General"%}

{{ item.year }}

{{ item.numeric_reference }}

@@ -24,7 +25,7 @@

{{ item.file_type }}

-{% if item.related_file %}

{{ item.related_file }}

{% endif %} +{% if item.related_file %}

{{ item.related_file }}

{% endif %} {% if item.comment %}

{{ item.comment }}

{%endif%}

{% trans "Localisation"%}

diff --git a/static/media/style.css b/static/media/style.css index f4dd8ddc9..0c0ef338e 100644 --- a/static/media/style.css +++ b/static/media/style.css @@ -110,7 +110,7 @@ div#main_menu > ul{ } div#context_menu fieldset{ - right:20px;; + right:20px; position:absolute; width:420px; background-color:#EEE; @@ -291,6 +291,11 @@ table.confirm tr.spacer td:last-child{ text-align:left; } +#window table td.no_items{ +text-align:center; +font-style:italic; +} + #window .sheet{ } @@ -306,6 +311,11 @@ table.confirm tr.spacer td:last-child{ border-top-right-radius: 8px; } +#window .tool{ +text-align:center; +font-style:italic; +} + #window .body{ position:absolute; padding:10px; -- cgit v1.2.3