[Erp5-report] r32418 nicolas - in /erp5/trunk/products/ERP5OOo: ./ tests/ www/
nobody at svn.erp5.org
nobody at svn.erp5.org
Wed Feb 10 17:32:52 CET 2010
Author: nicolas
Date: Wed Feb 10 17:32:52 2010
New Revision: 32418
URL: http://svn.erp5.org?rev=32418&view=rev
Log:
Add filename property (Tales) on FormPrintout
in order to customise filename of downloadable file.
Modified:
erp5/trunk/products/ERP5OOo/FormPrintout.py
erp5/trunk/products/ERP5OOo/tests/testFormPrintoutAsODT.py
erp5/trunk/products/ERP5OOo/www/FormPrintout_manageEdit.zpt
Modified: erp5/trunk/products/ERP5OOo/FormPrintout.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5OOo/FormPrintout.py?rev=32418&r1=32417&r2=32418&view=diff
==============================================================================
--- erp5/trunk/products/ERP5OOo/FormPrintout.py [utf8] (original)
+++ erp5/trunk/products/ERP5OOo/FormPrintout.py [utf8] Wed Feb 10 17:32:52 2010
@@ -40,6 +40,7 @@
from AccessControl import ClassSecurityInfo
from AccessControl.Role import RoleManager
from OFS.SimpleItem import Item
+from OFS.PropertyManager import PropertyManager
from urllib import quote, quote_plus
from copy import deepcopy
from lxml import etree
@@ -76,7 +77,8 @@
# Constructors
manage_addFormPrintout = DTMLFile("dtml/FormPrintout_add", globals())
-def addFormPrintout(self, id, title="", form_name='', template='', REQUEST=None):
+def addFormPrintout(self, id, title="", form_name='', template='',
+ REQUEST=None, filename='object/title_or_id'):
"""Add form printout to folder.
Keyword arguments:
@@ -86,7 +88,7 @@
template -- the name of a template which describes printout layout
"""
# add actual object
- id = self._setObject(id, FormPrintout(id, title, form_name, template))
+ id = self._setObject(id, FormPrintout(id, title, form_name, template, filename))
# respond to the add_and_edit button if necessary
add_and_edit(self, id, REQUEST)
return ''
@@ -108,7 +110,7 @@
u = "%s/%s" % (u, quote(id))
REQUEST.RESPONSE.redirect(u+'/manage_main')
-class FormPrintout(Implicit, Persistent, RoleManager, Item):
+class FormPrintout(Implicit, Persistent, RoleManager, Item, PropertyManager):
"""Form Printout
FormPrintout is one of a reporting system in ERP5.
@@ -137,6 +139,15 @@
property_sheets = ( PropertySheet.Base
, PropertySheet.SimpleItem)
+ _properties = ( {'id': 'template',
+ 'type': 'string',
+ 'mode': 'w'},
+ {'id': 'form_name',
+ 'type': 'string',
+ 'mode': 'w'},
+ {'id': 'filename',
+ 'type': 'tales',
+ 'mode': 'w',},)
# Constructors
constructors = (manage_addFormPrintout, addFormPrintout)
@@ -157,8 +168,10 @@
# default attributes
template = None
form_name = None
-
- def __init__(self, id, title='', form_name='', template=''):
+ filename = 'object/title_or_id'
+
+ def __init__(self, id, title='', form_name='', template='',
+ filename='object/title_or_id'):
"""Initialize id, title, form_name, template.
Keyword arguments:
@@ -166,11 +179,14 @@
title -- the title of a form printout
form_name -- the name of a form which as a document content
template -- the name of a template which as a document layout
+ filename -- Tales expression which return the filename of
+ downloadable file.
"""
self.id = id
self.title = title
self.form_name = form_name
self.template = template
+ self.filename = filename
security.declareProtected('View', 'index_html')
def index_html(self, REQUEST, RESPONSE=None, format=None, batch_mode=False):
@@ -213,13 +229,14 @@
__call__ = index_html
security.declareProtected('Manage properties', 'doSettings')
- def doSettings(self, REQUEST, title='', form_name='', template=''):
- """Change title, form_name, template."""
+ def doSettings(self, REQUEST, title='', form_name='', template='', filename='object/title_or_id'):
+ """Change title, form_name, template, filename."""
if SUPPORTS_WEBDAV_LOCKS and self.wl_isLocked():
raise ResourceLockedError, "File is locked via WebDAV"
self.form_name = form_name
self.template = template
self.title = title
+ self.filename = filename
message = "Saved changes."
if getattr(self, '_v_warnings', None):
message = ("<strong>Warning:</strong> <i>%s</i>"
@@ -248,11 +265,13 @@
"""
if REQUEST is not None and not format:
format = REQUEST.get('format', None)
+ filename = self.getProperty('filename')
if not format:
if REQUEST is not None and not batch_mode:
REQUEST.RESPONSE.setHeader('Content-Type','%s' % content_type)
REQUEST.RESPONSE.setHeader('Content-disposition',
- 'inline;filename="%s%s"' % (self.title_or_id(), guess_extension(content_type)))
+ 'inline;filename="%s%s"' % \
+ (filename, guess_extension(content_type) or ''))
return printout
from Products.ERP5Type.Document import newTempOOoDocument
tmp_ooo = newTempOOoDocument(self, self.title_or_id())
@@ -265,7 +284,7 @@
if REQUEST is not None and not batch_mode:
REQUEST.RESPONSE.setHeader('Content-type', mime)
REQUEST.RESPONSE.setHeader('Content-disposition',
- 'attachment;filename="%s.%s"' % (self.title_or_id(), format))
+ 'attachment;filename="%s.%s"' % (filename, format))
return data
InitializeClass(FormPrintout)
Modified: erp5/trunk/products/ERP5OOo/tests/testFormPrintoutAsODT.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5OOo/tests/testFormPrintoutAsODT.py?rev=32418&r1=32417&r2=32418&view=diff
==============================================================================
--- erp5/trunk/products/ERP5OOo/tests/testFormPrintoutAsODT.py [utf8] (original)
+++ erp5/trunk/products/ERP5OOo/tests/testFormPrintoutAsODT.py [utf8] Wed Feb 10 17:32:52 2010
@@ -222,6 +222,15 @@
self.assertTrue(content_xml.find("Français test2") > 0)
self._validate(odf_document)
+ # 7. Change Filename of downloadable file
+ reference = 'My Reference'
+ test1.setReference(reference)
+ foo_printout.filename = 'here/getReference'
+ odf_document = foo_printout(self.portal.REQUEST)
+ self.assertEqual(request.RESPONSE.getHeader('content-disposition'),
+ 'inline;filename="%s.odt"' % reference)
+ test1.setReference(None)
+
def test_01_Paragraph_07_LinesField(self):
"""test LinesField into multi line"""
foo_printout = self.portal.foo_module.test1.Foo_viewAsPrintout
Modified: erp5/trunk/products/ERP5OOo/www/FormPrintout_manageEdit.zpt
URL: http://svn.erp5.org/erp5/trunk/products/ERP5OOo/www/FormPrintout_manageEdit.zpt?rev=32418&r1=32417&r2=32418&view=diff
==============================================================================
--- erp5/trunk/products/ERP5OOo/www/FormPrintout_manageEdit.zpt [utf8] (original)
+++ erp5/trunk/products/ERP5OOo/www/FormPrintout_manageEdit.zpt [utf8] Wed Feb 10 17:32:52 2010
@@ -20,6 +20,11 @@
<td><input name="template" value="default_template" type="text" size="20"
tal:attributes="value request/template | here/template | nothing"/></td>
</tr>
+ <tr>
+ <td class="form-label">Filename</td>
+ <td><input name="filename" value="default_filename" type="text" size="20"
+ tal:attributes="value request/filename | here/filename | nothing"/></td>
+ </tr>
<tr>
<td align="left" valign="top" colspan="2">
More information about the Erp5-report
mailing list