Commit 2178cbed authored by Jérome Perrin's avatar Jérome Perrin

pdm: fix pylint messages and enable coding style test

parent 22cb0a5c
# Remove empty items
item_list = filter(lambda x: x not in [('',''), ['','']],
item_list)
if default_sub_field_property_dict is None:
default_sub_field_property_dict = {}
sub_field_dict = {}
split_depth = 1
for item in item_list:
# Remove empty items
if item in (('', ''), ['', '']):
continue
# Get value of the item
item_value = item[int(not is_right_display)]
......
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>item_list, value_list, default_sub_field_property_dict={}, is_right_display=0</string> </value>
<value> <string>item_list, value_list, default_sub_field_property_dict=None, is_right_display=0</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
# from Products.ERP5Type.Utils import cartesianProduct
# XXX unable to import cartesianProduct, so, I copied the code (Romain)
def cartesianProduct(list_of_list):
if len(list_of_list) == 0:
return [[]]
result = []
head = list_of_list[0]
tail = list_of_list[1:]
product = cartesianProduct(tail)
for v in head:
for p in product:
result += [[v] + p]
return result
from Products.ERP5Type.Utils import cartesianProduct
line = []
column = []
tab = []
transformation = context.getParentValue()
# security.declareProtected(Permissions.AccessContentsInformation, 'getQLineItemList')
# def getQLineItemList(self, display_id='getTitle', base=1, current_category=None):
# """
# """
# line_category = self._getSortedBaseCategoryList(self.getQVariationBaseCategoryList())[0]
# #LOG('getQLineItemList', 0, "%s" % str(line_category))
# if line_category is None:
# result = [(None,'')]
# else:
# result = self.getVariationRangeCategoryItemList(base_category_list = [line_category],
# display_id=display_id,
# base=base,
# current_category=current_category)
# #LOG('getQLineItemList', 10, "%s" % str(result))
# return result
# security.declareProtected(Permissions.AccessContentsInformation, 'getQColumnItemList')
# def getQColumnItemList(self, display_id='getTitle', base=1, current_category=None):
# """
# """
# column_category = self._getSortedBaseCategoryList(self.getQVariationBaseCategoryList())[1]
# #LOG('getQColumnItemList', 0, "%s" % str(column_category))
# if column_category is None:
# result = [(None,'')]
# else:
# result = self.getVariationRangeCategoryItemList(base_category_list = [column_category],
# display_id=display_id,
# base=base,
# current_category=current_category)
# #LOG('getQColumnItemList', 0, "%s" % str(result))
# return result
# security.declareProtected(Permissions.AccessContentsInformation, 'getQTabItemList')
# def getQTabItemList(self, display_id='getTitle', base=1, current_category=None):
# """
# Returns a list of items which can be used as index for
# each tab of a matrix or to define a cell range.
# """
# tab_category_list = self._getSortedBaseCategoryList(self.getQVariationBaseCategoryList())[2:]
# tab_category_item_list_list = []
# for tab_category in tab_category_list:
# tab_category_item_list = self.getVariationRangeCategoryItemList(base_category_list = [tab_category],
# display_id=display_id,
# base=base,
# current_category=current_category)
# tab_category_item_list_list.append(tab_category_item_list)
# transformation = self.getParentValue()
# transformation_category_item_list = transformation.getVariationCategoryItemList(
# display_id=display_id,
# base=base,
# current_category=current_category)
# tab_category_item_list_list.append(transformation_category_item_list)
# if len(tab_category_item_list_list) > 0:
# product_list = cartesianProduct(tab_category_item_list_list)
# result = []
# for item_list in product_list:
# value_list = []
# label_list = []
# for item in item_list:
# value_list.append(item[0])
# label_list.append(item[1])
# result.append((value_list, label_list))
# else:
# result = [(None,'')]
# return result
# base_cell_id possible value: 'quantity', 'variation'
base_cell_id = 'quantity'
......@@ -160,43 +13,20 @@ get_variation_base_category_method_dict = {
'variation': 'getVVariationBaseCategoryList'
}
# from Products.ERP5Type.Utils import cartesianProduct
# XXX unable to import cartesianProduct, so, I copied the code (Romain)
def cartesianProduct(list_of_list):
if len(list_of_list) == 0:
return [[]]
result = []
head = list_of_list[0]
tail = list_of_list[1:]
product = cartesianProduct(tail)
for v in head:
for p in product:
result += [[v] + p]
return result
line = []
column = []
tab = []
transformation = context.getParentValue()
# Those value are define on property sheet of portal type
line_base_category = transformation.getVariationBaseCategoryLine()
column_base_category = transformation.getVariationBaseCategoryColumn()
# Calculate line and column
for axe, axe_base_category in [(line, line_base_category),(column, column_base_category)]:
for axe, axe_base_category in [(line, line_base_category), (column, column_base_category)]:
clist = []
#if axe_base_category in context.getVVariationBaseCategoryList():
if axe_base_category in getattr(context, get_variation_base_category_method_dict[base_cell_id])():
if matrixbox == 1:
if matrixbox:
# XXX matrixbox is right_display (not as listfield) => invert display and value in item
axe += map(lambda x: (x[1],x[0]), transformation.getVariationCategoryItemList(base_category_list = (axe_base_category,) ) )
axe.extend([(x[1], x[0]) for x in transformation.getVariationCategoryItemList(base_category_list = (axe_base_category,) )])
else:
axe += transformation.getVariationCategoryList(base_category_list = (axe_base_category,) )
axe.extend(transformation.getVariationCategoryList(base_category_list = (axe_base_category,) ))
# Calculate tab
# We can only display 3 dimension, so, we use a cartesian product to decrease matrix dimension
......@@ -207,11 +37,11 @@ for c in base_category_list:
if not c in (line_base_category, column_base_category):
#if c in context.getVVariationBaseCategoryList():
if c in getattr(context, get_variation_base_category_method_dict[base_cell_id])():
if matrixbox == 1:
if matrixbox:
# XXX matrixbox is right_display (not as listfield) => invert display and value in item
base_category += [ map(lambda x: (x[1],x[0]), transformation.getVariationCategoryItemList(base_category_list = (c,) )) ]
base_category.extend([(x[1], x[0]) for x in transformation.getVariationCategoryItemList(base_category_list = (c,)) ])
else:
base_category += [ transformation.getVariationCategoryList(base_category_list = (c,) ) ]
base_category.extend(transformation.getVariationCategoryList(base_category_list = (c,)))
if len(base_category) > 0:
# Then make a cartesian product
......@@ -222,12 +52,12 @@ if len(base_category) > 0:
for c in clist:
if matrixbox == 1:
# XXX matrixbox is right display
tab.append( ( repr(map(lambda x: x[0], c)) , repr(map(lambda x: x[1], c)) ) )
tab.append((repr([x[0] for x in c]), repr([x[1] for x in c])))
else:
tab.append( repr(c) )
# Try fill line first, then column, and after tab
for i in range(2):
for _ in range(2):
if line == []:
tmp = line
line = column
......
......@@ -11,15 +11,6 @@ def getPreferredCategoryDisplayMethodId():
return method == 'getTranslatedCompactTitle' and 'getCompactTranslatedTitle' \
or method
# Zope: waiting for __builtin__.set
set = lambda seq: dict((k,None) for k in seq).iterkeys()
# Zope: waiting for __builtin__.sorted
def sorted(seq):
l = list(seq)
l.sort()
return l
class ResourceSelection:
"""
Helper class to handle a selection of resources.
......
from math import log
result = context.getPriceParameterDict(context=movement, **kw)
# Calculate
......
......@@ -11,11 +11,9 @@ sampling_amount inventory lines, sorted by date.
# XXX: Might be set in preferences
sampling_amount = kwargs.get('sampling_amount',20)
from Products.ERP5Type.Document import newTempDocument
from DateTime import DateTime
resource = context
request = context.REQUEST
portal = context.getPortalObject()
node = portal.restrictedTraverse(kwargs.get('node'))
......@@ -47,7 +45,6 @@ inventory_tuple_list = []
precise_time_format = '%Y/%m/%d %H:%M.%S'
base_time_format = precise_time_format
rough_time_form = '%Y/%m/%d'
# XXX: Below performance issues:
# * sampling made in dumb way - it shall use SQL
# * inventory is invoked 3 times for each sample
......@@ -72,15 +69,16 @@ for i in range(0,sampling_amount):
inventory_tuple_list.append(internal_tuple)
return_list = []
for a in range(0,len(inventory_tuple_list)):
d = newTempDocument( portal, str(a) )
for a in range(0, len(inventory_tuple_list)):
data = inventory_tuple_list[a]
d.edit(
title = 'title %s'%(a,),
date = data[0],
current = data[1],
available = data[2],
future = data[3],
)
return_list.append(d)
return_list.append(
portal.newContent(
portal_type='Base',
temp_object=True,
id=str(a),
title='title %s'%(a,),
date=data[0],
current=data[1],
available=data[2],
future=data[3],))
return return_list
......@@ -42,11 +42,11 @@ for base_category_list in base_category_list_list:
if matrixbox:
# XXX matrixbox is right_display (not as listfield)
# => invert display and value in item
cell_range.append(map(lambda x: (x[1], x[0]),
cell_range.append([(x[1], x[0]) for x in
context.getVariationRangeCategoryItemList(
base_category_list=base_category_list,
display_base_category=display_base_category,
sort_id='id')))
sort_id='id')])
else:
cell_range.append(
context.getVariationRangeCategoryList(
......
from Products.ERP5Type.Document import newTempAmount
tmp_context = newTempAmount(context, "temp_context",
tmp_context = context.newContent(
id="temp_context",
portal_type="Amount",
temp_object=True,
quantity=1.0,
variation_category_list=reference_variation_category_list,
resource=context.getRelativeUrl())
price_currency = kw.get('price_currency', None)
result = context.getAggregatedAmountList(tmp_context)
final_result = []
for line in result:
resource = line.getResourceValue()
sender_value = None
if resource is not None:
sender = line.getResourceValue().getPurchaseSupplyLineSource()
line.setCategoryMembership('source', sender)
......
from Products.ERP5Type.Utils import cartesianProduct
from Products.ERP5Form.Report import ReportSection
REQUEST = context.REQUEST
......@@ -9,20 +10,6 @@ elif reference_variation_category_list == []:
result = []
# from Products.ERP5Type.Utils import cartesianProduct
# XXX unable to import cartesianProduct, so, I copied the code (Romain)
def cartesianProduct(list_of_list):
if len(list_of_list) == 0:
return [[]]
result = []
head = list_of_list[0]
tail = list_of_list[1:]
product = cartesianProduct(tail)
for v in head:
for p in product:
result += [[v] + p]
return result
# Separate reference_variation_category_list by base category
variation_category_dict = {}
for variation_category in reference_variation_category_list:
......@@ -35,8 +22,6 @@ for variation_category in reference_variation_category_list:
variation_key_list = cartesianProduct( variation_category_dict.values() )
portal = context.portal_url.getPortalObject()
for variation_key in variation_key_list:
params = {
'reference_variation_category_list' : variation_key,
......
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>reference_variation_category_list=[]</string> </value>
<value> <string>reference_variation_category_list=()</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
if selection_name is not None:
reference_variation_category_list = context.portal_selections.getSelectionParamsFor(selection_name)['reference_variation_category_list']
from Products.ERP5Type.Document import newTempAmount
tmp_context = newTempAmount(context, "temp_context",
tmp_context = context.newContent(
id="temp_context",
portal_type="Amount",
temp_object=True,
quantity=1.0,
variation_category_list=reference_variation_category_list,
resource=context.getRelativeUrl())
aal = context.getAggregatedAmountList(tmp_context)
result = aal.getTotalDuration()
return result
else:
return None
if selection_name is not None:
reference_variation_category_list = context.portal_selections.getSelectionParamsFor(selection_name)['reference_variation_category_list']
from Products.ERP5Type.Document import newTempAmount
tmp_context = newTempAmount(context, "temp_context",
tmp_context = context.newContent(
id="temp_context",
portal_type="Amount",
temp_object=True,
quantity=1.0,
variation_category_list=reference_variation_category_list,
resource=context.getRelativeUrl())
price_currency = context.REQUEST.get('price_currency', None)
aal = context.getAggregatedAmountList(tmp_context)
for line in aal:
resource = line.getResourceValue()
sender_value = None
if resource is not None:
sender = line.getResourceValue().getPurchaseSupplyLineSource()
line.setCategoryMembership('source', sender)
......@@ -19,7 +21,3 @@ if selection_name is not None:
result = aal.getTotalPrice()
return result
else:
return None
......@@ -13,25 +13,23 @@ line_base_category = transformation.getVariationBaseCategoryLine()
column_base_category = transformation.getVariationBaseCategoryColumn()
base_category_list = transformation.getVariationBaseCategoryList()
tab_base_category_list = filter(lambda x: x not in [line_base_category,
column_base_category], base_category_list)
tab_base_category_list = [x for x in base_category_list if x not in (line_base_category, column_base_category)]
for c in ([line_base_category, column_base_category] + tab_base_category_list):
# try to display line first, then column, and finally others
if c in getattr(context,
get_variation_base_category_method_dict[base_id])():
# base category was selected by user
if matrixbox == 1:
if matrixbox:
# XXX matrixbox is right_display (not as listfield)
# => invert display and value in item
cell_range.append(map(lambda x: (x[1],x[0]),
transformation.getVariationCategoryItemList
(base_category_list=(c,))))
cell_range.append(
[(x[1], x[0]) for x in transformation.getVariationCategoryItemList(base_category_list=(c,))])
else:
cell_range.append(transformation.getVariationCategoryList(
base_category_list=(c,)))
# Remove empty range
cell_range = filter(lambda x: x != [], cell_range)
cell_range = [x for x in cell_range if x != []]
return cell_range
request = context.REQUEST
consumption_list = context.getSpecialiseValueList()
# convert string to float
reference_quantity = float( reference_quantity )
......
request = context.REQUEST
cell_key_list = context.getCellKeyList( base_id = 'variation')
for cell_key in cell_key_list:
......
# Remove empty items
item_list = filter(lambda x: x not in [('',''), ['','']],
item_list)
if default_sub_field_property_dict is None:
default_sub_field_property_dict = {}
sub_field_dict = {}
split_depth = 1
for item in item_list:
# Remove empty items
if item in (('', ''), ['', '']):
continue
# Get value of the item
item_value = item[int(not is_right_display)]
......
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>item_list, value_list, default_sub_field_property_dict={}, is_right_display=0</string> </value>
<value> <string>item_list, value_list, default_sub_field_property_dict=None, is_right_display=0</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
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