From 7e47f58029315fee2140275cbd146dfcef631519 Mon Sep 17 00:00:00 2001 From: Sebastien Robin <seb@nexedi.com> Date: Tue, 24 Aug 2010 07:44:53 +0000 Subject: [PATCH] create new ERP5 class PythonScript. Add a constructor specific for the ZMI, this specific constructor can be safely removed later. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@37965 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5/Document/PythonScript.py | 100 ++++++++++++++++++ product/ERP5/PropertySheet/PythonScript.py | 46 ++++++++ .../PropertySheet/SubversionPreference.py | 5 + product/ERP5/Tool/TemplateTool.py | 10 +- product/ERP5/__init__.py | 2 + .../ERP5/dtml/addPythonScriptThroughZMI.dtml | 51 +++++++++ 6 files changed, 211 insertions(+), 3 deletions(-) create mode 100644 product/ERP5/Document/PythonScript.py create mode 100644 product/ERP5/PropertySheet/PythonScript.py create mode 100644 product/ERP5/dtml/addPythonScriptThroughZMI.dtml diff --git a/product/ERP5/Document/PythonScript.py b/product/ERP5/Document/PythonScript.py new file mode 100644 index 0000000000..93b3a4e4fc --- /dev/null +++ b/product/ERP5/Document/PythonScript.py @@ -0,0 +1,100 @@ +############################################################################## +# +# Copyright (c) 2010 Nexedi SARL and Contributors. All Rights Reserved. +# Sebastien Robin <seb@nexedi.com> +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsability of assessing all potential +# consequences resulting from its eventual inadequacies and bugs +# End users who are looking for a ready-to-use solution with commercial +# garantees and support are strongly adviced to contract a Free Software +# Service Company +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +############################################################################## + +from AccessControl import ClassSecurityInfo + +from Products.ERP5Type import Permissions, PropertySheet +from App.special_dtml import HTMLFile +from Products.ERP5Type.XMLObject import XMLObject +from Products.ERP5.Document.Ticket import Ticket +from Products.PythonScripts.PythonScript import \ + PythonScript as ZopePythonScript + +# Only needed until skin tool is migrated +manage_addPythonScriptFormThroughZMI = \ + HTMLFile("../dtml/addPythonScriptThroughZMI", globals()) +def addPythonScriptThroughZMI(self, id, title="", REQUEST=None): + """Add a Python script to a folder. + """ + from Products.ERP5Type.Document import addPythonScript + type_info = self.getPortalObject().portal_types.getTypeInfo("Python Script") + type_info.constructInstance( + container=self, + id=id) + if REQUEST is not None: + try: u = self.DestinationURL() + except: u = REQUEST['URL1'] + REQUEST.RESPONSE.redirect(u+'/manage_main') + +class PythonScriptThroughZMI(XMLObject): + """ + Dummy class only used to do construction through zmi of PythonScript + + This class needs to be removed as soon as portal_skins is an ERP5 object + """ + meta_type = 'ERP5 Python Script Through ZMI' + portal_type = 'Python Script Through ZMI' + add_permission = Permissions.AddPortalContent + + # Declarative security + security = ClassSecurityInfo() + security.declareObjectProtected(Permissions.AccessContentsInformation) + + constructors = (manage_addPythonScriptFormThroughZMI, + addPythonScriptThroughZMI) + icon = None + +class PythonScript(XMLObject, ZopePythonScript): + """ Script python for ERP5 + """ + + meta_type = 'ERP5 Python Script' + portal_type = 'Python Script' + add_permission = Permissions.AddPortalContent + + # Declarative security + security = ClassSecurityInfo() + security.declareObjectProtected(Permissions.AccessContentsInformation) + + # Declarative properties + property_sheets = ( PropertySheet.Base + , PropertySheet.XMLObject + , PropertySheet.CategoryCore + , PropertySheet.DublinCore + ) + + def _setBody(self, value): + """ + override to call ZopePythonScript methods to initialize code + """ + self.write(value) + + __call__ = ZopePythonScript.__call__ + + def edit(self, **kw): + XMLObject.edit(self, **kw) diff --git a/product/ERP5/PropertySheet/PythonScript.py b/product/ERP5/PropertySheet/PythonScript.py new file mode 100644 index 0000000000..f73dd6149c --- /dev/null +++ b/product/ERP5/PropertySheet/PythonScript.py @@ -0,0 +1,46 @@ +############################################################################## +# +# Copyright (c) 2002-2010 Nexedi SA and Contributors. All Rights Reserved. +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsibility of assessing all potential +# consequences resulting from its eventual inadequacies and bugs +# End users who are looking for a ready-to-use solution with commercial +# guarantees and support are strongly adviced to contract a Free Software +# Service Company +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +############################################################################## + +class PythonScript: + """ + PythonScript properties for all ERP5 objects + """ + + _properties = ( + { 'id' : 'body', + 'description' : 'A local property description', + 'type' : 'string', + 'storage_id' : '_body', + 'mode' : '' }, + { 'id' : 'parameter_signature', + 'description' : 'A local property description', + 'type' : 'string', + 'storage_id' : '_params', + 'mode' : '' }, + ) + + diff --git a/product/ERP5/PropertySheet/SubversionPreference.py b/product/ERP5/PropertySheet/SubversionPreference.py index 51387de06f..07eed5255d 100644 --- a/product/ERP5/PropertySheet/SubversionPreference.py +++ b/product/ERP5/PropertySheet/SubversionPreference.py @@ -42,4 +42,9 @@ class SubversionPreference: 'type' : 'lines', 'preference' : 1, 'mode' : 'w' }, + { 'id' : 'preferred_diff_filter_script_id', + 'description' : 'Scripts to filter what is displayed in diffs ', + 'type' : 'lines', + 'preference' : 1, + 'mode' : 'w' }, ) diff --git a/product/ERP5/Tool/TemplateTool.py b/product/ERP5/Tool/TemplateTool.py index c6c4ec85fe..37addfbad0 100644 --- a/product/ERP5/Tool/TemplateTool.py +++ b/product/ERP5/Tool/TemplateTool.py @@ -626,9 +626,13 @@ class TemplateTool (BaseTool): """ Return list of scripts usable to filter diff """ - # XXX-Aurel : this will be removed in a near future when script - # will be configurable on the tool - return [getattr(self, 'TemplateTool_filterTupleDiff'),] + # XXX, the or [] should not be there, the preference tool is + # inconsistent, the called method should not return None when + # nothing is selected + script_id_list = self.getPortalObject().portal_preferences\ + .getPreferredDiffFilterScriptIdList() or [] + + return [getattr(self, x) for x in script_id_list] def getFilteredDiffAsHTML(self, diff): """ diff --git a/product/ERP5/__init__.py b/product/ERP5/__init__.py index 2f1cb7583b..5a4509b979 100644 --- a/product/ERP5/__init__.py +++ b/product/ERP5/__init__.py @@ -52,7 +52,9 @@ from Tool import CategoryTool, SimulationTool, RuleTool, IdTool, TemplateTool,\ AcknowledgementTool, SolverTool, SolverProcessTool,\ ConversionTool, RoundingTool import ERP5Site +from Document import PythonScript object_classes = ( ERP5Site.ERP5Site, + PythonScript.PythonScriptThroughZMI, ) portal_tools = ( CategoryTool.CategoryTool, SimulationTool.SimulationTool, diff --git a/product/ERP5/dtml/addPythonScriptThroughZMI.dtml b/product/ERP5/dtml/addPythonScriptThroughZMI.dtml new file mode 100644 index 0000000000..257ad6c826 --- /dev/null +++ b/product/ERP5/dtml/addPythonScriptThroughZMI.dtml @@ -0,0 +1,51 @@ +<dtml-var manage_page_header> + +<dtml-var "manage_form_title(this(), _, + form_title='Add ERP5 Formulator Form', + )"> + +<p class="form-help"> +Formulator Forms allow you to create solid web forms more easily. +</p> + +<form action="addPythonScriptThroughZMI" method="POST"> + +<table cellspacing="0" cellpadding="2" border="0"> + <tr> + <td align="left" valign="top"> + <div class="form-label"> + Id + </div> + </td> + <td align="left" valign="top"> + <input type="text" name="id" size="40" /> + </td> + </tr> + + <tr> + <td align="left" valign="top"> + <div class="form-label"> + Title + </div> + </td> + <td align="left" valign="top"> + <input type="text" name="title" size="40" /> + </td> + </tr> + + <tr> + <td align="left" valign="top"> + </td> + <td align="left" valign="top"> + <div class="form-element"> + <input class="form-element" type="submit" name="submit" + value=" Add " /> + <input class="form-element" type="submit" name="submit" + value=" Add and Edit " /> + </div> + </td> + </tr> +</table> +</form> + +<dtml-var manage_page_footer> -- 2.30.9