diff --git a/product/ERP5OOo/FormPrintout.py b/product/ERP5OOo/FormPrintout.py index b0e0d5c9e1b4e43a4376e309beefe0620965bf3b..37fa921d2f8d3040cf9e6936b1eee0df287baeff 100644 --- a/product/ERP5OOo/FormPrintout.py +++ b/product/ERP5OOo/FormPrintout.py @@ -40,6 +40,7 @@ from Products.ERP5Type.Globals import InitializeClass, DTMLFile, Persistent 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 @@ NSMAP = { # 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 @@ def addFormPrintout(self, id, title="", form_name='', template='', REQUEST=None) 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 @@ def add_and_edit(self, id, REQUEST): 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 @@ class FormPrintout(Implicit, Persistent, RoleManager, Item): 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 @@ class FormPrintout(Implicit, Persistent, RoleManager, Item): # default attributes template = None form_name = None + filename = 'object/title_or_id' - def __init__(self, id, title='', form_name='', template=''): + 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 @@ class FormPrintout(Implicit, Persistent, RoleManager, Item): 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 @@ class FormPrintout(Implicit, Persistent, RoleManager, Item): __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 @@ class FormPrintout(Implicit, Persistent, RoleManager, Item): """ 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 @@ class FormPrintout(Implicit, Persistent, RoleManager, Item): 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) diff --git a/product/ERP5OOo/tests/testFormPrintoutAsODT.py b/product/ERP5OOo/tests/testFormPrintoutAsODT.py index ed6d64a54e3dbb73c8a0c9a30be41c34d259b2a3..317e9a4da6a6e77dbc02dc0dcfaa129dda74ee3d 100644 --- a/product/ERP5OOo/tests/testFormPrintoutAsODT.py +++ b/product/ERP5OOo/tests/testFormPrintoutAsODT.py @@ -222,6 +222,15 @@ class TestFormPrintoutAsODT(TestFormPrintoutMixin): 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 diff --git a/product/ERP5OOo/www/FormPrintout_manageEdit.zpt b/product/ERP5OOo/www/FormPrintout_manageEdit.zpt index c670c36c51f8598fc0075182a5f95b735f0febbe..afba6e7be0f088c8535b6761b3e130b42c22da7c 100644 --- a/product/ERP5OOo/www/FormPrintout_manageEdit.zpt +++ b/product/ERP5OOo/www/FormPrintout_manageEdit.zpt @@ -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">