[gen] Changes in parameters of some basic field methods to enable field.languages to be defined dymanically via a method.
This commit is contained in:
parent
18afb4416c
commit
f8a7103c7a
15 changed files with 153 additions and 112 deletions
|
@ -1246,12 +1246,27 @@ class ToolMixin(BaseMixin):
|
|||
return [f for f in self.getAllAppyTypes(contentType) \
|
||||
if (f.type == 'Pod') and (f.show == 'result')]
|
||||
|
||||
def formatDate(self, date, withHour=True):
|
||||
'''Returns p_date formatted as specified by tool.dateFormat.
|
||||
If p_withHour is True, hour is appended, with a format specified
|
||||
in tool.hourFormat.'''
|
||||
def formatDate(self, date, format=None, withHour=True, language=None):
|
||||
'''Returns p_date formatted as specified by p_format, or tool.dateFormat
|
||||
if not specified. If p_withHour is True, hour is appended, with a
|
||||
format specified in tool.hourFormat.'''
|
||||
tool = self.appy()
|
||||
res = date.strftime(tool.dateFormat)
|
||||
fmt = format or tool.dateFormat
|
||||
# Resolve appy-specific formatting symbols used for getting translated
|
||||
# names of days or months:
|
||||
# - %dt: translated name of day
|
||||
# - %DT: translated name of day, capitalized
|
||||
# - %mt: translated name of month
|
||||
# - %MT: translated name of month, capitalized
|
||||
if ('%dt' in fmt) or ('%DT' in fmt):
|
||||
day = self.translate('day_%s' % date._aday, language=language)
|
||||
fmt = fmt.replace('%dt', day.lower()).replace('%DT', day)
|
||||
if ('%mt' in fmt) or ('%MT' in fmt):
|
||||
month = self.translate('month_%s' % date._amon, language=language)
|
||||
fmt = fmt.replace('%mt', month.lower()).replace('%MT', month)
|
||||
# Resolve all other, standard, symbols
|
||||
res = date.strftime(fmt)
|
||||
# Append hour from tool.hourFormat
|
||||
if withHour: res += ' (%s)' % date.strftime(tool.hourFormat)
|
||||
return res
|
||||
|
||||
|
|
|
@ -337,12 +337,12 @@ class BaseMixin:
|
|||
rq = self.REQUEST
|
||||
for field in self.getAppyTypes('edit', rq.form.get('page')):
|
||||
if not field.validable or not field.isClientVisible(self): continue
|
||||
value = field.getRequestValue(rq)
|
||||
value = field.getRequestValue(self)
|
||||
message = field.validate(self, value)
|
||||
if message:
|
||||
setattr(errors, field.name, message)
|
||||
else:
|
||||
setattr(values, field.name, field.getStorableValue(value))
|
||||
setattr(values, field.name, field.getStorableValue(self, value))
|
||||
# Validate sub-fields within Lists
|
||||
if field.type != 'List': continue
|
||||
i = -1
|
||||
|
@ -634,7 +634,7 @@ class BaseMixin:
|
|||
if lg:
|
||||
isEmpty = not changes[name] or not changes[name].get(lg)
|
||||
else:
|
||||
isEmpty = field.isEmptyValue(changes[name], self)
|
||||
isEmpty = field.isEmptyValue(self, changes[name])
|
||||
if isEmpty:
|
||||
del changes[name]
|
||||
else:
|
||||
|
@ -664,14 +664,17 @@ class BaseMixin:
|
|||
# In some cases the old value must be formatted.
|
||||
if field.type == 'Ref':
|
||||
previousData[name] = [r.title for r in previousData[name]]
|
||||
elif (field.type == 'String') and field.isMultilingual():
|
||||
# Consider every language-specific value as a first-class value
|
||||
del previousData[name]
|
||||
for lg in field.languages:
|
||||
lgPrev = prev and prev.get(lg) or None
|
||||
lgCurr = curr and curr.get(lg) or None
|
||||
if lgPrev == lgCurr: continue
|
||||
previousData['%s-%s' % (name, lg)] = lgPrev
|
||||
elif field.type == 'String':
|
||||
languages = field.getAttribute(self, 'languages')
|
||||
if len(languages) > 1:
|
||||
# Consider every language-specific value as a first-class
|
||||
# value.
|
||||
del previousData[name]
|
||||
for lg in languages:
|
||||
lgPrev = prev and prev.get(lg) or None
|
||||
lgCurr = curr and curr.get(lg) or None
|
||||
if lgPrev == lgCurr: continue
|
||||
previousData['%s-%s' % (name, lg)] = lgPrev
|
||||
if previousData:
|
||||
self.addDataChange(previousData)
|
||||
|
||||
|
@ -714,7 +717,7 @@ class BaseMixin:
|
|||
'''Gets the value of field p_name as may be present in the request.'''
|
||||
# Return the request value for standard fields.
|
||||
if '*' not in name:
|
||||
return self.getAppyType(name).getRequestValue(self.REQUEST)
|
||||
return self.getAppyType(name).getRequestValue(self)
|
||||
# For sub-fields within Lists, the corresponding request values have
|
||||
# already been computed in the request key corresponding to the whole
|
||||
# List.
|
||||
|
@ -1083,7 +1086,11 @@ class BaseMixin:
|
|||
return True
|
||||
else:
|
||||
field = self.getAppyType(name)
|
||||
multilingual = (field.type == 'String') and field.isMultilingual()
|
||||
# Is this field a multilingual field ?
|
||||
languages = None
|
||||
if field.type == 'String':
|
||||
languages = field.getAttribute(self, 'languages')
|
||||
multilingual = len(languages) > 1
|
||||
for event in history:
|
||||
if event['action'] != '_datachange_': continue
|
||||
# Is there a value present for this field in this data change?
|
||||
|
@ -1093,7 +1100,7 @@ class BaseMixin:
|
|||
return True
|
||||
else:
|
||||
# At least one language-specific value must be present
|
||||
for lg in field.languages:
|
||||
for lg in languages:
|
||||
lgName = '%s-%s' % (field.name, lg)
|
||||
if (lgName in event['changes']) and \
|
||||
event['changes'][lgName][0]:
|
||||
|
@ -1142,7 +1149,7 @@ class BaseMixin:
|
|||
# previous value, we propose a diff with the next
|
||||
# version, excepted if the previous value is empty.
|
||||
if lg: isEmpty = not oldValue[0]
|
||||
else: isEmpty = field.isEmptyValue(oldValue[0])
|
||||
else: isEmpty = field.isEmptyValue(self, oldValue[0])
|
||||
if isEmpty:
|
||||
val = '-'
|
||||
else:
|
||||
|
|
|
@ -627,15 +627,6 @@ class ToolWrapper(AbstractWrapper):
|
|||
(user.o.absolute_url(), user.title,access))
|
||||
return res + '\n'.join(rows) + '</table>'
|
||||
|
||||
def getInitiator(self, field=False):
|
||||
'''Retrieves the object that triggered the creation of the object
|
||||
being currently created (if any), or the name of the field in this
|
||||
object if p_field is given.'''
|
||||
nav = self.o.REQUEST.get('nav', '')
|
||||
if not nav or not nav.startswith('ref.'): return
|
||||
if not field: return self.getObject(nav.split('.')[1])
|
||||
return nav.split('.')[2].split(':')[0]
|
||||
|
||||
def getObject(self, uid):
|
||||
'''Allow to retrieve an object from its unique identifier p_uid.'''
|
||||
return self.o.getObject(uid, appy=True)
|
||||
|
@ -666,10 +657,10 @@ class ToolWrapper(AbstractWrapper):
|
|||
'''Sends a mail. See doc for appy.gen.mail.sendMail.'''
|
||||
sendMail(self, to, subject, body, attachments=attachments)
|
||||
|
||||
def formatDate(self, date, withHour=True):
|
||||
def formatDate(self, date, format=None, withHour=True, language=None):
|
||||
'''Check doc @ToolMixin::formatDate.'''
|
||||
if not date: return
|
||||
return self.o.formatDate(date, withHour=withHour)
|
||||
return self.o.formatDate(date, format, withHour, language)
|
||||
|
||||
def getUserName(self, login=None, normalized=False):
|
||||
return self.o.getUserName(login=login, normalized=normalized)
|
||||
|
|
|
@ -43,10 +43,11 @@ class TranslationWrapper(AbstractWrapper):
|
|||
if field.type == 'Computed': name = field.name[:-6]
|
||||
else: name = field.name
|
||||
# Get the source message
|
||||
sourceLanguage = self.o.getProductConfig(True).sourceLanguage
|
||||
obj = self.o
|
||||
sourceLanguage = obj.getProductConfig(True).sourceLanguage
|
||||
sourceTranslation = getattr(tool.o, sourceLanguage).appy()
|
||||
sourceMsg = getattr(sourceTranslation, name)
|
||||
if field.isEmptyValue(sourceMsg): return False
|
||||
if field.isEmptyValue(obj, sourceMsg): return
|
||||
return True
|
||||
|
||||
poReplacements = ( ('\r\n', '<br/>'), ('\n', '<br/>'), ('"', '\\"') )
|
||||
|
|
|
@ -788,7 +788,7 @@ class AbstractWrapper(object):
|
|||
obj = self.o
|
||||
if hasattr(obj.aq_base, name):
|
||||
field = obj.getAppyType(name)
|
||||
return field.isEmptyValue(getattr(obj, name))
|
||||
return field.isEmptyValue(obj, getattr(obj, name))
|
||||
return True
|
||||
|
||||
def isTemp(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue