Commit ee4588fd authored by wenjie.zheng's avatar wenjie.zheng

Variable.py: add attributes and fonctions in class Variable.

parent 96b7845c
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.XMLObject import XMLObject from Products.ERP5Type.XMLObject import XMLObject
from Products.DCWorkflow.Guard import Guard
from Products.CMFCore.Expression import Expression
class Variable(XMLObject): class Variable(XMLObject):
""" """
...@@ -41,6 +43,15 @@ class Variable(XMLObject): ...@@ -41,6 +43,15 @@ class Variable(XMLObject):
isPortalContent = 1 isPortalContent = 1
isRADContent = 1 isRADContent = 1
info_guard = None
description = ''
for_catalog = 1
for_status = 1
default_value = ''
default_expr = None # Overrides default_value if set
info_guard = None
update_always = 1
# Declarative security # Declarative security
security = ClassSecurityInfo() security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation) security.declareObjectProtected(Permissions.AccessContentsInformation)
...@@ -53,3 +64,62 @@ class Variable(XMLObject): ...@@ -53,3 +64,62 @@ class Variable(XMLObject):
PropertySheet.DublinCore, PropertySheet.DublinCore,
PropertySheet.Variable, PropertySheet.Variable,
) )
def getDefaultExprText(self):
if not self.default_expr:
return ''
else:
return self.default_expr.text
def generateInfoGuard(self):
if self.info_guard == None:
self.info_guard = Guard(permissions=self.getPermissionList(),
roles=self.getRoleList(),
groups=self.getGroupList(),
expr=self.getExpression())
if self.info_guard.roles != self.getRoleList():
self.info_guard.roles = self.getRoleList()
elif self.info_guard.permissions != self.getPermissionList():
self.info_guard.permissions = self.getPermissionList()
elif self.info_guard.groups != self.getGroupList():
self.info_guard.groups = self.getGroupList()
elif self.info_guard.expr != self.getExpression():
self.info_guard.expr = self.getExpression()
def getInfoGuard(self):
if self.info_guard is not None:
return self.info_guard
else:
return Guard().__of__(self) # Create a temporary guard.
def getInfoGuardSummary(self):
res = None
if self.info_guard is not None:
res = self.info_guard.getSummary()
return res
def setProperties(self, description,
default_value='', default_expr='',
for_catalog=0, for_status=0,
update_always=0,
props=None, REQUEST=None):
'''
'''
self.description = str(description)
self.default_value = str(default_value)
if default_expr:
self.default_expr = Expression(default_expr)
else:
self.default_expr = None
g = Guard()
if g.changeFromProperties(props or REQUEST):
self.info_guard = g
else:
self.info_guard = None
self.for_catalog = bool(for_catalog)
self.for_status = bool(for_status)
self.update_always = bool(update_always)
if REQUEST is not None:
return self.manage_properties(REQUEST, 'Properties changed.')
\ 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