[gen] Added params Type.swidth and Type.sheight to allow for different sizes for the search widgets.

This commit is contained in:
Gaetan Delannay 2013-02-19 09:57:02 +01:00
parent 24089ef674
commit f6b2afc423
9 changed files with 59 additions and 50 deletions

View file

@ -415,7 +415,7 @@ class Type:
layouts, move, indexed, searchable, specificReadPermission,
specificWritePermission, width, height, maxChars, colspan,
master, masterValue, focus, historized, sync, mapping, label,
sdefault, scolspan):
sdefault, scolspan, swidth, sheight):
# The validator restricts which values may be defined. It can be an
# interval (1,None), a list of string values ['choice1', 'choice2'],
# a regular expression, a custom function, a Selection instance, etc.
@ -515,6 +515,9 @@ class Type:
self.sdefault = sdefault
# Colspan for rendering the search widget corresponding to this field.
self.scolspan = scolspan
# Width and height for the search widget
self.swidth = swidth or width
self.sheight = sheight or height
def init(self, name, klass, appName):
'''When the application server starts, this secondary constructor is
@ -990,15 +993,15 @@ class Integer(Type):
def __init__(self, validator=None, multiplicity=(0,1), default=None,
show=True, page='main', group=None, layouts=None, move=0,
indexed=False, searchable=False, specificReadPermission=False,
specificWritePermission=False, width=6, height=None,
specificWritePermission=False, width=5, height=None,
maxChars=13, colspan=1, master=None, masterValue=None,
focus=False, historized=False, mapping=None, label=None,
sdefault=('',''), scolspan=1):
sdefault=('',''), scolspan=1, swidth=None, sheight=None):
Type.__init__(self, validator, multiplicity, default, show, page, group,
layouts, move, indexed, searchable,specificReadPermission,
specificWritePermission, width, height, maxChars, colspan,
master, masterValue, focus, historized, True, mapping,
label, sdefault, scolspan)
label, sdefault, scolspan, swidth, sheight)
self.pythonType = long
def validateValue(self, obj, value):
@ -1020,11 +1023,11 @@ class Float(Type):
def __init__(self, validator=None, multiplicity=(0,1), default=None,
show=True, page='main', group=None, layouts=None, move=0,
indexed=False, searchable=False, specificReadPermission=False,
specificWritePermission=False, width=6, height=None,
specificWritePermission=False, width=5, height=None,
maxChars=13, colspan=1, master=None, masterValue=None,
focus=False, historized=False, mapping=None, label=None,
sdefault=('',''), scolspan=1, precision=None, sep=(',', '.'),
tsep=' '):
sdefault=('',''), scolspan=1, swidth=None, sheight=None,
precision=None, sep=(',', '.'), tsep=' '):
# The precision is the number of decimal digits. This number is used
# for rendering the float, but the internal float representation is not
# rounded.
@ -1045,7 +1048,7 @@ class Float(Type):
layouts, move, indexed, False, specificReadPermission,
specificWritePermission, width, height, maxChars, colspan,
master, masterValue, focus, historized, True, mapping,
label, sdefault, scolspan)
label, sdefault, scolspan, swidth, sheight)
self.pythonType = float
def getFormattedValue(self, obj, value, showChanges=False):
@ -1176,7 +1179,7 @@ class String(Type):
specificReadPermission=False, specificWritePermission=False,
width=None, height=None, maxChars=None, colspan=1, master=None,
masterValue=None, focus=False, historized=False, mapping=None,
label=None, sdefault='', scolspan=1,
label=None, sdefault='', scolspan=1, swidth=None, sheight=None,
transform='none', styles=('p','h1','h2','h3','h4'),
allowImageUpload=True, richText=False):
# According to format, the widget will be different: input field,
@ -1205,7 +1208,7 @@ class String(Type):
layouts, move, indexed, searchable,specificReadPermission,
specificWritePermission, width, height, maxChars, colspan,
master, masterValue, focus, historized, True, mapping,
label, sdefault, scolspan)
label, sdefault, scolspan, swidth, sheight)
self.isSelect = self.isSelection()
# If self.isSelect, self.sdefault must be a list of value(s).
if self.isSelect and not sdefault:
@ -1228,6 +1231,8 @@ class String(Type):
elif format == String.PASSWORD: self.maxChars = 20
self.filterable = self.indexed and (self.format == String.LINE) and \
not self.isSelect
self.swidth = self.swidth or self.width
self.sheight = self.sheight or self.height
def isSelection(self):
'''Does the validator of this type definition define a list of values
@ -1523,12 +1528,12 @@ class Boolean(Type):
specificWritePermission=False, width=None, height=None,
maxChars=None, colspan=1, master=None, masterValue=None,
focus=False, historized=False, mapping=None, label=None,
sdefault=False, scolspan=1):
sdefault=False, scolspan=1, swidth=None, sheight=None):
Type.__init__(self, validator, multiplicity, default, show, page, group,
layouts, move, indexed, searchable,specificReadPermission,
specificWritePermission, width, height, None, colspan,
master, masterValue, focus, historized, True, mapping,
label, sdefault, scolspan)
label, sdefault, scolspan, swidth, sheight)
self.pythonType = bool
# Layout including a description
@ -1576,7 +1581,7 @@ class Date(Type):
specificWritePermission=False, width=None, height=None,
maxChars=None, colspan=1, master=None, masterValue=None,
focus=False, historized=False, mapping=None, label=None,
sdefault=None, scolspan=1):
sdefault=None, scolspan=1, swidth=None, sheight=None):
self.format = format
self.calendar = calendar
self.startYear = startYear
@ -1588,7 +1593,7 @@ class Date(Type):
layouts, move, indexed, searchable,specificReadPermission,
specificWritePermission, width, height, None, colspan,
master, masterValue, focus, historized, True, mapping,
label, sdefault, scolspan)
label, sdefault, scolspan, swidth, sheight)
def getCss(self, layoutType, res):
# CSS files are only required if the calendar must be shown.
@ -1655,13 +1660,14 @@ class File(Type):
specificWritePermission=False, width=None, height=None,
maxChars=None, colspan=1, master=None, masterValue=None,
focus=False, historized=False, mapping=None, label=None,
isImage=False, sdefault='', scolspan=1):
isImage=False, sdefault='', scolspan=1, swidth=None,
sheight=None):
self.isImage = isImage
Type.__init__(self, validator, multiplicity, default, show, page, group,
layouts, move, indexed, False, specificReadPermission,
specificWritePermission, width, height, None, colspan,
master, masterValue, focus, historized, True, mapping,
label, sdefault, scolspan)
label, sdefault, scolspan, swidth, sheight)
@staticmethod
def getFileObject(filePath, fileName=None, zope=False):
@ -1816,7 +1822,7 @@ class Ref(Type):
masterValue=None, focus=False, historized=False, mapping=None,
label=None, queryable=False, queryFields=None, queryNbCols=1,
navigable=False, searchSelect=None, changeOrder=True,
sdefault='', scolspan=1):
sdefault='', scolspan=1, swidth=None, sheight=None):
self.klass = klass
self.attribute = attribute
# May the user add new objects through this ref ?
@ -1896,7 +1902,7 @@ class Ref(Type):
layouts, move, indexed, False, specificReadPermission,
specificWritePermission, width, height, None, colspan,
master, masterValue, focus, historized, sync, mapping,
label, sdefault, scolspan)
label, sdefault, scolspan, swidth, sheight)
self.validable = self.link
def getDefaultLayouts(self):
@ -2160,7 +2166,7 @@ class Computed(Type):
maxChars=None, colspan=1, method=None, plainText=True,
master=None, masterValue=None, focus=False, historized=False,
sync=True, mapping=None, label=None, sdefault='', scolspan=1,
context={}):
swidth=None, sheight=None, context={}):
# The Python method used for computing the field value
self.method = method
# Does field computation produce plain text or XHTML?
@ -2174,10 +2180,10 @@ class Computed(Type):
# "someKey", it will be available to the macro as "options/someKey".
self.context = context
Type.__init__(self, None, multiplicity, default, show, page, group,
layouts, move, indexed, False, specificReadPermission,
layouts, move, indexed, searchable,specificReadPermission,
specificWritePermission, width, height, None, colspan,
master, masterValue, focus, historized, sync, mapping,
label, sdefault, scolspan)
label, sdefault, scolspan, swidth, sheight)
self.validable = False
def callMacro(self, obj, macroPath):
@ -2247,7 +2253,7 @@ class Action(Type):
move, indexed, False, specificReadPermission,
specificWritePermission, width, height, None, colspan,
master, masterValue, focus, historized, False, mapping,
label, None, None)
label, None, None, None, None)
self.validable = False
def getDefaultLayouts(self): return {'view': 'l-f', 'edit': 'lrv-f'}
@ -2295,7 +2301,7 @@ class Info(Type):
move, indexed, False, specificReadPermission,
specificWritePermission, width, height, None, colspan,
master, masterValue, focus, historized, False, mapping,
label, None, None)
label, None, None, None, None)
self.validable = False
class Pod(Type):
@ -2334,7 +2340,7 @@ class Pod(Type):
move, indexed, searchable, specificReadPermission,
specificWritePermission, width, height, None, colspan,
master, masterValue, focus, historized, False, mapping,
label, None, None)
label, None, None, None, None)
self.validable = False
def isFrozen(self, obj):
@ -2478,7 +2484,7 @@ class List(Type):
layouts, move, indexed, False, specificReadPermission,
specificWritePermission, width, height, None, colspan,
master, masterValue, focus, historized, True, mapping,
label, None, None)
label, None, None, None, None)
self.validable = True
# Tuples of (names, Type instances) determining the format of every
# element in the list.

