Commit a22dae2f authored by Jean-Paul Smets's avatar Jean-Paul Smets

first version


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@52 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent f354836a
##############################################################################
#
# Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved.
# Jean-Paul Smets-Solane <jp@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 Globals import PersistentMapping
from Acquisition import Implicit
from AccessControl import ClassSecurityInfo
from Products.CMFCore.utils import getToolByName
from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface
from Products.ERP5Type.XMLObject import XMLObject
import cStringIO
from zLOG import LOG
class ObjectTemplateItem(Implicit):
export_string = None
def __init__(self, ob, **kw):
self.__dict__.update(kw)
self.export_string = cStringIO.StringIO()
ob._p_jar.exportFile(ob._p_oid, self.export_string)
self.export_string = self.export_string.read()
def install(self, portal):
folder._importObjectFromFile(cStringIO.StringIO(self.export_string))
class ActionTemplateItem(Implicit):
export_string = None
def __init__(self, ai, **kw):
self.__dict__.update(kw)
self.id = id
self.title = ai.title
self.description = ai.description
self.category = ai.category
self.condition = ai.condition
self.permissions = ai.permissions
self.priority = ai.priority
self.visible = ai.visible
self.expression = ai.getActionExpression()
def install(self, portal):
folder._importObjectFromFile(cStringIO.StringIO(self.export_string))
class PropertyTemplateItem(Implicit):
export_string = None
def __init__(self, pi, **kw):
self.__dict__.update(kw)
self.property_definition = pi.copy()
def install(self, portal):
folder._importObjectFromFile(cStringIO.StringIO(self.export_string))
class BusinessTemplate(XMLObject):
"""
A business template allows to construct ERP5 modules
in part or completely. It may include:
- dependency
- conflicts
- catalog definition ( -> formal definition + sql files )
- SQL methods including:
- purpose (catalog, uncatalog, etc.)
- filter definition
- Mapping definition
- id (ex. getTitle)
- column_id (ex. title)
- indexed
- preferred table (ex. catalog)
- portal_types definition ( -> zexp/xml file)
- id
- actions
- module definition ( -> zexp/xml file)
- id
- relative_url
- menus
- roles/security
- workflow definitions ( -> zexp/xml file)
- workflow_id
- XML/XMI definition
- relevant portal_types
- tool definition ( -> formal definition)
- categories definition
Each definition should be usable in both import and update mode.
Technology:
- download a zip file (from the web, from a CVS repository)
- install files to the right location (publish / update) (in the ZODB)
- PUBLISH: publish method allows to publish an application (and share code)
publication in a CVS repository allows to develop
THIS IS THE MOST IMPORTANT CONCEPT
Use case:
- install core ERP5 (the minimum)
- go to "BT" menu. Refresh list. Select BT. Click register.
- go to "BT" menu. Select register BT. Define params. Click install / update.
- go to "BT" menu. Create new BT. Define BT elements (workflow, methods, attributes, etc.). Click publish. Provide URL.
Done.
"""
meta_type = 'ERP5 Business Template'
portal_type = 'Business Template'
add_permission = Permissions.AddERP5Content
isPortalContent = 1
isRADContent = 1
# Declarative security
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.View)
# Declarative interfaces
__implements__ = ( Interface.Variated, )
# Declarative properties
property_sheets = ( PropertySheet.Base
, PropertySheet.XMLObject
, PropertySheet.CategoryCore
, PropertySheet.BusinessTemplate
)
# Factory Type Information
factory_type_information = \
{ 'id' : portal_type
, 'meta_type' : meta_type
, 'description' : """\
Une ligne tarifaire."""
, 'icon' : 'order_line_icon.gif'
, 'product' : 'ERP5'
, 'factory' : 'addBusinessTemplate'
, 'immediate_view' : 'BusinessTemplate_view'
, 'allow_discussion' : 1
, 'allowed_content_types': ('BusinessTemplate',
)
, 'filter_content_types' : 1
, 'global_allow' : 1
, 'actions' :
( { 'id' : 'view'
, 'name' : 'View'
, 'category' : 'object_view'
, 'action' : 'BusinessTemplate_view'
, 'permissions' : (
Permissions.View, )
}
, { 'id' : 'list'
, 'name' : 'Object Contents'
, 'category' : 'object_action'
, 'action' : 'folder_contents'
, 'permissions' : (
Permissions.View, )
}
, { 'id' : 'print'
, 'name' : 'Print'
, 'category' : 'object_print'
, 'action' : 'BusinessTemplate_print'
, 'permissions' : (
Permissions.View, )
}
, { 'id' : 'metadata'
, 'name' : 'Metadata'
, 'category' : 'object_view'
, 'action' : 'metadata_view'
, 'permissions' : (
Permissions.View, )
}
, { 'id' : 'translate'
, 'name' : 'Translate'
, 'category' : 'object_action'
, 'action' : 'translation_template_view'
, 'permissions' : (
Permissions.TranslateContent, )
}
)
}
def initInstance(self):
if not hasattr(self, 'object_archive'):
self.object_archive = PersistentMapping()
if not hasattr(self, 'action_archive'):
self.action_archive = PersistentMapping()
if not hasattr(self, 'property_archive'):
self.property_archive = PersistentMapping()
def addObjectTemplateItem(self, relative_url_or_id, tool_id=None):
p = self.getPortalObject()
if tool_id is not None:
relative_url = "%s/%s" % (tool_id, relative_url_or_id)
object = p.unrestrictedTraverse(relative_url)
if object is not None:
self.object_archive[(relative_url_or_id, tool_id)] = ObjectTemplateItem(object,
id = object.id,
tool_id=tool_id,
relative_url=relative_url,
relative_url_or_id=relative_url_or_id)
def splitPath(self, path):
# Add error checking here
relative_url = path[0:path.find('[')]
id_block = path[path.find('[')+1:path.find(']')]
key = path.split('=')[0]
value = path.split('=')[2]
return relative_url, key, value
def addActionTemplateItem(self, path):
relative_url, key, value = self.splitPath(path)
p = self.getPortalObject()
object = p.unrestrictedTraverse(relative_url)
for ai in object.listActions(): # Replace this with some kind of regexp
if getattr(ai, key) == value:
self.action_archive[path] = ActionTemplateItem(ai,
id = key,
relative_url = relative_url,
path = path)
def addSitePropertyTemplateItem(self, path):
relative_url, key, value = self.splitPath(path)
p = self.getPortalObject()
object = p.unrestrictedTraverse(relative_url)
for pi in object.propertyMap():
if getattr(pi, key) == value: # Replace this with some kind of regexp
self.property_archive[path] = PropertyTemplateItem(pi,
id = key,
value = object.getProperty(key),
relative_url = relative_url,
path = path)
def build(self):
"""
Copy existing portal objects to self
"""
self.initInstance()
# Copy portal_types
for id in self.getTemplatePortalTypeIdList():
self.addObjectTemplateItem(id, 'portal_types')
# Copy workflows
for id in self.getTemplateWorkflowIdList():
self.addObjectTemplateItem(id, 'portal_workflow')
# Copy skins
for id in self.getTemplateSkinIdList():
self.addObjectTemplateItem(id, 'portal_skins')
# Copy categories
for id in self.getTemplateBaseCategoryIdList():
self.addObjectTemplateItem(id, 'portal_categories')
# Copy catalog methods
for id in self.getTemplateCatalogMethodIdList():
self.addObjectTemplateItem(id, 'portal_catalog')
# Copy actions
for id in self.getTemplateActionPathList():
self.addActionTemplateItem(path)
# Copy properties
for id in self.getTemplateSitePropertyIdList():
self.addSitePropertyTemplateItem(id)
def publish(self, format='web'):
"""
Publish in a format or another
"""
def upgrade(self):
"""
Upgrade template
"""
def update(self):
"""
Update the current portal with this template definition
"""
# call local update
def install(self, **kw):
"""
For install based on paramaters provided in **kw
"""
# call local install
def installRoles(self, update=1):
"""
C
"""
p.__ac_roles__ = ('Member', 'Reviewer',)
def installPermissions(self, update=1):
"""
C
"""
mp = p.manage_permission
mp('Set own password', ['Member','Manager',], 1)
def installSkins(self, update=1):
from Products.CMFCore.DirectoryView import addDirectoryViews
ps = getToolByName(p, 'portal_skins')
addDirectoryViews(ps, 'skins', globals())
addDirectoryViews(ps, 'skins', topic_globals)
ps.manage_addProduct['OFSP'].manage_addFolder(id='custom')
ps.addSkinSelection('Basic',
'custom, zpt_topic, zpt_content, zpt_generic,'
+ 'zpt_control, topic, content, generic, control, Images',
make_default=1)
ps.addSkinSelection('Nouvelle',
'nouvelle, custom, topic, content, generic, control, Images')
ps.addSkinSelection('No CSS',
'no_css, custom, topic, content, generic, control, Images')
p.setupCurrentSkin()
def installPortalTypes(self, update=1):
"""
C
"""
def installWorklow(self, update=1):
"""
C
"""
def installProperties(self, update=1):
"""
C
"""
##############################################################################
#
# Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved.
# Jean-Paul Smets-Solane <jp@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.
#
##############################################################################
class BusinessTemplate:
"""
Organisation properties and categories
"""
_properties = (
{ 'id' : 'template_portal_type_id',
'description' : 'A list of ids of portal types used by this module',
'type' : 'lines',
'mode' : 'w',
'default' : () },
{ 'id' : 'template_module_id',
'description' : 'A list of ids of modules used by this module',
'type' : 'lines',
'mode' : 'w',
'default' : () },
{ 'id' : 'template_skin_id',
'description' : 'A list of ids of skins used by this module',
'type' : 'lines',
'mode' : 'w',
'default' : () },
{ 'id' : 'template_workflow_id',
'description' : 'A list of ids of skins used by this module',
'type' : 'lines',
'mode' : 'w',
'default' : () },
{ 'id' : 'template_document_id',
'description' : 'A list of ids of skins used by this module',
'type' : 'lines',
'mode' : 'w',
'default' : () },
{ 'id' : 'template_propertysheet_id',
'description' : 'A list of ids of skins used by this module',
'type' : 'lines',
'mode' : 'w',
'default' : () },
{ 'id' : 'template_role',
'description' : 'A list of ids of skins used by this module',
'type' : 'lines',
'mode' : 'w',
'default' : () },
{ 'id' : 'template_catalog_method_id',
'description' : 'A list of ids of skins used by this module',
'type' : 'lines',
'mode' : 'w',
'default' : () },
{ 'id' : 'template_catalog_column_id',
'description' : 'A list of ids of skins used by this module',
'type' : 'lines',
'mode' : 'w',
'default' : () },
{ 'id' : 'template_catalog_result_table',
'description' : 'A list of ids of skins used by this module',
'type' : 'lines',
'mode' : 'w',
'default' : () },
{ 'id' : 'template_site_property_id',
'description' : 'A list of ids of skins used by this module',
'type' : 'lines',
'mode' : 'w',
'default' : () },
{ 'id' : 'template_base_category_id',
'description' : 'A list of ids of skins used by this module',
'type' : 'lines',
'mode' : 'w',
'default' : () },
{ 'id' : 'template_action_path',
'description' : 'A list of ids of skins used by this module',
'type' : 'lines',
'mode' : 'w',
'default' : () },
{ 'id' : 'object_path',
'description' : 'A list of ids of skins used by this module',
'type' : 'lines',
'mode' : 'w',
'default' : () },
)
_categories = ( )
##############################################################################
#
# Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved.
# Jean-Paul Smets-Solane <jp@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 Products.CMFCore.utils import UniqueObject
from AccessControl import ClassSecurityInfo
from Globals import InitializeClass, DTMLFile
from Products.ERP5Type.Document.Folder import Folder
from Products.ERP5Type import Permissions
from Products.ERP5 import _dtmldir
from zLOG import LOG
class TemplateTool (UniqueObject, Folder):
"""
The RulesTool implements portal object
transformation policies.
An object transformation template is defined by
a domain and a transformation pattent:
The domain is defined as:
- the meta_type it applies to
- the portal_type it applies to
- the conditions of application (category membership, value range,
security, function, etc.)
The transformation template is defined as:
- a tree of portal_types starting on the object itself
- default values for each node of the tree, incl. the root itself
When a transformation is triggered, it will check the existence of
each node and eventually update values
Transformations are very similar to XSLT in the XML world.
Examples of applications:
- generate accounting movements from a stock movement
- generate a birthday event from a person
ERP5 main application : generate submovements from movements
according to templates. Allows to parametrize modules
such as payroll.
Try to mimic: XSL semantics
Status : OK
NEW NAME : Rules Tool
"""
id = 'portal_templates'
meta_type = 'ERP5 Template Tool'
allowed_types = ( 'ERP5 Business Template',)
# Declarative Security
security = ClassSecurityInfo()
#
# ZMI methods
#
manage_options = ( ( { 'label' : 'Overview'
, 'action' : 'manage_overview'
}
,
)
+ Folder.manage_options
)
security.declareProtected( Permissions.ManagePortal, 'manage_overview' )
manage_overview = DTMLFile( 'explainRuleTool', _dtmldir )
# Filter content (ZMI))
def __init__(self):
return Folder.__init__(self, TemplateTool.id)
# Filter content (ZMI))
def filtered_meta_types(self, user=None):
# Filters the list of available meta types.
all = TemplateTool.inheritedAttribute('filtered_meta_types')(self)
meta_types = []
for meta_type in self.all_meta_types():
if meta_type['name'] in self.allowed_types:
meta_types.append(meta_type)
return meta_types
def importDocumentClass(self, path):
"""
Imports a document class
"""
import imp
from Products.ERP5Type.Utils import importLocalDocumentClass
local_product = self.Control_Panel.Products.ERP5
app = local_product._p_jar.root()['Application']
importLocalDocumentClass('Test')
#__import__('Document.Test')
InitializeClass(TemplateTool)
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