From e01615476b763254d73979fc0a955449535e55a7 Mon Sep 17 00:00:00 2001 From: Gaetan Delannay Date: Tue, 9 Dec 2014 15:19:28 +0100 Subject: [PATCH] [gen] Added attribute Field.view allowing to specify, for any field, an alternative pxView. --- fields/__init__.py | 19 ++++++++++++------- fields/action.py | 4 ++-- fields/boolean.py | 4 ++-- fields/calendar.py | 4 ++-- fields/computed.py | 5 +++-- fields/date.py | 4 ++-- fields/file.py | 4 ++-- fields/float.py | 4 ++-- fields/info.py | 4 ++-- fields/integer.py | 4 ++-- fields/list.py | 5 +++-- fields/ogone.py | 4 ++-- fields/pod.py | 4 ++-- fields/ref.py | 4 ++-- fields/string.py | 4 ++-- gen/mixins/__init__.py | 2 ++ gen/wrappers/__init__.py | 2 +- 17 files changed, 45 insertions(+), 36 deletions(-) diff --git a/fields/__init__.py b/fields/__init__.py index 7c0a886..49c4bff 100644 --- a/fields/__init__.py +++ b/fields/__init__.py @@ -97,27 +97,27 @@ class Field: context[k] = ctx[k] return self.pxRender(context).encode('utf-8') - # Displays a field label. + # Displays a field label pxLabel = Px('''''') - # Displays a field description. + # Displays a field description pxDescription = Px('''::_('descr', field=field)''') - # Displays a field help. + # Displays a field help pxHelp = Px('''''') - # Displays validation-error-related info about a field. + # Displays validation-error-related info about a field pxValidation = Px('''''') - # Displays the fact that a field is required. + # Displays the fact that a field is required pxRequired = Px('''''') - # Button for showing changes to the field. + # Button for showing changes to the field pxChanges = Px(''' @@ -141,7 +141,7 @@ class Field: layouts, move, indexed, searchable, specificReadPermission, specificWritePermission, width, height, maxChars, colspan, master, masterValue, focus, historized, mapping, label, - sdefault, scolspan, swidth, sheight, persist, xml): + sdefault, scolspan, swidth, sheight, persist, view, xml): # 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. @@ -250,6 +250,11 @@ class Field: # For some fields it is not wanted (ie, fields used only as masters to # update slave's selectable values). self.persist = persist + # If you want to use an alternate PX than Field.pxView, you can specify + # it in "view". + if view != None: + # This instance attribute will override the class attribute + self.pxView = view # Standard marshallers are provided for converting values of this field # into XML. If you want to customize the marshalling process, you can # define a method in "xml" that will accept a field value and will diff --git a/fields/action.py b/fields/action.py index ff31b36..94bd0c9 100644 --- a/fields/action.py +++ b/fields/action.py @@ -59,7 +59,7 @@ class Action(Field): width=None, height=None, maxChars=None, colspan=1, action=None, result='computation', confirm=False, master=None, masterValue=None, focus=False, historized=False, mapping=None, - label=None, icon=None, xml=None): + label=None, icon=None, view=None, xml=None): # Can be a single method or a list/tuple of methods self.action = action # For the 'result' param: @@ -80,7 +80,7 @@ class Action(Field): move, indexed, False, specificReadPermission, specificWritePermission, width, height, None, colspan, master, masterValue, focus, historized, mapping, label, - None, None, None, None, False, xml) + None, None, None, None, False, view, xml) self.validable = False self.renderLabel = False # Label is rendered directly within the button diff --git a/fields/boolean.py b/fields/boolean.py index 93cb66e..c26a2e9 100644 --- a/fields/boolean.py +++ b/fields/boolean.py @@ -84,7 +84,7 @@ class Boolean(Field): maxChars=None, colspan=1, master=None, masterValue=None, focus=False, historized=False, mapping=None, label=None, sdefault=False, scolspan=1, swidth=None, sheight=None, - persist=True, render='checkbox', xml=None): + persist=True, render='checkbox', view=None, xml=None): # By default, a boolean is edited via a checkbox. It can also be edited # via 2 radio buttons (p_render="radios"). self.render = render @@ -93,7 +93,7 @@ class Boolean(Field): specificReadPermission, specificWritePermission, width, height, None, colspan, master, masterValue, focus, historized, mapping, label, sdefault, scolspan, swidth, - sheight, persist, xml) + sheight, persist, view, xml) self.pythonType = bool def getDefaultLayouts(self): diff --git a/fields/calendar.py b/fields/calendar.py index 13d7907..b73d39d 100644 --- a/fields/calendar.py +++ b/fields/calendar.py @@ -217,12 +217,12 @@ class Calendar(Field): mapping=None, label=None, maxEventLength=50, otherCalendars=None, additionalInfo=None, startDate=None, endDate=None, defaultDate=None, preCompute=None, - applicableEvents=None, xml=None): + applicableEvents=None, view=None, xml=None): Field.__init__(self, validator, (0,1), default, show, page, group, layouts, move, False, False, specificReadPermission, specificWritePermission, width, height, None, colspan, master, masterValue, focus, False, mapping, label, None, - None, None, None, True, xml) + None, None, None, True, view, xml) # 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/fields/computed.py b/fields/computed.py index 3af4d96..ef18833 100644 --- a/fields/computed.py +++ b/fields/computed.py @@ -37,7 +37,8 @@ class Computed(Field): maxChars=None, colspan=1, method=None, formatMethod=None, plainText=False, master=None, masterValue=None, focus=False, historized=False, mapping=None, label=None, sdefault='', - scolspan=1, swidth=None, sheight=None, context=None, xml=None): + scolspan=1, swidth=None, sheight=None, context=None, view=None, + xml=None): # The Python method used for computing the field value, or a PX. self.method = method # A specific method for producing the formatted value of this field. @@ -68,7 +69,7 @@ class Computed(Field): specificReadPermission, specificWritePermission, width, height, None, colspan, master, masterValue, focus, historized, mapping, label, sdefault, scolspan, swidth, - sheight, False, xml) + sheight, False, view, xml) self.validable = False def getValue(self, obj): diff --git a/fields/date.py b/fields/date.py index f9f3214..3c14d0d 100644 --- a/fields/date.py +++ b/fields/date.py @@ -170,7 +170,7 @@ class Date(Field): maxChars=None, colspan=1, master=None, masterValue=None, focus=False, historized=False, mapping=None, label=None, sdefault=None, scolspan=1, swidth=None, sheight=None, - persist=True, xml=None): + persist=True, view=None, xml=None): self.format = format self.calendar = calendar self.startYear = startYear @@ -183,7 +183,7 @@ class Date(Field): specificReadPermission, specificWritePermission, width, height, None, colspan, master, masterValue, focus, historized, mapping, label, sdefault, scolspan, swidth, - sheight, persist, xml) + sheight, persist, view, xml) def getCss(self, layoutType, res): # CSS files are only required if the calendar must be shown. diff --git a/fields/file.py b/fields/file.py index 457f6c4..15baa68 100644 --- a/fields/file.py +++ b/fields/file.py @@ -349,14 +349,14 @@ class File(Field): maxChars=None, colspan=1, master=None, masterValue=None, focus=False, historized=False, mapping=None, label=None, isImage=False, sdefault='', scolspan=1, swidth=None, - sheight=None, xml=None): + sheight=None, view=None, xml=None): self.isImage = isImage Field.__init__(self, validator, multiplicity, default, show, page, group, layouts, move, indexed, False, specificReadPermission, specificWritePermission, width, height, None, colspan, master, masterValue, focus, historized, mapping, label, sdefault, scolspan, swidth, - sheight, True, xml) + sheight, True, view, xml) def getRequestValue(self, obj, requestName=None): name = requestName or self.name diff --git a/fields/float.py b/fields/float.py index 0908851..c9a7a86 100644 --- a/fields/float.py +++ b/fields/float.py @@ -57,7 +57,7 @@ class Float(Field): focus=False, historized=False, mapping=None, label=None, sdefault=('',''), scolspan=1, swidth=None, sheight=None, persist=True, precision=None, sep=(',', '.'), tsep=' ', - xml=None): + view=None, xml=None): # The precision is the number of decimal digits. This number is used # for rendering the float, but the internal float representation is not # rounded. @@ -79,7 +79,7 @@ class Float(Field): specificReadPermission, specificWritePermission, width, height, maxChars, colspan, master, masterValue, focus, historized, mapping, label, sdefault, scolspan, swidth, - sheight, persist, xml) + sheight, persist, view, xml) self.pythonType = float def getFormattedValue(self, obj, value, showChanges=False, language=None): diff --git a/fields/info.py b/fields/info.py index 2684f47..4de8355 100644 --- a/fields/info.py +++ b/fields/info.py @@ -30,11 +30,11 @@ class Info(Field): specificWritePermission=False, width=None, height=None, maxChars=None, colspan=1, master=None, masterValue=None, focus=False, historized=False, mapping=None, label=None, - xml=None): + view=None, xml=None): Field.__init__(self, None, (0,1), default, show, page, group, layouts, move, indexed, False, specificReadPermission, specificWritePermission, width, height, None, colspan, master, masterValue, focus, historized, mapping, label, - None, None, None, None, False, xml) + None, None, None, None, False, view, xml) self.validable = False # ------------------------------------------------------------------------------ diff --git a/fields/integer.py b/fields/integer.py index a8e7945..322a4e0 100644 --- a/fields/integer.py +++ b/fields/integer.py @@ -53,13 +53,13 @@ class Integer(Field): maxChars=13, colspan=1, master=None, masterValue=None, focus=False, historized=False, mapping=None, label=None, sdefault=('',''), scolspan=1, swidth=None, sheight=None, - persist=True, xml=None): + persist=True, view=None, xml=None): Field.__init__(self, validator, multiplicity, default, show, page, group, layouts, move, indexed, searchable, specificReadPermission, specificWritePermission, width, height, maxChars, colspan, master, masterValue, focus, historized, mapping, label, sdefault, scolspan, swidth, - sheight, persist, xml) + sheight, persist, view, xml) self.pythonType = long def validateValue(self, obj, value): diff --git a/fields/list.py b/fields/list.py index d612f85..279c3da 100644 --- a/fields/list.py +++ b/fields/list.py @@ -78,13 +78,14 @@ class List(Field): specificWritePermission=False, width='', height=None, maxChars=None, colspan=1, master=None, masterValue=None, focus=False, historized=False, mapping=None, label=None, - subLayouts=Table('frv', width=None), widths=None, xml=None): + subLayouts=Table('frv', width=None), widths=None, view=None, + xml=None): Field.__init__(self, validator, multiplicity, default, show, page, group, layouts, move, indexed, False, specificReadPermission, specificWritePermission, width, height, None, colspan, master, masterValue, focus, historized, mapping, label, None, None, None, None, - True, xml) + True, view, xml) self.validable = True # Tuples of (names, Field instances) determining the format of every # element in the list. diff --git a/fields/ogone.py b/fields/ogone.py index c337a09..d3a4ff7 100644 --- a/fields/ogone.py +++ b/fields/ogone.py @@ -49,12 +49,12 @@ class Ogone(Field): group=None, layouts=None, move=0, specificReadPermission=False, specificWritePermission=False, width=None, height=None, colspan=1, master=None, masterValue=None, focus=False, - mapping=None, label=None, xml=None): + mapping=None, label=None, view=None, xml=None): Field.__init__(self, None, (0,1), None, show, page, group, layouts, move, False, False,specificReadPermission, specificWritePermission, width, height, None, colspan, master, masterValue, focus, False, mapping, label, None, - None, None, None, False, xml) + None, None, None, False, view, xml) # 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/fields/pod.py b/fields/pod.py index 2f2e0c8..5fcea6f 100644 --- a/fields/pod.py +++ b/fields/pod.py @@ -159,7 +159,7 @@ class Pod(Field): freezeTemplate=None, maxPerRow=5, context=None, stylesMapping={}, formats=None, getChecked=None, mailing=None, mailingName=None, showMailing=None, mailingInfo=None, - xml=None): + view=None, xml=None): # Param "template" stores the path to the pod template(s). If there is # a single template, a string is expected. Else, a list or tuple of # strings is expected. Every such path must be relative to your @@ -276,7 +276,7 @@ class Pod(Field): move, indexed, searchable, specificReadPermission, specificWritePermission, width, height, None, colspan, master, masterValue, focus, historized, mapping, label, - None, None, None, None, True, xml) + None, None, None, None, True, view, xml) # Param "persist" is set to True but actually, persistence for a pod # field is determined by freezing. self.validable = False diff --git a/fields/ref.py b/fields/ref.py index 1468c65..f91c348 100644 --- a/fields/ref.py +++ b/fields/ref.py @@ -528,7 +528,7 @@ class Ref(Field): checkboxes=True, checkboxesDefault=None, sdefault='', scolspan=1, swidth=None, sheight=None, sselect=None, persist=True, render='list', menuIdMethod=None, - menuInfoMethod=None, menuUrlMethod=None, xml=None): + menuInfoMethod=None, menuUrlMethod=None, view=None, xml=None): self.klass = klass self.attribute = attribute # May the user add new objects through this ref ? "add" may also contain @@ -714,7 +714,7 @@ class Ref(Field): specificReadPermission, specificWritePermission, width, height, None, colspan, master, masterValue, focus, historized, mapping, label, sdefault, scolspan, swidth, - sheight, persist, xml) + sheight, persist, view, xml) self.validable = bool(self.link) self.checkParameters() diff --git a/fields/string.py b/fields/string.py index 8600fc0..97d4acb 100644 --- a/fields/string.py +++ b/fields/string.py @@ -381,7 +381,7 @@ class String(Field): persist=True, transform='none', placeholder=None, styles=('p','h1','h2','h3','h4'), allowImageUpload=True, spellcheck=False, languages=('en',), languagesLayouts=None, - inlineEdit=False, xml=None): + inlineEdit=False, view=None, xml=None): # According to format, the widget will be different: input field, # textarea, inline editor... Note that there can be only one String # field of format CAPTCHA by page, because the captcha challenge is @@ -425,7 +425,7 @@ class String(Field): specificReadPermission, specificWritePermission, width, height, maxChars, colspan, master, masterValue, focus, historized, mapping, label, sdefault, scolspan, swidth, - sheight, persist, xml) + sheight, persist, view, xml) self.isSelect = self.isSelection() # If self.isSelect, self.sdefault must be a list of value(s). if self.isSelect and not sdefault: diff --git a/gen/mixins/__init__.py b/gen/mixins/__init__.py index af9121a..9e10a2d 100644 --- a/gen/mixins/__init__.py +++ b/gen/mixins/__init__.py @@ -533,6 +533,8 @@ class BaseMixin: except Exception, e: tb = sutils.Traceback.get() res = XmlMarshaller(rootTag='exception').marshall(tb) + import transaction + transaction.abort() return res def say(self, msg, type='info'): diff --git a/gen/wrappers/__init__.py b/gen/wrappers/__init__.py index 2fb965b..3f9dbbd 100644 --- a/gen/wrappers/__init__.py +++ b/gen/wrappers/__init__.py @@ -553,7 +553,7 @@ class AbstractWrapper(object): ''') - # Displays the fields of a given page for a given object. + # Display the fields of a given page for a given object pxFields = Px('''