Small bugfix while searching string fields and added the possibility to define a text-transform on String fields.
This commit is contained in:
parent
ae4bfc9970
commit
ca7b688c00
6 changed files with 39 additions and 25 deletions
|
@ -276,13 +276,20 @@ class String(Type):
|
|||
show=True, page='main', group=None, move=0, indexed=False,
|
||||
searchable=False, specificReadPermission=False,
|
||||
specificWritePermission=False, width=None, height=None,
|
||||
master=None, masterValue=None, focus=False, historized=False):
|
||||
master=None, masterValue=None, focus=False, historized=False,
|
||||
transform='none'):
|
||||
Type.__init__(self, validator, multiplicity, index, default, optional,
|
||||
editDefault, show, page, group, move, indexed, searchable,
|
||||
specificReadPermission, specificWritePermission, width,
|
||||
height, master, masterValue, focus, historized)
|
||||
self.format = format
|
||||
self.isSelect = self.isSelection()
|
||||
# The following field has a direct impact on the text entered by the
|
||||
# user. It applies a transformation on it, exactly as does the CSS
|
||||
# "text-transform" property. Allowed values are those allowed for the
|
||||
# CSS property: "none" (default), "uppercase", "capitalize" or
|
||||
# "lowercase".
|
||||
self.transform = transform
|
||||
def isSelection(self):
|
||||
'''Does the validator of this type definition define a list of values
|
||||
into which the user must select one or more values?'''
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -26,7 +26,8 @@
|
|||
<label tal:attributes="for widgetName" tal:content="python: tool.translate(appyType['label'])"></label><br>
|
||||
<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">
|
||||
|
|
|
@ -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
|
||||
# ------------------------------------------------------------------------------
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue