From f6b2afc4232ba5b07e2325d27b8f1a6fa90d8771 Mon Sep 17 00:00:00 2001 From: Gaetan Delannay Date: Tue, 19 Feb 2013 09:57:02 +0100 Subject: [PATCH] [gen] Added params Type.swidth and Type.sheight to allow for different sizes for the search widgets. --- gen/__init__.py | 56 ++++++++++++++++++++++----------------- gen/calendar.py | 2 +- gen/mixins/ToolMixin.py | 9 +++---- gen/ogone.py | 2 +- gen/ui/appy.css | 3 +-- gen/ui/widgets/float.pt | 10 ++++--- gen/ui/widgets/integer.pt | 10 ++++--- gen/ui/widgets/ref.pt | 9 ++++--- gen/ui/widgets/string.pt | 8 +++--- 9 files changed, 59 insertions(+), 50 deletions(-) diff --git a/gen/__init__.py b/gen/__init__.py index 58a23ca..f8fd986 100644 --- a/gen/__init__.py +++ b/gen/__init__.py @@ -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. diff --git a/gen/calendar.py b/gen/calendar.py index 066ce66..f37d82f 100644 --- a/gen/calendar.py +++ b/gen/calendar.py @@ -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 diff --git a/gen/mixins/ToolMixin.py b/gen/mixins/ToolMixin.py index 5eebb63..b740a97 100644 --- a/gen/mixins/ToolMixin.py +++ b/gen/mixins/ToolMixin.py @@ -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): diff --git a/gen/ogone.py b/gen/ogone.py index ed23344..cb6c3b0 100644 --- a/gen/ogone.py +++ b/gen/ogone.py @@ -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 diff --git a/gen/ui/appy.css b/gen/ui/appy.css index 34b8009..6f720d9 100644 --- a/gen/ui/appy.css +++ b/gen/ui/appy.css @@ -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; diff --git a/gen/ui/widgets/float.pt b/gen/ui/widgets/float.pt index 7a631f1..f6d510b 100644 --- a/gen/ui/widgets/float.pt +++ b/gen/ui/widgets/float.pt @@ -23,14 +23,16 @@
   - + value python: widget['sdefault'][0]; + size widget/swidth"/> - + value python: widget['sdefault'][1]; + size widget/swidth"/>
diff --git a/gen/ui/widgets/integer.pt b/gen/ui/widgets/integer.pt index b6c37c3..79d0f5b 100644 --- a/gen/ui/widgets/integer.pt +++ b/gen/ui/widgets/integer.pt @@ -23,14 +23,16 @@
   - + value python: widget['sdefault'][0]; + size widget/swidth"/> - + value python: widget['sdefault'][1]; + size widget/swidth"/>
diff --git a/gen/ui/widgets/ref.pt b/gen/ui/widgets/ref.pt index 40f5b49..c21e569 100644 --- a/gen/ui/widgets/ref.pt +++ b/gen/ui/widgets/ref.pt @@ -158,7 +158,8 @@ The search icon if field is queryable - + Appy (top) navigation @@ -265,12 +266,12 @@
The list of values - diff --git a/gen/ui/widgets/string.pt b/gen/ui/widgets/string.pt index 58bb1a8..ce27889 100644 --- a/gen/ui/widgets/string.pt +++ b/gen/ui/widgets/string.pt @@ -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)"> + tal:content="python:tool.truncateValue(possibleValue[1], widget['width'])"> @@ -94,7 +94,7 @@ @@ -113,11 +113,11 @@ The list of values