diff options
author | Étienne Loks <etienne.loks@peacefrogs.net> | 2013-12-02 14:51:09 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@peacefrogs.net> | 2013-12-02 14:59:06 +0100 |
commit | 6326867adb72dd9ded160769ef09e77b2e482784 (patch) | |
tree | e7c44902b0dc74675ae3dda5658fc29c14ec71ba /archaeological_files/views.py | |
parent | de9fbce423f780a02b73a9e943995b0b7efb0008 (diff) | |
download | Ishtar-6326867adb72dd9ded160769ef09e77b2e482784.tar.bz2 Ishtar-6326867adb72dd9ded160769ef09e77b2e482784.zip |
Manage document template
* ooo_replace: generate a document by mapping ooo variables with
a given dict
* DocumentTemplate model: store templates associated with a type
of objects
* get_values method: generate a dict of value from a model
* new form/view to generate document from administrativ acts
Diffstat (limited to 'archaeological_files/views.py')
-rw-r--r-- | archaeological_files/views.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/archaeological_files/views.py b/archaeological_files/views.py index 407bbe821..e55368e62 100644 --- a/archaeological_files/views.py +++ b/archaeological_files/views.py @@ -18,10 +18,12 @@ # See the file COPYING for details. import json +import os from django.db.models import Q from django.http import HttpResponse from django.shortcuts import render_to_response +from django.template.defaultfilters import slugify from django.utils.translation import ugettext_lazy as _ from ishtar_common.views import get_item, show_item, revert_item @@ -156,3 +158,29 @@ file_administrativeactfile_deletion_wizard = \ label=_(u"File: administrative act deletion"), url_name='file_administrativeactfile_deletion',) +def file_administrativeactfile_document(request): + dct = {} + if request.POST: + dct['search_form'] = AdministrativeActFileFormSelection(request.POST) + dct['template_form'] = DocumentGenerationAdminActForm(request.POST) + if dct['search_form'].is_valid() and dct['template_form'].is_valid(): + doc = dct['template_form'].save( + dct['search_form'].cleaned_data.get('pk')) + if doc: + MIMES = {'odt':'application/vnd.oasis.opendocument.text', + 'ods':'application/vnd.oasis.opendocument.spreadsheet'} + ext = doc.split('.')[-1] + doc_name = slugify(doc.split(os.path.sep)[-1][:-len(ext)])+ "."\ + + ext + mimetype = 'text/csv' + if ext in MIMES: + mimetype = MIMES[ext] + response = HttpResponse(open(doc), mimetype=mimetype) + response['Content-Disposition'] = 'attachment; filename=%s' % \ + doc_name + return response + else: + dct['search_form'] = AdministrativeActFileFormSelection() + dct['template_form'] = DocumentGenerationAdminActForm() + return render_to_response('ishtar/administrativeact_document.html', dct, + context_instance=RequestContext(request)) |