View file

@ -25,7 +25,7 @@ class Calendar(Type):
layouts, move, False, False, specificReadPermission,
specificWritePermission, width, height, None, colspan,
master, masterValue, focus, False, True, mapping, label,
None, None)
None, None, None, None)
# eventTypes can be a "static" list or tuple of strings that identify
# the types of events that are supported by this calendar. It can also
# be a method that computes such a "dynamic" list or tuple. When

View file

@ -396,12 +396,11 @@ class ToolMixin(BaseMixin):
res = getattr(self.appy(), toolFieldName)
return res
def truncateValue(self, value, appyType):
'''Truncates the p_value according to p_appyType width.'''
maxWidth = appyType['width']
def truncateValue(self, value, width=15):
'''Truncates the p_value according to p_width.'''
if isinstance(value, str): value = value.decode('utf-8')
if len(value) > maxWidth:
return value[:maxWidth].encode('utf-8') + '...'
if len(value) > width:
return value[:width].encode('utf-8') + '...'
return value.encode('utf-8')
def truncateText(self, text, width=15):

View file

@ -38,7 +38,7 @@ class Ogone(Type):
False, False,specificReadPermission,
specificWritePermission, width, height, None, colspan,
master, masterValue, focus, False, True, mapping, label,
None, None)
None, None, None, None)
# orderMethod must contain a method returning a dict containing info
# about the order. Following keys are mandatory:
# * orderID An identifier for the order. Don't use the object UID

