Commit 989644a4 authored by Jean-Paul Smets's avatar Jean-Paul Smets

Added constraint edition, cache reset, accessor reset


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@2049 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 29a8bc7c
############################################################################## ##############################################################################
# #
# Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved. # Copyright (c) 2002-2004 Nexedi SARL and Contributors. All Rights Reserved.
# Jean-Paul Smets-Solanes <jp@nexedi.com> # Jean-Paul Smets-Solanes <jp@nexedi.com>
# #
# WARNING: This program as such is intended to be used by professional # WARNING: This program as such is intended to be used by professional
...@@ -39,9 +39,16 @@ from Products.ERP5Type.Document.Folder import Folder ...@@ -39,9 +39,16 @@ from Products.ERP5Type.Document.Folder import Folder
from Products.ERP5Type.Utils import readLocalPropertySheet, writeLocalPropertySheet, getLocalPropertySheetList from Products.ERP5Type.Utils import readLocalPropertySheet, writeLocalPropertySheet, getLocalPropertySheetList
from Products.ERP5Type.Utils import readLocalExtension, writeLocalExtension, getLocalExtensionList from Products.ERP5Type.Utils import readLocalExtension, writeLocalExtension, getLocalExtensionList
from Products.ERP5Type.Utils import readLocalDocument, writeLocalDocument, getLocalDocumentList from Products.ERP5Type.Utils import readLocalDocument, writeLocalDocument, getLocalDocumentList
from Products.ERP5Type.Utils import readLocalConstraint, writeLocalConstraint, getLocalConstraintList
from Products.ERP5Type.InitGenerator import getProductDocumentPathList from Products.ERP5Type.InitGenerator import getProductDocumentPathList
class ClassTool(BaseTool): from Products.ERP5Type.Base import _aq_reset
from Products.ERP5Type import allowClassTool
if allowClassTool():
class ClassTool(BaseTool):
""" """
A tool to edit code through the web A tool to edit code through the web
""" """
...@@ -63,12 +70,17 @@ class ClassTool(BaseTool): ...@@ -63,12 +70,17 @@ class ClassTool(BaseTool):
,{ 'label' : 'PropertySheets' ,{ 'label' : 'PropertySheets'
, 'action' : 'manage_viewPropertySheetList' , 'action' : 'manage_viewPropertySheetList'
} }
,{ 'label' : 'Constraints'
, 'action' : 'manage_viewConstraintList'
}
,{ 'label' : 'Extensions' ,{ 'label' : 'Extensions'
, 'action' : 'manage_viewExtensionList' , 'action' : 'manage_viewExtensionList'
} }
, ,
) )
+ Folder.manage_options + tuple (
filter(lambda a: a['label'] not in ('Contents', 'View'),
Folder.manage_options))
) )
security.declareProtected( Permissions.ManagePortal, 'manage_overview' ) security.declareProtected( Permissions.ManagePortal, 'manage_overview' )
...@@ -83,15 +95,29 @@ class ClassTool(BaseTool): ...@@ -83,15 +95,29 @@ class ClassTool(BaseTool):
security.declareProtected( Permissions.ManagePortal, 'manage_viewExtensionList' ) security.declareProtected( Permissions.ManagePortal, 'manage_viewExtensionList' )
manage_viewExtensionList = DTMLFile( 'viewExtensionList', _dtmldir ) manage_viewExtensionList = DTMLFile( 'viewExtensionList', _dtmldir )
security.declareProtected( Permissions.ManagePortal, 'manage_viewConstraintList' )
manage_viewConstraintList = DTMLFile( 'viewConstraintList', _dtmldir )
security.declareProtected( Permissions.ManagePortal, 'manage_editDocumentForm' ) security.declareProtected( Permissions.ManagePortal, 'manage_editDocumentForm' )
manage_editDocumentForm = DTMLFile( 'editDocumentForm', _dtmldir ) manage_editDocumentForm = DTMLFile( 'editDocumentForm', _dtmldir )
security.declareProtected( Permissions.ManagePortal, 'manage_editExtensionForm' ) security.declareProtected( Permissions.ManagePortal, 'manage_editExtensionForm' )
manage_editExtensionForm = DTMLFile( 'editExtensionForm', _dtmldir ) manage_editExtensionForm = DTMLFile( 'editExtensionForm', _dtmldir )
security.declareProtected( Permissions.ManagePortal, 'manage_editConstraintForm' )
manage_editConstraintForm = DTMLFile( 'editConstraintForm', _dtmldir )
security.declareProtected( Permissions.ManagePortal, 'manage_editPropertySheetForm' ) security.declareProtected( Permissions.ManagePortal, 'manage_editPropertySheetForm' )
manage_editPropertySheetForm = DTMLFile( 'editPropertySheetForm', _dtmldir ) manage_editPropertySheetForm = DTMLFile( 'editPropertySheetForm', _dtmldir )
# Clears the cache of all databases
def _clearCache(self):
database = self.Control_Panel.Database
for name in database.getDatabaseNames():
from zLOG import LOG
LOG('_clearCache', 0, str(name))
database[name].manage_minimize()
security.declareProtected( Permissions.ManagePortal, 'getLocalPropertySheetList' ) security.declareProtected( Permissions.ManagePortal, 'getLocalPropertySheetList' )
def getLocalPropertySheetList(self): def getLocalPropertySheetList(self):
""" """
...@@ -106,6 +132,13 @@ class ClassTool(BaseTool): ...@@ -106,6 +132,13 @@ class ClassTool(BaseTool):
""" """
return getLocalExtensionList() return getLocalExtensionList()
security.declareProtected( Permissions.ManagePortal, 'getLocalConstraintList' )
def getLocalConstraintList(self):
"""
Return a list of Constraint id which can be modified through the web
"""
return getLocalConstraintList()
security.declareProtected( Permissions.ManagePortal, 'getLocalDocumentList' ) security.declareProtected( Permissions.ManagePortal, 'getLocalDocumentList' )
def getLocalDocumentList(self): def getLocalDocumentList(self):
""" """
...@@ -133,40 +166,40 @@ class ClassTool(BaseTool): ...@@ -133,40 +166,40 @@ class ClassTool(BaseTool):
Updates a Document with a new text Updates a Document with a new text
""" """
text = """ text = """
############################################################################## ##############################################################################
# #
# Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved. # Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved.
# #
# WARNING: This program as such is intended to be used by professional # WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential # programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs # consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial # End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software # garantees and support are strongly adviced to contract a Free Software
# Service Company # Service Company
# #
# This program is Free Software; you can redistribute it and/or # This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# #
############################################################################## ##############################################################################
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.CMFCore.utils import getToolByName from Products.CMFCore.utils import getToolByName
from Products.CMFCore.WorkflowCore import WorkflowMethod from Products.CMFCore.WorkflowCore import WorkflowMethod
from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface
from Products.ERP5Type.XMLObject import XMLObject from Products.ERP5Type.XMLObject import XMLObject
class %s(XMLObject): class %s(XMLObject):
# CMF Type Definition # CMF Type Definition
meta_type = 'MYPROJECT Template Document' meta_type = 'MYPROJECT Template Document'
portal_type = 'Template Document' portal_type = 'Template Document'
...@@ -193,7 +226,7 @@ class %s(XMLObject): ...@@ -193,7 +226,7 @@ class %s(XMLObject):
Updates a Document with a new text Updates a Document with a new text
""" """
previous_text = readLocalDocument(class_id) previous_text = readLocalDocument(class_id)
writeLocalDocument(class_id, text) writeLocalDocument(class_id, text, create=0)
if REQUEST is not None: if REQUEST is not None:
REQUEST.RESPONSE.redirect('%s/manage_editDocumentForm?class_id=%s&message=Document+Saved' % (self.absolute_url(), class_id)) REQUEST.RESPONSE.redirect('%s/manage_editDocumentForm?class_id=%s&message=Document+Saved' % (self.absolute_url(), class_id))
...@@ -206,6 +239,11 @@ class %s(XMLObject): ...@@ -206,6 +239,11 @@ class %s(XMLObject):
local_product = self.Control_Panel.Products.ERP5Type local_product = self.Control_Panel.Products.ERP5Type
app = local_product._p_jar.root()['Application'] app = local_product._p_jar.root()['Application']
importLocalDocument(class_id, document_path=class_path) importLocalDocument(class_id, document_path=class_path)
# Clear object cache and reset _aq_dynamic after reload
self._clearCache()
_aq_reset()
if REQUEST is not None and class_path is None: if REQUEST is not None and class_path is None:
REQUEST.RESPONSE.redirect('%s/manage_editDocumentForm?class_id=%s&message=Document+Reloaded+Successfully' % (self.absolute_url(), class_id)) REQUEST.RESPONSE.redirect('%s/manage_editDocumentForm?class_id=%s&message=Document+Reloaded+Successfully' % (self.absolute_url(), class_id))
...@@ -223,34 +261,34 @@ class %s(XMLObject): ...@@ -223,34 +261,34 @@ class %s(XMLObject):
Updates a PropertySheet with a new text Updates a PropertySheet with a new text
""" """
text = """ text = """
############################################################################## ##############################################################################
# #
# Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved. # Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved.
# #
# WARNING: This program as such is intended to be used by professional # WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential # programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs # consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial # End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software # garantees and support are strongly adviced to contract a Free Software
# Service Company # Service Company
# #
# This program is Free Software; you can redistribute it and/or # This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# #
############################################################################## ##############################################################################
class PropertySheetTemplate: class PropertySheetTemplate:
\"\"\" \"\"\"
PropertySheetTemplate properties for all ERP5 objects PropertySheetTemplate properties for all ERP5 objects
\"\"\" \"\"\"
...@@ -263,7 +301,7 @@ class PropertySheetTemplate: ...@@ -263,7 +301,7 @@ class PropertySheetTemplate:
) )
""" """
writeLocalPropertySheet(class_id, text) writeLocalPropertySheet(class_id, text)
if REQUEST is not None: if REQUEST is not None:
REQUEST.RESPONSE.redirect('%s/manage_editPropertySheetForm?class_id=%s&message=PropertySheet+Created' % (self.absolute_url(), class_id)) REQUEST.RESPONSE.redirect('%s/manage_editPropertySheetForm?class_id=%s&message=PropertySheet+Created' % (self.absolute_url(), class_id))
...@@ -274,7 +312,7 @@ class PropertySheetTemplate: ...@@ -274,7 +312,7 @@ class PropertySheetTemplate:
Updates a PropertySheet with a new text Updates a PropertySheet with a new text
""" """
previous_text = readLocalPropertySheet(class_id) previous_text = readLocalPropertySheet(class_id)
writeLocalPropertySheet(class_id, text) writeLocalPropertySheet(class_id, text, create=0)
if REQUEST is not None: if REQUEST is not None:
REQUEST.RESPONSE.redirect('%s/manage_editPropertySheetForm?class_id=%s&message=PropertySheet+Saved' % (self.absolute_url(), class_id)) REQUEST.RESPONSE.redirect('%s/manage_editPropertySheetForm?class_id=%s&message=PropertySheet+Saved' % (self.absolute_url(), class_id))
...@@ -287,6 +325,10 @@ class PropertySheetTemplate: ...@@ -287,6 +325,10 @@ class PropertySheetTemplate:
local_product = self.Control_Panel.Products.ERP5Type local_product = self.Control_Panel.Products.ERP5Type
app = local_product._p_jar.root()['Application'] app = local_product._p_jar.root()['Application']
importLocalPropertySheet(class_id) importLocalPropertySheet(class_id)
# Reset _aq_dynamic after reload
# There is no need to reset the cache in this case because
# XXX it is not sure however that class defined propertysheets will be updated
_aq_reset()
if REQUEST is not None: if REQUEST is not None:
REQUEST.RESPONSE.redirect('%s/manage_editPropertySheetForm?class_id=%s&message=PropertySheet+Reloaded+Successfully' % (self.absolute_url(), class_id)) REQUEST.RESPONSE.redirect('%s/manage_editPropertySheetForm?class_id=%s&message=PropertySheet+Reloaded+Successfully' % (self.absolute_url(), class_id))
...@@ -303,36 +345,36 @@ class PropertySheetTemplate: ...@@ -303,36 +345,36 @@ class PropertySheetTemplate:
Updates a Extension with a new text Updates a Extension with a new text
""" """
text = """ text = """
############################################################################## ##############################################################################
# #
# Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved. # Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved.
# #
# WARNING: This program as such is intended to be used by professional # WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential # programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs # consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial # End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software # garantees and support are strongly adviced to contract a Free Software
# Service Company # Service Company
# #
# This program is Free Software; you can redistribute it and/or # This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# #
############################################################################## ##############################################################################
def myExtensionMethod(context, param=None): def myExtensionMethod(self, param=None):
pass pass
""" """
writeLocalExtension(class_id, text) writeLocalExtension(class_id, text)
if REQUEST is not None: if REQUEST is not None:
REQUEST.RESPONSE.redirect('%s/manage_editExtensionForm?class_id=%s&message=Extension+Created' % (self.absolute_url(), class_id)) REQUEST.RESPONSE.redirect('%s/manage_editExtensionForm?class_id=%s&message=Extension+Created' % (self.absolute_url(), class_id))
...@@ -343,8 +385,98 @@ def myExtensionMethod(context, param=None): ...@@ -343,8 +385,98 @@ def myExtensionMethod(context, param=None):
Updates a Extension with a new text Updates a Extension with a new text
""" """
previous_text = readLocalExtension(class_id) previous_text = readLocalExtension(class_id)
writeLocalExtension(class_id, text) writeLocalExtension(class_id, text, create=0)
if REQUEST is not None: if REQUEST is not None:
REQUEST.RESPONSE.redirect('%s/manage_editExtensionForm?class_id=%s&message=Extension+Saved' % (self.absolute_url(), class_id)) REQUEST.RESPONSE.redirect('%s/manage_editExtensionForm?class_id=%s&message=Extension+Saved' % (self.absolute_url(), class_id))
security.declareProtected( Permissions.ManagePortal, 'getConstraintText' )
def getConstraintText(self, class_id):
"""
Updates a Constraint with a new text
"""
return readLocalConstraint(class_id)
security.declareProtected( Permissions.ManageExtensions, 'newConstraint' )
def newConstraint(self, class_id, REQUEST=None):
"""
Updates a Constraint with a new text
"""
text = """
##############################################################################
#
# Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved.
#
# 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 Products.ERP5Type.Constraint import Constraint
class ConstraintTemplate(Constraint):
\"\"\"
Explain here what this constraint checker does
\"\"\"
def checkConsistency(self, object, fixit = 0):
\"\"\"
Implement here the consistency checker
whenever fixit is not 0, object data should be updated to
satisfy the constraint
\"\"\"
errors = []
# Do the job here
return errors
"""
writeLocalConstraint(class_id, text)
if REQUEST is not None:
REQUEST.RESPONSE.redirect('%s/manage_editConstraintForm?class_id=%s&message=Constraint+Created' % (self.absolute_url(), class_id))
security.declareProtected( Permissions.ManageExtensions, 'editConstraint' )
def editConstraint(self, class_id, text, REQUEST=None):
"""
Updates a Constraint with a new text
"""
previous_text = readLocalConstraint(class_id)
writeLocalConstraint(class_id, text, create=0)
if REQUEST is not None:
REQUEST.RESPONSE.redirect('%s/manage_editConstraintForm?class_id=%s&message=Constraint+Saved' % (self.absolute_url(), class_id))
else:
class ClassTool(BaseTool):
"""
A tool to edit code through the web
"""
id = 'portal_classes'
meta_type = 'ERP5 Dummy Class Tool'
# Declarative Security
security = ClassSecurityInfo()
security.declareProtected( Permissions.ManagePortal, 'manage_overview' )
manage_overview = DTMLFile( 'explainDummyClassTool', _dtmldir )
InitializeClass(ClassTool) InitializeClass(ClassTool)
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment