Small bugfix while searching string fields and added the possibility to define a text-transform on String fields.

This commit is contained in:
Gaetan Delannay 2010-04-16 17:07:34 +02:00
parent ae4bfc9970
commit ca7b688c00
6 changed files with 39 additions and 25 deletions

View file

@ -173,7 +173,8 @@ class ToolMixin(AbstractMixin):
if isinstance(fieldValue, basestring) and \
fieldValue.endswith('*'):
v = fieldValue[:-1]
params[attrName] = {'query':(v,v+'Z'), 'range':'minmax'}
params[attrName] = {'query':(v,v+'z'), 'range':'min:max'}
# Warning: 'z' is higher than 'Z'!
elif type(fieldValue) in sequenceTypes:
if fieldValue and isinstance(fieldValue[0], basestring):
# We have a list of string values (ie: we need to
@ -430,6 +431,8 @@ class ToolMixin(AbstractMixin):
day = int(day)-1
return res
transformMethods = {'uppercase': 'upper', 'lowercase': 'lower',
'capitalize': 'capitalize'}
def onSearchObjects(self):
'''This method is called when the user triggers a search from
search.pt.'''
@ -471,6 +474,14 @@ class ToolMixin(AbstractMixin):
day = rq.form['%s_to_day' % prefix]
toDate = self._getDateTime(year, month, day, False)
attrValue = (fromDate, toDate)
elif attrType.startswith('string'):
# In the case of a string, it could be necessary to
# apply some text transform.
if len(attrType) > 6:
transform = attrType.split('-')[1]
if (transform != 'none') and attrValue:
exec 'attrValue = attrValue.%s()' % \
self.transformMethods[transform]
if isinstance(attrValue, list):
# It is a list of values. Check if we have an operator for
# the field, to see if we make an "and" or "or" for all

View file

@ -26,7 +26,8 @@
<label tal:attributes="for widgetName" tal:content="python: tool.translate(appyType['label'])"></label><br>&nbsp;&nbsp;
<tal:comment replace="nothing">Show a simple search field for most String fields.</tal:comment>
<tal:simpleSearch condition="not: appyType/isSelect">
<input type="text" tal:attributes="name widgetName"/>
<input type="text" tal:attributes="name python: '%s*string-%s' % (widgetName, appyType['transform']);
style python: 'text-transform:%s' % appyType['transform']"/>
</tal:simpleSearch>
<tal:comment replace="nothing">Show a multi-selection box for fields whose validator defines a list of values, with a "AND/OR" checkbox.</tal:comment>
<tal:selectSearch condition="appyType/isSelect">

View file

@ -436,16 +436,20 @@ class FileWrapper:
convScript = '%s/converter.py' % os.path.dirname(appy.pod.__file__)
cmd = '%s %s "%s" %s -p%d' % (tool.unoEnabledPython, convScript,
filePath, format, tool.openOfficePort)
errorMessage = executeCommand(cmd, ignoreLines='warning')
errorMessage = executeCommand(cmd)
# Even if we have an "error" message, it could be a simple warning.
# So we will continue here and, as a subsequent check for knowing if
# an error occurred or not, we will test the existence of the
# converted file (see below).
os.remove(filePath)
if errorMessage:
tool.log(CONVERSION_ERROR % (cmd, errorMessage), type='error')
return
# Return the name of the converted file.
baseName, ext = os.path.splitext(filePath)
if (ext == '.%s' % format):
filePath = '%s.res.%s' % (baseName, format)
else:
filePath = '%s.%s' % (baseName, format)
if not os.path.exists(filePath):
tool.log(CONVERSION_ERROR % (cmd, errorMessage), type='error')
return
return filePath
# ------------------------------------------------------------------------------