View file

@ -73,7 +73,7 @@ img { border: 0; vertical-align: middle}
background-color: #d7dee4; border-radius: 2px 2px 2px 2px;
box-shadow: 0 2px 4px #A9A9A9 }
.focus td { padding: 4px 0px 4px 4px }
.discreet { font-size: 90%; }
.discreet { font-size: 90%; color: grey }
.lostPassword a { font-size: 90%; color: white; padding-left: 1em;}
.portlet { width: 150px; border-right: 1px solid #5F7983;
background-color: #ededed}
@ -127,7 +127,6 @@ img { border: 0; vertical-align: middle}
.history th { font-style: italic; text-align: left; padding: 0 5px 0 5px }
.topSpace { margin-top: 15px;}
.bottomSpace { margin-bottom: 15px;}
.discreet { color: grey}
.pageLink { padding-left: 8px }
.footer { font-size: 95% }
.footer td { background-color: #CBCBC9; border-top: 1px solid grey;

View file

@ -23,14 +23,16 @@
<label tal:content="python: _(widget['labelId'])"></label><br>&nbsp;&nbsp;
<tal:from define="fromName python: '%s*float' % widgetName">
<label tal:attributes="for fromName" tal:content="python: _('search_from')"></label>
<input type="text" size="4"
<input type="text"
tal:attributes="name fromName; maxlength maxChars;
value python: widget['sdefault'][0]"/>
value python: widget['sdefault'][0];
size widget/swidth"/>
</tal:from>
<tal:to define="toName python: '%s_to' % name">
<label tal:attributes="for toName" tal:content="python: _('search_to')"></label>
<input type="text" size="4"
<input type="text"
tal:attributes="name toName; maxlength maxChars;
value python: widget['sdefault'][1]"/>
value python: widget['sdefault'][1];
size widget/swidth"/>
</tal:to><br/>
</metal:search>

View file

@ -23,14 +23,16 @@
<label tal:content="python: _(widget['labelId'])"></label><br>&nbsp;&nbsp;
<tal:from define="fromName python: '%s*int' % widgetName">
<label tal:attributes="for fromName" tal:content="python: _('search_from')"></label>
<input type="text" size="4"
<input type="text"
tal:attributes="name fromName; maxlength maxChars;
value python: widget['sdefault'][0]"/>
value python: widget['sdefault'][0];
size widget/swidth"/>
</tal:from>
<tal:to define="toName python: '%s_to' % name">
<label tal:attributes="for toName" tal:content="python: _('search_to')"></label>
<input type="text" size="4"
<input type="text"
tal:attributes="name toName; maxlength maxChars;
value python: widget['sdefault'][1]"/>
value python: widget['sdefault'][1];
size widget/swidth"/>
</tal:to><br/>
</metal:search>

View file

@ -158,7 +158,8 @@
<tal:comment replace="nothing">The search icon if field is queryable</tal:comment>
<a tal:condition="python: objs and appyType['queryable']"
tal:attributes="href python: '%s/ui/search?className=%s&ref=%s:%s' % (tool.absolute_url(), linkedPortalType, contextObj.UID(), appyType['name'])">
<img src="search.gif" tal:attributes="title python: _('search_title')"/></a>
<img tal:attributes="title python: _('search_title');
src string: $appUrl/ui/search.gif"/></a>
</div>
<tal:comment replace="nothing">Appy (top) navigation</tal:comment>
@ -265,12 +266,12 @@
<label tal:attributes="for andName" tal:content="python: _('search_and')"></label><br/>
</tal:operator>
<tal:comment replace="nothing">The list of values</tal:comment>
<select tal:attributes="name widgetName; size widget/height" multiple="multiple">
<select tal:attributes="name widgetName; size widget/sheight" multiple="multiple">
<tal:option repeat="v python: tool.getSearchValues(name, className)">
<option tal:define="uid python: v[0];
title python: tool.getReferenceLabel(name, v[1], className)"
tal:attributes="value uid; title title"
tal:content="python: tool.truncateValue(title, widget)">
tal:attributes="value uid; title title"
tal:content="python: tool.truncateValue(title, widget['swidth'])">
</option>
</tal:option>
</select>

View file

@ -47,7 +47,7 @@
tal:attributes="value python: possibleValue[0];
selected python:contextObj.fieldValueSelected(name, possibleValue[0], rawValue);
title python: possibleValue[1]"
tal:content="python:tool.truncateValue(possibleValue[1], widget)"></option>
tal:content="python:tool.truncateValue(possibleValue[1], widget['width'])"></option>
</select>
</tal:choice>
<tal:line condition="python: isOneLine and not isSelect">
@ -94,7 +94,7 @@
<tal:simpleSearch condition="not: widget/isSelect">
<input type="text" tal:define="maxChars python: test(widget['maxChars'], widget['maxChars'], '')"
tal:attributes="name python: '%s*string-%s' % (widgetName, widget['transform']);
maxlength maxChars; size widget/width;
maxlength maxChars; size widget/swidth;
style python: 'text-transform:%s' % widget['transform'];
value widget/sdefault"/>
</tal:simpleSearch>
@ -113,11 +113,11 @@
</tal:operator>
<tal:comment replace="nothing">The list of values</tal:comment>
<select tal:define="preSelected widget/sdefault"
tal:attributes="name widgetName; size widget/height" multiple="multiple">
tal:attributes="name widgetName; size widget/sheight" multiple="multiple">
<option tal:repeat="v python:tool.getPossibleValues(name, withTranslations=True, withBlankValue=False, className=className)"
tal:attributes="value python:v[0]; title python: v[1];
selected python: v[0] in preSelected"
tal:content="python: tool.truncateValue(v[1], widget)">
tal:content="python: tool.truncateValue(v[1], widget['swidth'])">
</option>
</select>
</tal:selectSearch><br/>