Commit ea488e40 authored by Julien Muchembled's avatar Julien Muchembled

Variated -> VariatedMixin

git-svn-id: https://svn.erp5.org/repos/public/erp5/sandbox/amount_generator@39281 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 8ceef6bd
......@@ -82,7 +82,7 @@ variation_list = kwargs.get(\'variation_list\')\n
variation_text = \'\'\n
\n
if variation_list is not None and len(variation_list) > 0:\n
# imitate behaviour from ERP5/Variated.py:getVariationText\n
# imitate behaviour from VariatedMixin.getVariationText\n
# to create text\n
variation_list.sort()\n
variation_text = \'\\n\'.join(variation_list)\n
......
......@@ -30,7 +30,7 @@
import zope.interface
from math import log
from AccessControl import ClassSecurityInfo
from Products.ERP5.Variated import Variated
from Products.ERP5.mixin.variated import VariatedMixin
from Products.ERP5.VariationValue import VariationValue
from Products.ERP5Type import Permissions, PropertySheet, interfaces
from Products.ERP5Type.Base import Base
......@@ -41,7 +41,7 @@ from zLOG import LOG, ERROR
from warnings import warn
class Amount(Base, Variated):
class Amount(Base, VariatedMixin):
"""
A mix-in class which provides some utilities
(variations, conversions, etc.)
......@@ -61,8 +61,7 @@ class Amount(Base, Variated):
security.declareObjectProtected(Permissions.AccessContentsInformation)
# Declarative interfaces
zope.interface.implements(interfaces.IVariated,
interfaces.IAmount)
zope.interface.implements(interfaces.IAmount)
property_sheets = ( PropertySheet.Base
, PropertySheet.SimpleItem
......@@ -108,7 +107,7 @@ class Amount(Base, Variated):
current_category=None,**kw):
"""
Returns the list of possible variations
XXX Copied and modified from Variated
XXX Copied and modified from VariatedMixin
Result is left display.
"""
variation_category_item_list = []
......@@ -274,7 +273,7 @@ class Amount(Base, Variated):
result = resource.getVariationBaseCategoryList(
omit_optional_variation=omit_optional_variation)
else:
result = Variated.getVariationRangeBaseCategoryList(self)
result = super(Amount, self).getVariationRangeBaseCategoryList()
return result
security.declareProtected(Permissions.AccessContentsInformation,
......
......@@ -30,11 +30,10 @@ from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5.Document.Predicate import Predicate
from Products.ERP5.mixin.variated import VariatedMixin
from Products.ERP5.Variated import Variated
class Budget(Predicate, Variated):
class Budget(Predicate, VariatedMixin):
"""
Budget means a kind of budget stock.
"""
......
......@@ -32,10 +32,10 @@ from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.XMLMatrix import XMLMatrix
from Products.ERP5.Document.Predicate import Predicate
from Products.ERP5.Variated import Variated
from Products.ERP5.mixin.variated import VariatedMixin
class BudgetLine(Predicate, XMLMatrix, Variated):
class BudgetLine(Predicate, XMLMatrix, VariatedMixin):
""" A Line of budget, variated in budget cells.
"""
......
......@@ -33,9 +33,10 @@ from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5Type.XMLMatrix import XMLMatrix
from Products.ERP5.Variated import Variated
from Products.ERP5.mixin.variated import VariatedMixin
class Consumption(XMLObject, XMLMatrix, Variated):
class Consumption(XMLObject, XMLMatrix, VariatedMixin):
"""
A matrix which provides default quantities
for a given quantity
......@@ -66,7 +67,7 @@ class Consumption(XMLObject, XMLMatrix, Variated):
self._setCategoryMembership(self.getVariationRangeBaseCategoryList(),
value, base=1)
# XXX Must use in futur this method, but it failed today
#Variated._setVariationCategoryList(self, value)
#VariatedMixin._setVariationCategoryList(self, value)
# XXX FIXME: Use a interaction workflow instead
# Kept for compatibility.
self.updateCellRange(base_id='quantity')
......
......@@ -35,11 +35,9 @@ from Products.ERP5Type.XMLMatrix import XMLMatrix
from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5.Document.Movement import Movement
from Products.ERP5.Variated import Variated
from Products.ERP5.Document.ImmobilisationMovement import ImmobilisationMovement
class DeliveryLine(Movement, XMLObject, XMLMatrix, Variated,
ImmobilisationMovement):
class DeliveryLine(Movement, XMLObject, XMLMatrix, ImmobilisationMovement):
"""
A DeliveryLine object allows to implement lines in
Deliveries (packing list, order, invoice, etc.)
......
......@@ -38,14 +38,13 @@ from Products.ERP5Type.XMLMatrix import XMLMatrix
from Products.ERP5Type.Base import Base
from Products.ERP5Type.Utils import cartesianProduct
from Products.ERP5.Variated import Variated
from Products.ERP5.mixin.variated import VariatedMixin
from Products.CMFCategory.Renderer import Renderer
from Products.CMFCore.utils import getToolByName
from zLOG import LOG, WARNING
class Resource(XMLMatrix, Variated):
class Resource(XMLMatrix, VariatedMixin):
"""
A Resource
"""
......@@ -147,8 +146,8 @@ class Resource(XMLMatrix, Variated):
other_base_category_dict.iteritems() if y == 1]
# Get category variation
if other_base_category_list:
result.extend(Variated.getVariationRangeCategoryItemList(
self, base_category_list=other_base_category_list,
result.extend(super(Resource, self).getVariationRangeCategoryItemList(
base_category_list=other_base_category_list,
base=base, display_base_category=display_base_category, **kw))
# Return result
return result
......@@ -187,7 +186,7 @@ class Resource(XMLMatrix, Variated):
if not x in optional_bc_list]
result = Variated.getVariationCategoryItemList(self,
result = super(Resource, self).getVariationCategoryItemList(
base_category_list=other_bc_list,
display_base_category=display_base_category,
display_id=display_id, base=base, **kw)
......
......@@ -237,7 +237,7 @@ class Transformation(MappedValue, AmountGeneratorMixin, VariatedMixin):
**kw):
"""
Returns the list of possible variations
XXX Copied and modified from Variated
XXX Copied and modified from VariatedMixin
Result is left display.
"""
variation_category_item_list = []
......
......@@ -26,367 +26,13 @@
#
##############################################################################
from AccessControl import ClassSecurityInfo
from Products.ERP5Type.Globals import InitializeClass
from Products.CMFCore.utils import getToolByName
from Products.ERP5Type import interfaces, Permissions
from Products.ERP5Type.Base import Base
from Products.CMFCategory.Renderer import Renderer
from warnings import warn
from zope.interface import implements
class Variated(Base):
"""
Variated is a mix-in class for all classes which implement
the Variated Interface.
A Variable object is an object which can variate
according to multiple dimensions. Variable objects include:
- a Resource instance
- an Amount instance (a Movement, a DeliveryLine, etc.)
- an Item
- a TransformedResource instance
"""
# Declarative security
security = ClassSecurityInfo()
# Declarative interfaces
implements(interfaces.IVariated)
security.declareProtected(Permissions.AccessContentsInformation,
'getVariationBaseCategoryList')
def getVariationBaseCategoryList(self, omit_optional_variation=0,
omit_option_base_category=None, omit_individual_variation=0):
"""
Return the list of variation base category.
If omit_optional_variation==1, do not include base category
considered as option (ex: industrial_phase).
"""
#XXX backwards compatibility
if omit_option_base_category is not None:
warn("Please use omit_optional_variation instead of"\
" omit_option_base_category.", DeprecationWarning)
omit_optional_variation = omit_option_base_category
vbcl = self._baseGetVariationBaseCategoryList()
if omit_optional_variation == 1:
# XXX First implementation
# option base category list is a portal method, until the creation
# of a good API.
option_base_category_list = self.getPortalOptionBaseCategoryList()
vbcl = [x for x in vbcl if x not in option_base_category_list]
else:
vbcl.extend(self.getOptionalVariationBaseCategoryList())
if omit_individual_variation == 0:
vbcl.extend(self.getIndividualVariationBaseCategoryList())
return vbcl
security.declareProtected(Permissions.AccessContentsInformation,
'_getVariationCategoryList')
def _getVariationCategoryList(self, base_category_list = ()):
if base_category_list is ():
base_category_list = self.getVariationBaseCategoryList()
# base_category_list = self.getVariationRangeBaseCategoryList()
return self.getAcquiredCategoryMembershipList(base_category_list, base=1)
security.declareProtected(Permissions.AccessContentsInformation,
'getVariationCategoryList')
def getVariationCategoryList(self, base_category_list=(),
omit_optional_variation=0, omit_option_base_category=None):
"""
Returns the list of possible variations
"""
#XXX backwards compatibility
if omit_option_base_category is not None:
warn("Please use omit_optional_variation instead of"\
" omit_option_base_category.", DeprecationWarning)
omit_optional_variation = omit_option_base_category
return self._getVariationCategoryList(
base_category_list=base_category_list)
security.declareProtected(Permissions.AccessContentsInformation,
'getVariationCategoryItemList')
def getVariationCategoryItemList(self, base_category_list=(), base=1,
display_id='logical_path', display_base_category=1,
current_category=None, omit_optional_variation=0,
omit_option_base_category=None, **kw):
"""
Returns the list of possible variations
"""
#XXX backwards compatibility
if omit_option_base_category is not None:
warn("Please use omit_optional_variation instead of"\
" omit_option_base_category.", DeprecationWarning)
omit_optional_variation = omit_option_base_category
variation_category_item_list = []
if current_category is not None:
variation_category_item_list.append((current_category,current_category))
if base_category_list is ():
base_category_list = self.getVariationBaseCategoryList()
if omit_optional_variation == 1:
base_category_list = [x for x in base_category_list if x not in
self.getPortalOptionBaseCategoryList()]
# Prepare 2 rendering
portal_categories = self.portal_categories
for base_category in base_category_list:
variation_category_list = self._getVariationCategoryList(
base_category_list=[base_category])
category_list = []
object_list = []
for variation_category_path in variation_category_list:
try:
variation_category = portal_categories.resolveCategory(
variation_category_path)
var_cat_portal_type = variation_category.getPortalType()
except AttributeError:
variation_category_item_list.append((variation_category_path,
variation_category_path))
else:
if var_cat_portal_type != 'Category':
object_list.append(variation_category)
else:
category_list.append(variation_category)
# Render categories
variation_category_item_list.extend(Renderer(
display_base_category=display_base_category,
display_none_category=0, base=base,
current_category=current_category,
display_id=display_id, **kw).\
render(category_list))
# Render the others
variation_category_item_list.extend(Renderer(
base_category=base_category,
display_base_category=display_base_category,
display_none_category=0, base=base,
current_category=current_category,
display_id='title', **kw).\
render(object_list))
return variation_category_item_list
# XXX Is it used ?
# def getVariationCategoryTitleOrIdItemList(self, base_category_list=(),
# base=1, **kw):
# """
# Returns a list of tuples by parsing recursively all categories in a
# given list of base categories. Uses getTitleOrId as method
# """
# return self.getVariationCategoryItemList(
# display_id='title_or_id',
# base_category_list=base_category_list, base=base, **kw)
security.declareProtected(Permissions.ModifyPortalContent,
'_setVariationCategoryList')
def _setVariationCategoryList(self, node_list, base_category_list=()):
if base_category_list is ():
base_category_list = self.getVariationBaseCategoryList()
self._setCategoryMembership(base_category_list,node_list,base=1)
security.declareProtected(Permissions.ModifyPortalContent,
'setVariationCategoryList')
def setVariationCategoryList(self, node_list, base_category_list=()):
self._setVariationCategoryList(node_list,
base_category_list=base_category_list)
self.reindexObject()
# Range
security.declareProtected(Permissions.AccessContentsInformation,
'getVariationRangeBaseCategoryList')
def getVariationRangeBaseCategoryList(self):
"""
Returns possible variation base_category ids.
"""
# Get a portal method which defines a list of
# variation base category
return self.getPortalVariationBaseCategoryList()
security.declareProtected(Permissions.AccessContentsInformation,
'getVariationRangeBaseCategoryItemList')
def getVariationRangeBaseCategoryItemList(self, base=1,
display_id='getTitle',
current_category=None):
"""
Returns possible variations of the resource
as a list of tuples (id, title). This is mostly
useful in ERP5Form instances to generate selection
menus.
"""
return self.portal_categories.getItemList(
self.getVariationBaseCategoryList())
security.declareProtected(Permissions.AccessContentsInformation,
'getVariationBaseCategoryItemList')
def getVariationBaseCategoryItemList(self, display_id='title_or_id',
omit_optional_variation=0, omit_option_base_category=None,
omit_individual_variation=0):
"""
Returns base category of the resource
as a list of tuples (title, id). This is mostly
useful in ERP5Form instances to generate selection
menus.
"""
#XXX backwards compatibility
if omit_option_base_category is not None:
warn("Please use omit_optional_variation instead of"\
" omit_option_base_category.", DeprecationWarning)
omit_optional_variation = omit_option_base_category
variation_base_category_list = self.getVariationBaseCategoryList(
omit_optional_variation=omit_optional_variation,
omit_individual_variation=omit_individual_variation)
result = []
for base_category in variation_base_category_list:
bc = self.portal_categories.resolveCategory(base_category)
result.extend(Renderer(display_base_category=0,
display_none_category=0, base=1,
display_id=display_id).render([bc]))
return result
# Methods for matrix UI widgets
# XXX FIXME Those method are depreciated.
# We now use _asCellRange scripts.
security.declareProtected(Permissions.AccessContentsInformation,
'getLineVariationRangeCategoryItemList')
def getLineVariationRangeCategoryItemList(self):
"""
Returns possible variations in line
"""
try:
resource = self.getDefaultResourceValue()
except AttributeError:
resource = None
if resource is not None:
clist = resource.getVariationRangeCategoryItemList(
base_category_list=self.getVariationBaseCategoryLine(),
root=0)
else:
clist = [(None,None)]
return clist
security.declareProtected(Permissions.AccessContentsInformation,
'getColumnVariationRangeCategoryItemList')
def getColumnVariationRangeCategoryItemList(self):
"""
Returns possible variations in column
"""
try:
resource = self.getDefaultResourceValue()
except AttributeError:
resource = None
if resource is not None:
clist = resource.getVariationRangeCategoryItemList(base_category_list =
self.getVariationBaseCategoryColumn(), root=0)
else:
clist = [(None,None)]
return clist
security.declareProtected(Permissions.AccessContentsInformation,
'getTabVariationRangeCategoryItemList')
def getTabVariationRangeCategoryItemList(self):
"""
Returns possible variations in tab
"""
try:
resource = self.getDefaultResourceValue()
except AttributeError:
resource = None
if resource is not None:
clist = resource.getVariationRangeCategoryItemList(base_category_list =
self.getVariationBaseCategoryTabList(), root=0)
else:
clist = [(None,None)]
return clist
# Help
security.declareProtected(Permissions.AccessContentsInformation,
'getMatrixVariationRangeBaseCategoryList')
def getMatrixVariationRangeBaseCategoryList(self):
"""
Return base categories used in the matrix
"""
line_bc= self.getVariationBaseCategoryLine()
column_bc = self.getVariationBaseCategoryColumn()
# We need to copy values first
tab_bc = list(self.getVariationBaseCategoryTabList())
result = tab_bc
if line_bc is not None and line_bc is not '':
result += [line_bc]
if column_bc is not None and column_bc is not '':
result += [column_bc]
return result
security.declareProtected(Permissions.AccessContentsInformation,
'getVariationRangeCategoryItemList')
def getVariationRangeCategoryItemList(self, base_category_list=(), base=1,
root=1,
display_method_id='getCategoryChildLogicalPathItemList',
display_base_category=1,
current_category=None, **kw):
"""
Returns possible variations
=> [(display, value)]
"""
result = []
if base_category_list is ():
base_category_list = self.getVariationBaseCategoryList()
elif type(base_category_list) is type('a'):
base_category_list = (base_category_list, )
traverse = getToolByName(self, 'portal_categories').unrestrictedTraverse
# Render categories
for base_category in base_category_list:
result += getattr(traverse(base_category), display_method_id)(
base=base,
display_base_category=display_base_category,
display_none_category=0, **kw)
# Return result
return result
from Products.ERP5.mixin.variated import VariatedMixin
security.declareProtected(Permissions.AccessContentsInformation,
'getVariationRangeCategoryList')
def getVariationRangeCategoryList(self, base_category_list=(), base=1,
root=1, current_category=None,
omit_individual_variation=0, **kw):
"""
Returns the range of acceptable categories
"""
vrcil = self.getVariationRangeCategoryItemList(
base_category_list=base_category_list, base=base, root=root,
current_category=current_category,
omit_individual_variation=omit_individual_variation, **kw)
# display is on left
return [x[1] for x in vrcil]
# Context related methods
security.declarePublic('newVariationValue')
def newVariationValue(self, context=None, REQUEST=None, **kw):
# PERFORMANCE ISSUE
from Products.ERP5.VariationValue import newVariationValue
if context is None:
return newVariationValue(REQUEST=REQUEST, **kw)
else:
return newVariationValue(context=context, REQUEST=REQUEST, **kw)
class Variated(Base, VariatedMixin):
"""Deprecated. Use mixin.variated.VariatedMixin instead."""
# Provide a string representation of variations
security.declarePublic('getVariationText')
def getVariationText(self):
"""
Provide a string representation of variation
"""
category_list = list(self.getVariationCategoryList())
category_list.sort()
return '\n'.join(category_list)
InitializeClass(Variated)
......@@ -29,8 +29,7 @@
from Products.ERP5Type import interfaces
from Products.ERP5Type.Context import Context
from Products.ERP5Type.Globals import InitializeClass
from Products.ERP5.Variated import Variated
from Products.ERP5.mixin.variated import VariatedMixin
from zope.interface import implements
def newVariationValue(context=None, REQUEST=None, **kw):
......@@ -42,7 +41,7 @@ def newVariationValue(context=None, REQUEST=None, **kw):
else:
return context_obj
class VariationValue(Context, Variated):
class VariationValue(Context, VariatedMixin):
"""
Embodies a variation value. Implements discrete variations.
"""
......
......@@ -27,21 +27,16 @@
#
##############################################################################
from warnings import warn
from AccessControl import ClassSecurityInfo
from Products.ERP5Type.Globals import InitializeClass
from Products.CMFCore.utils import getToolByName
from Products.ERP5Type import Context, interfaces, Permissions
from Products.ERP5Type.Base import Base
from Products.CMFCategory.Renderer import Renderer
from Products.ERP5Type import interfaces, Permissions
import zope.interface
from warnings import warn
from zope.interface import implements
class VariatedMixin(Base):
class VariatedMixin:
"""
Variated is a mix-in class for all classes which implement
the Variated Interface.
Mix-in class for all classes which implement the Variated Interface.
A Variable object is an object which can variate
according to multiple dimensions. Variable objects include:
......@@ -59,7 +54,7 @@ class VariatedMixin(Base):
security = ClassSecurityInfo()
# Declarative interfaces
implements(interfaces.IVariated)
zope.interface.implements(interfaces.IVariated)
security.declareProtected(Permissions.AccessContentsInformation,
'getVariationBaseCategoryList')
......@@ -345,7 +340,7 @@ class VariatedMixin(Base):
elif type(base_category_list) is type('a'):
base_category_list = (base_category_list, )
traverse = getToolByName(self, 'portal_categories').unrestrictedTraverse
traverse = self.getPortalObject().portal_categories.unrestrictedTraverse
# Render categories
for base_category in base_category_list:
result += getattr(traverse(base_category), display_method_id)(
......@@ -359,15 +354,14 @@ class VariatedMixin(Base):
'getVariationRangeCategoryList')
def getVariationRangeCategoryList(self, base_category_list=(), base=1,
root=1, current_category=None,
omit_individual_variation=0):
omit_individual_variation=0, **kw):
"""
Returns the range of acceptable categories
"""
vrcil = self.getVariationRangeCategoryItemList(
base_category_list=base_category_list,
base=base, root=root,
current_category=current_category,
omit_individual_variation=omit_individual_variation)
base_category_list=base_category_list, base=base, root=root,
current_category=current_category,
omit_individual_variation=omit_individual_variation, **kw)
# display is on left
return [x[1] for x in vrcil]
......@@ -390,5 +384,3 @@ class VariatedMixin(Base):
category_list = list(self.getVariationCategoryList())
category_list.sort()
return '\n'.join(category_list)
InitializeClass(VariatedMixin)
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