Commit 3d26378e authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

* add PropertyRecordable property sheet.

* add PropertyRecordableMixin.
* use them in Simulation Movement.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@30474 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 80c1103d
......@@ -43,6 +43,7 @@ from Acquisition import aq_base
from Products.ERP5.Document.AppliedRule import TREE_DELIVERED_CACHE_KEY, TREE_DELIVERED_CACHE_ENABLED
from Products.ERP5Type.patches.WorkflowTool import WorkflowHistoryList
from Products.ERP5.mixin.property_recordable import PropertyRecordableMixin
# XXX Do we need to create groups ? (ie. confirm group include confirmed, getting_ready and ready
......@@ -61,7 +62,7 @@ parent_to_movement_simulation_state = {
'invoiced' : 'planned',
}
class SimulationMovement(Movement):
class SimulationMovement(Movement, PropertyRecordableMixin):
"""
Simulation movements belong to a simulation workflow which includes
the following steps
......@@ -103,9 +104,6 @@ class SimulationMovement(Movement):
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
# Declarative interfaces
zope.interface.implements(interfaces.IPropertyRecordable,)
# Declarative properties
property_sheets = ( PropertySheet.Base
, PropertySheet.SimpleItem
......@@ -120,6 +118,7 @@ class SimulationMovement(Movement):
, PropertySheet.AppliedRule
, PropertySheet.ItemAggregation
, PropertySheet.Reference
, PropertySheet.PropertyRecordable
)
def tpValues(self) :
......
#############################################################################
#
# Copyright (c) 2009 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 PropertyRecordable:
"""
Properties for property recordable documents
"""
_properties = (
{'id' :'recorded_property_dict',
'description':'The dict of recorded properties.',
'type' :'data',
'mode' :'w'
},
)
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2009 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.
#
##############################################################################
import zope.interface
from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, interfaces
class PropertyRecordableMixin:
"""
This class provides a generic implementation of IPropertyRecordable.
IPropertyRecordable provides methods to record
existing properties of a document and later retrieve
them. It is used by simulation to record forced
properties on simulation movements, but could be used
for other purpose.
TODO:
- extend interface to support time (getRecordedPropertyList)
"""
# Declarative security
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
# Declarative interfaces
zope.interface.implements(interfaces.IPropertyRecordable,)
security.declareProtected(Permissions.ModifyPortalContent, 'recordProperty')
def recordProperty(self, id):
"""
Records the current value of a property.
id -- ID of the property
"""
recorded_property_dict = self.getRecordedPropertyDict({})
# XXX it is better to use getPropertyList only for list type
# properties or categories.
recorded_property_dict[id] = self.getPropertyList(id)
self.setRecordedPropertyDict(recorded_property_dict)
security.declareProtected(Permissions.ModifyPortalContent,
'clearRecordedProperty')
def clearRecordedProperty(self, id):
"""
Clears a previously recorded property from
the property record.
"""
recorded_property_dict = self.getRecordedPropertyDict({})
try:
del(recorded_property_dict[id])
except KeyError:
pass
else:
self.setRecordedPropertyDict(recorded_property_dict)
security.declareProtected(Permissions.AccessContentsInformation,
'getRecordedPropertyIdList')
def getRecordedPropertyIdList(self):
"""
Returns the list of property IDs which have
been recorded.
"""
return (self.getRecordedPropertyDict({}).keys())
security.declareProtected(Permissions.AccessContentsInformation,
'isPropertyRecorded')
def isPropertyRecorded(self, id):
"""
Returns True if property with given ID has been
previously recorded, False else.
id -- ID of the property
"""
return self.getRecordedPropertyDict({}).has_key(id)
security.declareProtected(Permissions.AccessContentsInformation,
'getRecordedProperty')
def getRecordedProperty(self, id):
"""
Returns recorded value of property with given ID
id -- ID of the property
"""
return self.getRecordedPropertyDict({})[id]
security.declareProtected(Permissions.AccessContentsInformation,
'asRecordedContext')
def asRecordedContext(self):
"""
Returns current document as a temp document
which recorded properties in its context.
"""
context = self.asContext()
context.edit(**self.getRecordedPropertyDict({}))
return context
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