[gen] Added attribute Field.view allowing to specify, for any field, an alternative pxView.

This commit is contained in:
Gaetan Delannay 2014-12-09 15:19:28 +01:00
parent 186175250d
commit e01615476b
17 changed files with 45 additions and 36 deletions

View file

@ -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('''<label if="field.hasLabel and field.renderLabel"
lfor=":field.name">::_('label', field=field)</label>''')
# Displays a field description.
# Displays a field description
pxDescription = Px('''<span if="field.hasDescr"
class="discreet">::_('descr', field=field)</span>''')
# Displays a field help.
# Displays a field help
pxHelp = Px('''<acronym title=":_('help', field=field)"><img
src=":url('help')"/></acronym>''')
# Displays validation-error-related info about a field.
# Displays validation-error-related info about a field
pxValidation = Px('''<x><acronym if="error" title=":error"><img
src=":url('warning')"/></acronym><img if="not error"
src=":url('warning_no.gif')"/></x>''')
# Displays the fact that a field is required.
# Displays the fact that a field is required
pxRequired = Px('''<img src=":url('required.gif')"/>''')
# Button for showing changes to the field.
# Button for showing changes to the field
pxChanges = Px('''
<x if="zobj.hasHistory(name)">
<!-- Button for showing the field version containing changes -->
@ -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

View file

@ -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

View file

@ -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):

View file

@ -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

View file

@ -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):

View file

@ -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.

View file

@ -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

View file

@ -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):

View file

@ -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
# ------------------------------------------------------------------------------

View file

@ -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):

View file

@ -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.

View file

@ -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

View file

@ -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

View file

@ -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()

View file

@ -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:

View file

@ -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'):

View file

@ -553,7 +553,7 @@ class AbstractWrapper(object):
</x>
</div>''')
# Displays the fields of a given page for a given object.
# Display the fields of a given page for a given object
pxFields = Px('''
<table width=":layout.width">
<tr for="field in groupedFields">