[gen] Bugfixes.

This commit is contained in:
Gaetan Delannay 2015-02-23 12:38:49 +01:00
parent af635f936f
commit dd7e2000a1
4 changed files with 17 additions and 15 deletions

View file

@ -30,7 +30,7 @@ class Field:
'''Basic abstract class for defining any field.''' '''Basic abstract class for defining any field.'''
# Some global static variables # Some global static variables
nullValues = (None, '', []) nullValues = (None, '', [], {})
validatorTypes = (types.FunctionType, types.UnboundMethodType, validatorTypes = (types.FunctionType, types.UnboundMethodType,
type(re.compile(''))) type(re.compile('')))
labelTypes = ('label', 'descr', 'help') labelTypes = ('label', 'descr', 'help')

View file

@ -557,15 +557,14 @@ class String(Field):
return res return res
def isEmptyValue(self, obj, value): def isEmptyValue(self, obj, value):
'''Returns True if the p_value must be considered as an empty value.''' '''Returns True if the p_value must be considered as an empty value'''
if not self.isMultilingual(obj): if not isinstance(obj, dict):
return Field.isEmptyValue(self, obj, value) return Field.isEmptyValue(self, obj, value)
# For a multilingual value, as soon as a value is not empty for a given # p_value is a dict of multilingual values. For such values, as soon
# language, the whole value is considered as not being empty. # as a value is not empty for a given language, the whole value is
if not value: return True # considered as not being empty.
for v in value.itervalues(): for v in value.itervalues():
if not Field.isEmptyValue(self, obj, v): return if not Field.isEmptyValue(self, obj, v): return
return True
def isCompleteValue(self, obj, value): def isCompleteValue(self, obj, value):
'''Returns True if the p_value must be considered as complete. For a '''Returns True if the p_value must be considered as complete. For a
@ -910,8 +909,11 @@ class String(Field):
if rq.get('cancel') == 'True': return if rq.get('cancel') == 'True': return
requestValue = rq['fieldContent'] requestValue = rq['fieldContent']
# Remember previous value if the field is historized # Remember previous value if the field is historized
previousData = obj.rememberPreviousData([self]) isHistorized = self.getAttribute(obj, 'historized')
previousData = None
if isHistorized: previousData = obj.rememberPreviousData([self])
if self.isMultilingual(obj): if self.isMultilingual(obj):
if isHistorized:
# We take a copy of previousData because it is mutable (dict) # We take a copy of previousData because it is mutable (dict)
prevData = previousData[self.name] prevData = previousData[self.name]
if prevData != None: prevData = prevData.copy() if prevData != None: prevData = prevData.copy()
@ -925,7 +927,7 @@ class String(Field):
self.store(obj, self.getStorableValue(obj, requestValue)) self.store(obj, self.getStorableValue(obj, requestValue))
part = '' part = ''
# Update the object history when relevant # Update the object history when relevant
if previousData: obj.historizeData(previousData) if isHistorized and previousData: obj.historizeData(previousData)
# Update obj's last modification date # Update obj's last modification date
from DateTime import DateTime from DateTime import DateTime
obj.modified = DateTime() obj.modified = DateTime()

View file

@ -1189,7 +1189,7 @@ class BaseMixin:
if not includeInvisible: if not includeInvisible:
history = [e for e in history if e['comments'] != '_invisible_'] history = [e for e in history if e['comments'] != '_invisible_']
if reverse: history.reverse() if reverse: history.reverse()
# Keep only events which are within the batch. # Keep only events which are within the batch
res = [] res = []
stopIndex = startNumber + batchSize - 1 stopIndex = startNumber + batchSize - 1
i = -1 i = -1

View file

@ -31,7 +31,7 @@ class Merger:
self.i = 0 self.i = 0
# The delta index that must be applied on previous diffs # The delta index that must be applied on previous diffs
self.deltaPrevious = 0 self.deltaPrevious = 0
# A link to the caller HtmlDiff class. # A link to the caller HtmlDiff class
self.differ = differ self.differ = differ
def computeNewDiffs(self): def computeNewDiffs(self):