summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@peacefrogs.net>2011-02-25 15:58:32 +0100
committerÉtienne Loks <etienne.loks@peacefrogs.net>2011-02-25 15:58:32 +0100
commitee554dc96321418f22a482f48dce8dd2fb700233 (patch)
tree5b761be14e420b8fb41ccaf55773f2f7d0f85611
parent029945ebd31fce0a3283c6dd581caa65a758bb45 (diff)
downloadIshtar-ee554dc96321418f22a482f48dce8dd2fb700233.tar.bz2
Ishtar-ee554dc96321418f22a482f48dce8dd2fb700233.zip
Work on file sheet and odt export (refs #227)
-rw-r--r--.gitignore1
-rw-r--r--docs/src/INSTALL.t2t3
-rw-r--r--ishtar/__init__.py5
-rw-r--r--ishtar/furnitures/models.py9
-rw-r--r--ishtar/furnitures/urls.py5
-rw-r--r--ishtar/furnitures/views.py62
-rw-r--r--ishtar/settings.py.example2
-rw-r--r--ishtar/templates/sheet.html16
-rw-r--r--ishtar/templates/sheet_file.html151
-rw-r--r--ishtar/templates/sheet_file_window.html3
-rw-r--r--static/media/style.css15
-rw-r--r--static/template.odtbin0 -> 7013 bytes
12 files changed, 185 insertions, 87 deletions
diff --git a/.gitignore b/.gitignore
index d79b2cf6f..e282b5668 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,5 +3,6 @@
*.mo
django-simple-history/*
django-formwizard/*
+xhtml2odt
ishtar-docs
ishtar-logo
diff --git a/docs/src/INSTALL.t2t b/docs/src/INSTALL.t2t
index 8f28ac8fd..c485f0d96 100644
--- a/docs/src/INSTALL.t2t
+++ b/docs/src/INSTALL.t2t
@@ -29,7 +29,8 @@ cd django-simple-history
python setup.py install
```
-
+git clone git://gitorious.org/xhtml2odt/xhtml2odt.git
+INSTALL_PATH = "/home/etienne/work/ishtar/xhtml2odt"
Import towns:
curl --location --globoff "http://openstreetmap.us/xapi/api/0.6/node[place=village|town|city][bbox=-5.53711,41.90228,8.96484,51.50874]" -o data.osm
diff --git a/ishtar/__init__.py b/ishtar/__init__.py
index 128bebf23..d9bcb5701 100644
--- a/ishtar/__init__.py
+++ b/ishtar/__init__.py
@@ -2,4 +2,7 @@
from django.utils.translation import ugettext as _
_("username")
_("email address")
-
+if settings.XHTML2ODT_PATH:
+ import sys
+ sys.path.append(settings.XHTML2ODT_PATH)
+ from xhtml2odt import xhtml2odt
diff --git a/ishtar/furnitures/models.py b/ishtar/furnitures/models.py
index 3b73baba0..ce94e4042 100644
--- a/ishtar/furnitures/models.py
+++ b/ishtar/furnitures/models.py
@@ -237,7 +237,7 @@ class Person(Address, OwnPerms) :
return lbl
def full_label(self):
- return " ".join([getattr(self, attr)
+ return u" ".join([unicode(getattr(self, attr))
for attr in ('title', 'surname', 'name', 'attached_to')
if getattr(self, attr)])
@@ -360,6 +360,11 @@ class File(BaseHistorizedItem, OwnPerms):
if self.total_developed_surface:
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()]
+ ]
+
def is_preventive(self):
return FileType.is_preventive(self.file_type.pk)
@@ -391,7 +396,7 @@ class Operation(BaseHistorizedItem, OwnPerms):
blank=True, verbose_name=_(u"In charge"))
year = models.IntegerField(_(u"Year"))
operation_code = models.IntegerField(_(u"Operation code"))
- associated_file = models.ForeignKey(File, related_name='+',
+ associated_file = models.ForeignKey(File, related_name='operations',
verbose_name=_(u"File"), blank=True, null=True)
operation_type = models.ForeignKey(OperationType, related_name='+',
verbose_name=_(u"Operation type"))
diff --git a/ishtar/furnitures/urls.py b/ishtar/furnitures/urls.py
index 5123609fc..c93f14c78 100644
--- a/ishtar/furnitures/urls.py
+++ b/ishtar/furnitures/urls.py
@@ -87,13 +87,14 @@ urlpatterns += patterns('ishtar.furnitures.views',
name='autocomplete-file'),
url(BASE_URL + r'get-file/(?P<type>.+)?$', 'get_file',
name='get-file'),
- url(BASE_URL + r'show-file/(?P<pk>.+)?$', 'show_file',
+ url(BASE_URL + r'show-file/(?P<pk>.+)?/(?P<type>.+)?$', 'show_file',
name='show-file'),
url(BASE_URL + r'autocomplete-operation/$', 'autocomplete_operation',
name='autocomplete-operation'),
url(BASE_URL + r'get-operation/(?P<type>.+)?$', 'get_operation',
name='get-operation'),
- url(BASE_URL + r'show-operation/(?P<pk>.+)?$', 'show_operation',
+ url(BASE_URL + r'show-operation/(?P<pk>.+)?/(?P<type>.+)?$',
+ 'show_operation',
name='show-operation'),
url(BASE_URL + r'update-current-item/$', 'update_current_item',
name='update-current-item'),
diff --git a/ishtar/furnitures/views.py b/ishtar/furnitures/views.py
index 8511022a4..34d5c4655 100644
--- a/ishtar/furnitures/views.py
+++ b/ishtar/furnitures/views.py
@@ -24,9 +24,12 @@ Furnitures views
import csv
import json
import datetime
+import optparse
+from tempfile import NamedTemporaryFile
from django.http import HttpResponse, Http404
-from django.template import RequestContext
+from django.template import RequestContext, loader
+from django.template.defaultfilters import slugify
from django.shortcuts import render_to_response, redirect
from django.utils.translation import ugettext, ugettext_lazy as _
from django.core.exceptions import ObjectDoesNotExist
@@ -35,6 +38,11 @@ from django.db.models import Q
from django.core import serializers
from ishtar import settings
+if settings.XHTML2ODT_PATH:
+ import sys
+ sys.path.append(settings.XHTML2ODT_PATH)
+ from xhtml2odt import xhtml2odt
+
from menus import menu
import forms as ishtar_forms
import models
@@ -190,7 +198,7 @@ def get_item(model, func_name, default_name, extra_request_keys=[]):
for data in datas:
res = {'id':data[0],
'link':link_template % reverse('show-'+default_name,
- args=[data[0]])}
+ args=[data[0], ''])}
for idx, value in enumerate(data[1:]):
if value:
res[model.TABLE_COLS[idx].split('.')[-1]] = value
@@ -229,9 +237,55 @@ def show_item(model, name):
item = model.objects.get(pk=pk)
except ObjectDoesNotExist:
return HttpResponse(None)
+ doc_type = 'type' in dct and dct.pop('type')
dct['item'] = item
- return render_to_response('sheet_%s.html' % name, dct,
- context_instance=RequestContext(request))
+ context_instance = RequestContext(request)
+ context_instance.update(dct)
+ if doc_type == "odt" and settings.XHTML2ODT_PATH and \
+ settings.ODT_TEMPLATE:
+ tpl = loader.get_template('sheet_%s.html' % name)
+ content = tpl.render(context_instance)
+ try:
+ ht, odt = NamedTemporaryFile(), NamedTemporaryFile()
+ ht.write(content.encode('utf-8'))
+ options = optparse.Values()
+ options.input = ht.name
+ options.output = odt.name
+ options.template = settings.ODT_TEMPLATE
+ options.with_network = True
+ for k, v in (('input', ht.name),
+ ('output', None),
+ ('template', settings.ODT_TEMPLATE),
+ ('with_network', True),
+ ('top_header_level', 1),
+ ('img_width', '8cm'),
+ ('img_height', '6cm'),
+ ('verbose', False),
+ ('replace_keyword', 'ODT-INSERT'),
+ ('cut_start', 'ODT-CUT-START'),
+ ('htmlid', None),
+ ('url', "#")):
+ setattr(options, k, v)
+ htmlfile = xhtml2odt.HTMLFile(options)
+ htmlfile.read()
+ odtfile = xhtml2odt.ODTFile(options)
+ odtfile.open()
+ odtfile.import_xhtml(htmlfile.html)
+ hop = odtfile.save()
+ except xhtml2odt.ODTExportError, ex:
+ 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.write(hop)
+ return response
+ else:
+ tpl = loader.get_template('sheet_%s_window.html' % name)
+ content = tpl.render(context_instance)
+ return HttpResponse(content, content_type="application/xhtml")
return func
get_file = get_item(models.File, 'get_file', 'file')
diff --git a/ishtar/settings.py.example b/ishtar/settings.py.example
index 99017d049..4b3388389 100644
--- a/ishtar/settings.py.example
+++ b/ishtar/settings.py.example
@@ -11,6 +11,8 @@ ROOT_PATH = "/var/local/webapp/ishtar/ishtar/"
URL_PATH = ""
JQUERY_URL = "/javascript/jquery/jquery.js"
JQUERY_UI_URL = "/javascript/jquery-ui/"
+XHTML2ODT_PATH = ROOT_PATH + "../xhtml2odt"
+ODT_TEMPLATE = ROOT_PATH + "../static/template.odt"
LOGIN_REDIRECT_URL = "/" + URL_PATH
DEBUG = True
diff --git a/ishtar/templates/sheet.html b/ishtar/templates/sheet.html
index 9d1305c1d..a93b193e0 100644
--- a/ishtar/templates/sheet.html
+++ b/ishtar/templates/sheet.html
@@ -1,7 +1,23 @@
{% load i18n %}
+{% block main_head %}
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <link rel="shortcut icon" href="{{MEDIA_URL}}/media/images/favicon.png">
+ <title>{% block title %}Ishtar{% if APP_NAME %} - {{APP_NAME}}{%endif%}{% endblock %}
+ </title>
+ <link rel="stylesheet" href="{{MEDIA_URL}}/media/style.css" />
+</head>
+<body>
+{% endblock %}
<div class="sheet">
<div class="head"><a href='#' onclick='$("#window").hide("slow")'>{% trans "Close" %}</a></div>
<div class="body">
{% block content %}{% endblock %}
</div>
</div>
+{%block main_foot%}
+</body>
+</html>
+{%endblock%}
diff --git a/ishtar/templates/sheet_file.html b/ishtar/templates/sheet_file.html
index 57f1c00fc..ea0fc20bd 100644
--- a/ishtar/templates/sheet_file.html
+++ b/ishtar/templates/sheet_file.html
@@ -2,58 +2,53 @@
{% load i18n %}
{% block content %}
<h3>{% trans "General"%}</h3>
-<p><label>{%trans "Year:"%}</label> {{ item.year }}</p>
-<p><label>{%trans "Numerical reference:"%}</label> {{ item.numeric_reference }}</p>
+<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>
-<p><label>{%trans "File's name:"%}</label> {{ item.internal_reference }}</p>
+<p><label>{%trans "File's name:"%}</label><span class='value'>{{ item.internal_reference }}</span></p>
-<p><label>{%trans "Edition date:"%}</label> {{ item.history.all.0.history_date }}</p> <!-- date = now -->
-{% if item.reception_date %}<p><label>{%trans "Reception date:"%}</label> {{ item.reception_date }}</p>{% endif %}
-<p><label>{%trans "Creation date:"%}</label> {{ item.creation_date }}</p>
+<p><label>{%trans "Edition date:"%}</label><span class='value'>{{ item.history.all.0.history_date }}</span></p> <!-- date = now -->
+{% if item.reception_date %}<p><label>{%trans "Reception date:"%}</label><span class='value'>{{ item.reception_date }}</span></p>{% endif %}
+<p><label>{%trans "Creation date:"%}</label><span class='value'>{{ item.creation_date }}</span></p>
{% comment %}
{% if item.deadline_date and not item.acts %}
- <p>{%trans "Deadline"%} : {% item.deadline_date %}</p> <!-- calculated deadline for some preventive files , see saisine_type, not displayed if an act as been send -->
+ <p><label>{%trans "Deadline:"%}</label><span class='value'>{% item.deadline_date %}</span></p> <!-- calculated deadline for some preventive files , see saisine_type, not displayed if an act as been send -->
{% endif %}
{% endcomment %}
-<p><label>{%trans "In charge:"%}</label> {{ item.in_charge.full_label }}</p>
-<p><label>{%trans "State"%}</label>
-{% if item.is_active %}{%trans "Active file"%}</strong></p>
-{% else %}{%trans "Closed file"%}</p>
-<p><label>{%trans "Closing date:"%}</label> {{ item.closing.date }} <strong>{%trans "by" %}</strong> {{ item.closing.user }}</p>
+<p><label>{%trans "In charge:"%}</label><span class='value'>{{ item.in_charge.full_label }}</span></p>
+<p><label>{%trans "State"%}</label><span class='value'>{% if item.is_active %}{%trans "Active file"%}</span></p>
+{% else %}{%trans "Closed file"%}</span></p>
+<p><label>{%trans "Closing date:"%}</label><span class='value'>{{ item.closing.date }} <strong>{%trans "by" %}</strong> {{ item.closing.user }}</span></p>
{% endif %}
-<p><label>{%trans "Type:"%}</label> {{ item.file_type }}</p>
+<p><label>{%trans "Type:"%}</label><span class='value'>{{ item.file_type }}</span></p>
-{% if item.related_file %}<p>{%trans "Related file:"%} {{ item.related_file }}</p>{% endif %} <!-- Displayed as Year/index/Commune/Common_name This should be a link to the file sheet of the related file -->
-<p><label>{%trans "Comment:"%}</label> {{ item.comment }}</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.comment %}<p><label>{%trans "Comment:"%}</label><span class='value'>{{ item.comment }}</span></p>{%endif%}
<h3>{% trans "Localisation"%}</h3>
-<p><label>{%trans "Towns:"%}</label> {{ item.towns.all|join:", " }}</p>
+<p><label>{%trans "Towns:"%}</label><span class='value'>{{ item.towns.all|join:", " }}</span></p>
-<p><label>{%trans "Main address:"%}</label> {{ item.address }}</p>
-<p><label>{%trans "Complement:"%}</label> {{ item.complem_adress }}</p>
-<p><label>{%trans "Postal code:"%}</label> {{ item.postal_code }}</p>
+<p><label>{%trans "Main address:"%}</label><span class='value'>{{ item.address }}</span></p>
+{% if item.address_complement %}<p><label>{%trans "Complement:"%}</label><span class='value'>{{ item.address_complement }}</span></p>{%endif%}
+{% if item.postal_code %}<p><label>{%trans "Postal code:"%}</label><span class='value'>{{ item.postal_code }}</span></p>{%endif%}
-<p><label>{%trans "Surface:"%}</label> {{ item.total_surface }} m<sup>2</sup> ({{ item.total_surface_ha }} ha)</p>
+<p><label>{%trans "Surface:"%}</label><span class='value'>{{ item.total_surface }} m<sup>2</sup> ({{ item.total_surface_ha }} ha)</span></p>
{% if item.is_preventive %}
<h3>{% trans "Preventive archaelogical file"%}</h3>
-<p><label>{%trans "Planed surface:"%}</label> {{ item.total_developed_surface }} m<sup>2</sup> ({{ item.total_developed_surface_ha }} ha)</p>
-<p><label>{%trans "Saisine type:"%}</label> {{ item.saisine_type }}</p>
-{% if item.town_planning_service %}<p><label>{%trans "Town planning service:"%}</label>{{ item.town_planning_service }}</p>{% endif %}
-{% if item.permit_type %}<p><label>{%trans "Permit type:"%}</label> {{ item.permit_type }}</p>{% endif %}
-{% if item.permit_reference %}<p><label>{%trans "Permit reference:"%}</label> {{ item.permit_reference }}</p>{% endif %}
-{% if item.general_contractor.attached_to %}<p><label>{%trans "General contractor organisation:"%}</label> {{ item.general_contractor.attached_to }}</p>{% endif %} <!-- Contractor's organisation displayed as concat of Name/Adress/postal_code/city -->
-{% if item.general_contractor %}<p><label>{%trans "General contractor:"%}</label> {{ item.general_contractor.full_label }}</p>{% endif %}
-{% comment %}
-<p>{%trans "Numerical reference"%} : {% item.index %}</p> <!-- index -->
-{% endcomment %}
+<p><label>{%trans "Planed surface:"%}</label><span class='value'>{{ item.total_developed_surface }} m<sup>2</sup> ({{ item.total_developed_surface_ha }} ha)</span></p>
+<p><label>{%trans "Saisine type:"%}</label><span class='value'>{{ item.saisine_type }}</span></p>
+{% if item.town_planning_service %}<p><label>{%trans "Town planning service:"%}</label><span class='value'>{{ item.town_planning_service }}</span></p>{% endif %}
+{% if item.permit_type %}<p><label>{%trans "Permit type:"%}</label><span class='value'>{{ item.permit_type }}</span></p>{% endif %}
+{% if item.permit_reference %}<p><label>{%trans "Permit reference:"%}</label><span class='value'>{{ item.permit_reference }}</span></p>{% endif %}
+{% if item.general_contractor.attached_to %}<p><label>{%trans "General contractor organisation:"%}</label><span class='value'>{{ item.general_contractor.attached_to }}</span></p>{% endif %} <!-- Contractor's organisation displayed as concat of Name/Adress/postal_code/city -->
+{% if item.general_contractor %}<p><label>{%trans "General contractor:"%}</label><span class='value'>{{ item.general_contractor.full_label }}</span></p>{% endif %}
{% endif %}
-{% if item.administrative_act.all %}
<table>
<caption>{%trans "Admninistrative acts"%}</caption>
<tr>
@@ -66,53 +61,59 @@
<tr>
<td>{{act.signature_date.year}}</td>
<td>{{act.ref_sra}}</td>
- <td>{{act.act_type}}</td>
+ <td class='string'>{{act.act_type}}</td>
<td>{{act.signature_date}}</td>
</tr>
+ {% empty %}
+ <tr><td colspan="4" class='no_items'>{% trans "No administrative act associated to this archaelogical file" %}</td></tr>
{% endfor %}
</table>
-{%endif%}
-{% comment %}
-<!-- associated operations -->
-
- <table class='adm_ope'> <!-- associated ope class-->
- <caption>{%trans "Associated operations"%}</caption>
- <tr>
- {% for label, in item.data_ope %}
- <th>{{label}}</th>
- {% endfor %}
- </tr>
- {% for data, in item.data_ope %}
- <tr>
- <td>{{year}}</td>
- <td>{{reference}}</td>
- <td>{{patriarche}}</td>
- <td>{{type}}</td>
- <td>{{head_scientist}}</td>
- <td>{{date_debut}}</td>
- <td>{{date_fin}}</td>
- <td>{{link_to_ope_sheet}}</td>
- </tr>
- {% endfor %}
- </table>
-<!-- Operation's associated acts -->
-
- <table class='adm_acts'> <!-- associated acts class-->
- <caption>{%trans "Admninistrative acts linked to associated operations"%}</caption>
- <tr>
- {% for label, in item.ope.data_acts %}
- <th>{{label}}</th>
- {% endfor %}
- </tr>
- {% for data, in item.ope.data_acts %}
- <tr>
- <td>{{year}}</td>
- <td>{{reference}}</td>
- <td>{{type}}</td>
- <td>{{date}}</td>
- </tr>
- {% endfor %}
- </table>
-{% endcomment %}
+<table>
+ <caption>{%trans "Associated operations"%}</caption>
+ <tr>
+ <th>{% trans "Year" %}</th>
+ <th>{% trans "Reference" %}</th>
+ <th>Code Patriarche</th>
+ <th>{% trans "Type" %}</th>
+ <th>{% trans "In charge" %}</th>
+ <th>{% trans "Start date" %}</th>
+ <th>{% trans "End date" %}</th>
+ <th></th>
+ </tr>
+ {% for operation in item.operations.all %}
+ <tr>
+ <td>{{operation.year}}</td>
+ <td>{{operation.operation_code}}</td>
+ <td>{{operation.code_patriarche|default:""}}</td>
+ <td class='string'>{{operation.operation_type}}</td>
+ <td class='string'>{{operation.in_charge|default:""}}</td>
+ <td>{{operation.start_date|default:""}}</td>
+ <td>{{operation.end_date|default:""}}</td>
+ <td><a href="#{#{%url show-operation operation.pk%}#}">{% trans "Details" %}</a></td>
+ </tr>
+ {% empty %}
+ <tr><td colspan="4" class='no_items'>{% trans "No operation associated to this archaelogical file" %}</td></tr>
+ {% endfor %}
+</table>
+
+<table>
+ <caption>{%trans "Admninistrative acts linked to associated operations"%}</caption>
+ <tr>
+ <th>{% trans "Year" %}</th>
+ <th>{% trans "Reference" %}</th>
+ <th>{% trans "Type" %}</th>
+ <th>{% trans "Date" %}</th>
+ </tr>
+ {% for act in item.operation_acts %}
+ <tr>
+ <td>{{act.signature_date.year}}</td>
+ <td>{{act.ref_sra}}</td>
+ <td class='string'>{{act.act_type}}</td>
+ <td>{{act.signature_date}}</td>
+ </tr>
+ {% empty %}
+ <tr><td colspan="4" class='no_items'>{% trans "No administrative act linked to operations" %}</td></tr>
+ {% endfor %}
+</table>
{% endblock %}
diff --git a/ishtar/templates/sheet_file_window.html b/ishtar/templates/sheet_file_window.html
new file mode 100644
index 000000000..e9debdd0d
--- /dev/null
+++ b/ishtar/templates/sheet_file_window.html
@@ -0,0 +1,3 @@
+{% extends "sheet_file.html" %}
+{% block main_head %}{%endblock%}
+{% block main_foot %}{%endblock%}
diff --git a/static/media/style.css b/static/media/style.css
index 5e5613cfc..f4dd8ddc9 100644
--- a/static/media/style.css
+++ b/static/media/style.css
@@ -20,7 +20,7 @@ caption, h3 {
h3{
text-align:center;
- margin:1em 0;
+ margin:1em 0 0.5em 0;
}
label{display:block}
@@ -264,6 +264,7 @@ table.confirm tr.spacer td:last-child{
}
#window table{
+ font-size:0.9em;
margin:10px 0;
width:100%;
border-collapse:collapse;
@@ -279,12 +280,17 @@ table.confirm tr.spacer td:last-child{
border:1px solid #EEE;
color:#FFF;
}
+
#window table td{
text-align:right;
padding:0 1em;
border:1px solid #EEE;
}
+#window table td.string{
+ text-align:left;
+}
+
#window .sheet{
}
@@ -311,7 +317,12 @@ table.confirm tr.spacer td:last-child{
#window label{
display:inline-table;
font-weight:bold;
- width:160px;
+ width:240px;
+}
+
+#window span.value{
+ display:inline-table;
+ width:470px;
}
#window p{
diff --git a/static/template.odt b/static/template.odt
new file mode 100644
index 000000000..d1d0515bf
--- /dev/null
+++ b/static/template.odt
Binary files differ