diff --git a/gen/__init__.py b/gen/__init__.py index 4c3956b..00cdf9a 100644 --- a/gen/__init__.py +++ b/gen/__init__.py @@ -360,7 +360,7 @@ class Type: def __init__(self, validator, multiplicity, index, default, optional, editDefault, show, page, group, layouts, move, indexed, searchable, specificReadPermission, specificWritePermission, - width, height, colspan, master, masterValue, focus, + width, height, maxChars, colspan, master, masterValue, focus, historized, sync, mapping): # The validator restricts which values may be defined. It can be an # interval (1,None), a list of string values ['choice1', 'choice2'], @@ -425,6 +425,11 @@ class Type: # Widget width and height self.width = width self.height = height + # While width and height refer to widget dimensions, maxChars hereafter + # represents the maximum number of chars that a given input field may + # accept (corresponds to HTML "maxlength" property). "None" means + # "unlimited". + self.maxChars = maxChars # If the widget is in a group with multiple columns, the following # attribute specifies on how many columns to span the widget. self.colspan = colspan @@ -807,6 +812,16 @@ class Type: type-specific validation. p_value is never empty.''' return None + def securityCheck(self, obj, value): + '''This method performs some security checks on the p_value that + represents user input.''' + if not isinstance(value, basestring): return + # Search Javascript code in the value (prevent XSS attacks). + if ' self.maxChars): + value = value[:self.maxChars] exec 'obj.%s = value' % self.name def getIndexType(self): @@ -1346,13 +1373,13 @@ class Boolean(Type): page='main', group=None, layouts = None, move=0, indexed=False, searchable=False, specificReadPermission=False, specificWritePermission=False, width=None, height=None, - colspan=1, master=None, masterValue=None, focus=False, - historized=False, mapping=None): + maxChars=None, colspan=1, master=None, masterValue=None, + focus=False, historized=False, mapping=None): Type.__init__(self, validator, multiplicity, index, default, optional, editDefault, show, page, group, layouts, move, indexed, searchable, specificReadPermission, - specificWritePermission, width, height, colspan, master, - masterValue, focus, historized, True, mapping) + specificWritePermission, width, height, None, colspan, + master, masterValue, focus, historized, True, mapping) self.pythonType = bool def getDefaultLayouts(self): @@ -1389,8 +1416,8 @@ class Date(Type): show=True, page='main', group=None, layouts=None, move=0, indexed=False, searchable=False, specificReadPermission=False, specificWritePermission=False, width=None, height=None, - colspan=1, master=None, masterValue=None, focus=False, - historized=False, mapping=None): + maxChars=None, colspan=1, master=None, masterValue=None, + focus=False, historized=False, mapping=None): self.format = format self.calendar = calendar self.startYear = startYear @@ -1401,8 +1428,8 @@ class Date(Type): Type.__init__(self, validator, multiplicity, index, default, optional, editDefault, show, page, group, layouts, move, indexed, searchable, specificReadPermission, - specificWritePermission, width, height, colspan, master, - masterValue, focus, historized, True, mapping) + specificWritePermission, width, height, None, colspan, + master, masterValue, focus, historized, True, mapping) def getCss(self, layoutType): if (layoutType == 'edit') and self.calendar: @@ -1462,13 +1489,13 @@ class File(Type): page='main', group=None, layouts=None, move=0, indexed=False, searchable=False, specificReadPermission=False, specificWritePermission=False, width=None, height=None, - colspan=1, master=None, masterValue=None, focus=False, - historized=False, mapping=None, isImage=False): + maxChars=None, colspan=1, master=None, masterValue=None, + focus=False, historized=False, mapping=None, isImage=False): self.isImage = isImage Type.__init__(self, validator, multiplicity, index, default, optional, editDefault, show, page, group, layouts, move, indexed, False, specificReadPermission, specificWritePermission, - width, height, colspan, master, masterValue, focus, + width, height, None, colspan, master, masterValue, focus, historized, True, mapping) @staticmethod @@ -1612,8 +1639,8 @@ class Ref(Type): select=None, maxPerPage=30, move=0, indexed=False, searchable=False, specificReadPermission=False, specificWritePermission=False, width=None, height=5, - colspan=1, master=None, masterValue=None, focus=False, - historized=False, mapping=None, queryable=False, + maxChars=None, colspan=1, master=None, masterValue=None, + focus=False, historized=False, mapping=None, queryable=False, queryFields=None, queryNbCols=1): self.klass = klass self.attribute = attribute @@ -1663,7 +1690,7 @@ class Ref(Type): Type.__init__(self, validator, multiplicity, index, default, optional, editDefault, show, page, group, layouts, move, indexed, False, specificReadPermission, specificWritePermission, - width, height, colspan, master, masterValue, focus, + width, height, None, colspan, master, masterValue, focus, historized, sync, mapping) self.validable = self.link @@ -1829,9 +1856,9 @@ class Computed(Type): page='main', group=None, layouts=None, move=0, indexed=False, searchable=False, specificReadPermission=False, specificWritePermission=False, width=None, height=None, - colspan=1, method=None, plainText=True, master=None, - masterValue=None, focus=False, historized=False, sync=True, - mapping=None, context={}): + maxChars=None, colspan=1, method=None, plainText=True, + master=None, masterValue=None, focus=False, historized=False, + sync=True, mapping=None, context={}): # The Python method used for computing the field value self.method = method # Does field computation produce plain text or XHTML? @@ -1847,8 +1874,8 @@ class Computed(Type): Type.__init__(self, None, multiplicity, index, default, optional, False, show, page, group, layouts, move, indexed, False, specificReadPermission, specificWritePermission, width, - height, colspan, master, masterValue, focus, historized, - sync, mapping) + height, None, colspan, master, masterValue, focus, + historized, sync, mapping) self.validable = False def callMacro(self, obj, macroPath): @@ -1896,9 +1923,9 @@ class Action(Type): page='main', group=None, layouts=None, move=0, indexed=False, searchable=False, specificReadPermission=False, specificWritePermission=False, width=None, height=None, - colspan=1, action=None, result='computation', confirm=False, - master=None, masterValue=None, focus=False, historized=False, - mapping=None): + maxChars=None, colspan=1, action=None, result='computation', + confirm=False, master=None, masterValue=None, focus=False, + historized=False, mapping=None): # Can be a single method or a list/tuple of methods self.action = action # For the 'result' param: @@ -1918,8 +1945,8 @@ class Action(Type): Type.__init__(self, None, (0,1), index, default, optional, False, show, page, group, layouts, move, indexed, False, specificReadPermission, specificWritePermission, width, - height, colspan, master, masterValue, focus, historized, - False, mapping) + height, None, colspan, master, masterValue, focus, + historized, False, mapping) self.validable = False def getDefaultLayouts(self): return {'view': 'l-f', 'edit': 'lrv-f'} @@ -1966,13 +1993,13 @@ class Info(Type): page='main', group=None, layouts=None, move=0, indexed=False, searchable=False, specificReadPermission=False, specificWritePermission=False, width=None, height=None, - colspan=1, master=None, masterValue=None, focus=False, - historized=False, mapping=None): + maxChars=None, colspan=1, master=None, masterValue=None, + focus=False, historized=False, mapping=None): Type.__init__(self, None, (0,1), index, default, optional, False, show, page, group, layouts, move, indexed, False, specificReadPermission, specificWritePermission, width, - height, colspan, master, masterValue, focus, historized, - False, mapping) + height, None, colspan, master, masterValue, focus, + historized, False, mapping) self.validable = False class Pod(Type): @@ -1987,9 +2014,9 @@ class Pod(Type): page='main', group=None, layouts=None, move=0, indexed=False, searchable=False, specificReadPermission=False, specificWritePermission=False, width=None, height=None, - colspan=1, master=None, masterValue=None, focus=False, - historized=False, mapping=None, template=None, context=None, - action=None, askAction=False, stylesMapping={}, + maxChars=None, colspan=1, master=None, masterValue=None, + focus=False, historized=False, mapping=None, template=None, + context=None, action=None, askAction=False, stylesMapping={}, freezeFormat='pdf'): # The following param stores the path to a POD template self.template = template @@ -2009,8 +2036,8 @@ class Pod(Type): Type.__init__(self, None, (0,1), index, default, optional, False, show, page, group, layouts, move, indexed, searchable, specificReadPermission, - specificWritePermission, width, height, colspan, master, - masterValue, focus, historized, False, mapping) + specificWritePermission, width, height, None, colspan, + master, masterValue, focus, historized, False, mapping) self.validable = False def isFrozen(self, obj): diff --git a/gen/plone25/skin/widgets/float.pt b/gen/plone25/skin/widgets/float.pt index 9ae53a6..beddfd4 100644 --- a/gen/plone25/skin/widgets/float.pt +++ b/gen/plone25/skin/widgets/float.pt @@ -6,7 +6,8 @@ Edit macro for an Float. - @@ -16,14 +17,15 @@ Search macro for an Float. - +
   - + - +
diff --git a/gen/plone25/skin/widgets/integer.pt b/gen/plone25/skin/widgets/integer.pt index 02a11ce..c5e2437 100644 --- a/gen/plone25/skin/widgets/integer.pt +++ b/gen/plone25/skin/widgets/integer.pt @@ -5,7 +5,8 @@ Edit macro for an Integer. - @@ -15,14 +16,15 @@ Search macro for an Integer. - +
   - + - +
diff --git a/gen/plone25/skin/widgets/string.pt b/gen/plone25/skin/widgets/string.pt index 945297d..be4ba95 100644 --- a/gen/plone25/skin/widgets/string.pt +++ b/gen/plone25/skin/widgets/string.pt @@ -23,7 +23,8 @@ tal:define="fmt widget/format; isSelect widget/isSelect; isMaster widget/slaves; - isOneLine python: fmt in (0,3)"> + isOneLine python: fmt in (0,3); + maxChars python: test(widget['maxChars'], widget['maxChars'], '')"> @@ -53,8 +54,6 @@ style python: 'text-transform:%s' % widget['transform'];" tal:content="python: test(inRequest, requestValue, value)"> -
   Show a simple search field for most String fields. - Show a multi-selection box for fields whose