[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] context[k] = ctx[k]
return self.pxRender(context).encode('utf-8') return self.pxRender(context).encode('utf-8')
# Displays a field label. # Displays a field label
pxLabel = Px('''<label if="field.hasLabel and field.renderLabel" pxLabel = Px('''<label if="field.hasLabel and field.renderLabel"
lfor=":field.name">::_('label', field=field)</label>''') lfor=":field.name">::_('label', field=field)</label>''')
# Displays a field description. # Displays a field description
pxDescription = Px('''<span if="field.hasDescr" pxDescription = Px('''<span if="field.hasDescr"
class="discreet">::_('descr', field=field)</span>''') class="discreet">::_('descr', field=field)</span>''')
# Displays a field help. # Displays a field help
pxHelp = Px('''<acronym title=":_('help', field=field)"><img pxHelp = Px('''<acronym title=":_('help', field=field)"><img
src=":url('help')"/></acronym>''') 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 pxValidation = Px('''<x><acronym if="error" title=":error"><img
src=":url('warning')"/></acronym><img if="not error" src=":url('warning')"/></acronym><img if="not error"
src=":url('warning_no.gif')"/></x>''') 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')"/>''') pxRequired = Px('''<img src=":url('required.gif')"/>''')
# Button for showing changes to the field. # Button for showing changes to the field
pxChanges = Px(''' pxChanges = Px('''
<x if="zobj.hasHistory(name)"> <x if="zobj.hasHistory(name)">
<!-- Button for showing the field version containing changes --> <!-- Button for showing the field version containing changes -->
@ -141,7 +141,7 @@ class Field:
layouts, move, indexed, searchable, specificReadPermission, layouts, move, indexed, searchable, specificReadPermission,
specificWritePermission, width, height, maxChars, colspan, specificWritePermission, width, height, maxChars, colspan,
master, masterValue, focus, historized, mapping, label, 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 # The validator restricts which values may be defined. It can be an
# interval (1,None), a list of string values ['choice1', 'choice2'], # interval (1,None), a list of string values ['choice1', 'choice2'],
# a regular expression, a custom function, a Selection instance, etc. # 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 # For some fields it is not wanted (ie, fields used only as masters to
# update slave's selectable values). # update slave's selectable values).
self.persist = persist 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 # Standard marshallers are provided for converting values of this field
# into XML. If you want to customize the marshalling process, you can # 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 # 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, width=None, height=None, maxChars=None, colspan=1, action=None,
result='computation', confirm=False, master=None, result='computation', confirm=False, master=None,
masterValue=None, focus=False, historized=False, mapping=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 # Can be a single method or a list/tuple of methods
self.action = action self.action = action
# For the 'result' param: # For the 'result' param:
@ -80,7 +80,7 @@ class Action(Field):
move, indexed, False, specificReadPermission, move, indexed, False, specificReadPermission,
specificWritePermission, width, height, None, colspan, specificWritePermission, width, height, None, colspan,
master, masterValue, focus, historized, mapping, label, master, masterValue, focus, historized, mapping, label,
None, None, None, None, False, xml) None, None, None, None, False, view, xml)
self.validable = False self.validable = False
self.renderLabel = False # Label is rendered directly within the button 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, maxChars=None, colspan=1, master=None, masterValue=None,
focus=False, historized=False, mapping=None, label=None, focus=False, historized=False, mapping=None, label=None,
sdefault=False, scolspan=1, swidth=None, sheight=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 # By default, a boolean is edited via a checkbox. It can also be edited
# via 2 radio buttons (p_render="radios"). # via 2 radio buttons (p_render="radios").
self.render = render self.render = render
@ -93,7 +93,7 @@ class Boolean(Field):
specificReadPermission, specificWritePermission, width, specificReadPermission, specificWritePermission, width,
height, None, colspan, master, masterValue, focus, height, None, colspan, master, masterValue, focus,
historized, mapping, label, sdefault, scolspan, swidth, historized, mapping, label, sdefault, scolspan, swidth,
sheight, persist, xml) sheight, persist, view, xml)
self.pythonType = bool self.pythonType = bool
def getDefaultLayouts(self): def getDefaultLayouts(self):

View file

@ -217,12 +217,12 @@ class Calendar(Field):
mapping=None, label=None, maxEventLength=50, mapping=None, label=None, maxEventLength=50,
otherCalendars=None, additionalInfo=None, startDate=None, otherCalendars=None, additionalInfo=None, startDate=None,
endDate=None, defaultDate=None, preCompute=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, Field.__init__(self, validator, (0,1), default, show, page, group,
layouts, move, False, False, specificReadPermission, layouts, move, False, False, specificReadPermission,
specificWritePermission, width, height, None, colspan, specificWritePermission, width, height, None, colspan,
master, masterValue, focus, False, mapping, label, None, 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 # 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 # 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 # 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, maxChars=None, colspan=1, method=None, formatMethod=None,
plainText=False, master=None, masterValue=None, focus=False, plainText=False, master=None, masterValue=None, focus=False,
historized=False, mapping=None, label=None, sdefault='', 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. # The Python method used for computing the field value, or a PX.
self.method = method self.method = method
# A specific method for producing the formatted value of this field. # A specific method for producing the formatted value of this field.
@ -68,7 +69,7 @@ class Computed(Field):
specificReadPermission, specificWritePermission, width, specificReadPermission, specificWritePermission, width,
height, None, colspan, master, masterValue, focus, height, None, colspan, master, masterValue, focus,
historized, mapping, label, sdefault, scolspan, swidth, historized, mapping, label, sdefault, scolspan, swidth,
sheight, False, xml) sheight, False, view, xml)
self.validable = False self.validable = False
def getValue(self, obj): def getValue(self, obj):

View file

@ -170,7 +170,7 @@ class Date(Field):
maxChars=None, colspan=1, master=None, masterValue=None, maxChars=None, colspan=1, master=None, masterValue=None,
focus=False, historized=False, mapping=None, label=None, focus=False, historized=False, mapping=None, label=None,
sdefault=None, scolspan=1, swidth=None, sheight=None, sdefault=None, scolspan=1, swidth=None, sheight=None,
persist=True, xml=None): persist=True, view=None, xml=None):
self.format = format self.format = format
self.calendar = calendar self.calendar = calendar
self.startYear = startYear self.startYear = startYear
@ -183,7 +183,7 @@ class Date(Field):
specificReadPermission, specificWritePermission, width, specificReadPermission, specificWritePermission, width,
height, None, colspan, master, masterValue, focus, height, None, colspan, master, masterValue, focus,
historized, mapping, label, sdefault, scolspan, swidth, historized, mapping, label, sdefault, scolspan, swidth,
sheight, persist, xml) sheight, persist, view, xml)
def getCss(self, layoutType, res): def getCss(self, layoutType, res):
# CSS files are only required if the calendar must be shown. # 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, maxChars=None, colspan=1, master=None, masterValue=None,
focus=False, historized=False, mapping=None, label=None, focus=False, historized=False, mapping=None, label=None,
isImage=False, sdefault='', scolspan=1, swidth=None, isImage=False, sdefault='', scolspan=1, swidth=None,
sheight=None, xml=None): sheight=None, view=None, xml=None):
self.isImage = isImage self.isImage = isImage
Field.__init__(self, validator, multiplicity, default, show, page, Field.__init__(self, validator, multiplicity, default, show, page,
group, layouts, move, indexed, False, group, layouts, move, indexed, False,
specificReadPermission, specificWritePermission, width, specificReadPermission, specificWritePermission, width,
height, None, colspan, master, masterValue, focus, height, None, colspan, master, masterValue, focus,
historized, mapping, label, sdefault, scolspan, swidth, historized, mapping, label, sdefault, scolspan, swidth,
sheight, True, xml) sheight, True, view, xml)
def getRequestValue(self, obj, requestName=None): def getRequestValue(self, obj, requestName=None):
name = requestName or self.name name = requestName or self.name

View file

@ -57,7 +57,7 @@ class Float(Field):
focus=False, historized=False, mapping=None, label=None, focus=False, historized=False, mapping=None, label=None,
sdefault=('',''), scolspan=1, swidth=None, sheight=None, sdefault=('',''), scolspan=1, swidth=None, sheight=None,
persist=True, precision=None, sep=(',', '.'), tsep=' ', persist=True, precision=None, sep=(',', '.'), tsep=' ',
xml=None): view=None, xml=None):
# The precision is the number of decimal digits. This number is used # The precision is the number of decimal digits. This number is used
# for rendering the float, but the internal float representation is not # for rendering the float, but the internal float representation is not
# rounded. # rounded.
@ -79,7 +79,7 @@ class Float(Field):
specificReadPermission, specificWritePermission, width, specificReadPermission, specificWritePermission, width,
height, maxChars, colspan, master, masterValue, focus, height, maxChars, colspan, master, masterValue, focus,
historized, mapping, label, sdefault, scolspan, swidth, historized, mapping, label, sdefault, scolspan, swidth,
sheight, persist, xml) sheight, persist, view, xml)
self.pythonType = float self.pythonType = float
def getFormattedValue(self, obj, value, showChanges=False, language=None): def getFormattedValue(self, obj, value, showChanges=False, language=None):

View file

@ -30,11 +30,11 @@ class Info(Field):
specificWritePermission=False, width=None, height=None, specificWritePermission=False, width=None, height=None,
maxChars=None, colspan=1, master=None, masterValue=None, maxChars=None, colspan=1, master=None, masterValue=None,
focus=False, historized=False, mapping=None, label=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, Field.__init__(self, None, (0,1), default, show, page, group, layouts,
move, indexed, False, specificReadPermission, move, indexed, False, specificReadPermission,
specificWritePermission, width, height, None, colspan, specificWritePermission, width, height, None, colspan,
master, masterValue, focus, historized, mapping, label, master, masterValue, focus, historized, mapping, label,
None, None, None, None, False, xml) None, None, None, None, False, view, xml)
self.validable = False self.validable = False
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------

View file

@ -53,13 +53,13 @@ class Integer(Field):
maxChars=13, colspan=1, master=None, masterValue=None, maxChars=13, colspan=1, master=None, masterValue=None,
focus=False, historized=False, mapping=None, label=None, focus=False, historized=False, mapping=None, label=None,
sdefault=('',''), scolspan=1, swidth=None, sheight=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, Field.__init__(self, validator, multiplicity, default, show, page,
group, layouts, move, indexed, searchable, group, layouts, move, indexed, searchable,
specificReadPermission, specificWritePermission, width, specificReadPermission, specificWritePermission, width,
height, maxChars, colspan, master, masterValue, focus, height, maxChars, colspan, master, masterValue, focus,
historized, mapping, label, sdefault, scolspan, swidth, historized, mapping, label, sdefault, scolspan, swidth,
sheight, persist, xml) sheight, persist, view, xml)
self.pythonType = long self.pythonType = long
def validateValue(self, obj, value): def validateValue(self, obj, value):

View file

@ -78,13 +78,14 @@ class List(Field):
specificWritePermission=False, width='', height=None, specificWritePermission=False, width='', height=None,
maxChars=None, colspan=1, master=None, masterValue=None, maxChars=None, colspan=1, master=None, masterValue=None,
focus=False, historized=False, mapping=None, label=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, Field.__init__(self, validator, multiplicity, default, show, page,
group, layouts, move, indexed, False, group, layouts, move, indexed, False,
specificReadPermission, specificWritePermission, width, specificReadPermission, specificWritePermission, width,
height, None, colspan, master, masterValue, focus, height, None, colspan, master, masterValue, focus,
historized, mapping, label, None, None, None, None, historized, mapping, label, None, None, None, None,
True, xml) True, view, xml)
self.validable = True self.validable = True
# Tuples of (names, Field instances) determining the format of every # Tuples of (names, Field instances) determining the format of every
# element in the list. # element in the list.

View file

@ -49,12 +49,12 @@ class Ogone(Field):
group=None, layouts=None, move=0, specificReadPermission=False, group=None, layouts=None, move=0, specificReadPermission=False,
specificWritePermission=False, width=None, height=None, specificWritePermission=False, width=None, height=None,
colspan=1, master=None, masterValue=None, focus=False, 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, Field.__init__(self, None, (0,1), None, show, page, group, layouts,
move, False, False,specificReadPermission, move, False, False,specificReadPermission,
specificWritePermission, width, height, None, colspan, specificWritePermission, width, height, None, colspan,
master, masterValue, focus, False, mapping, label, None, 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 # orderMethod must contain a method returning a dict containing info
# about the order. Following keys are mandatory: # about the order. Following keys are mandatory:
# * orderID An identifier for the order. Don't use the object UID # * 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, freezeTemplate=None, maxPerRow=5, context=None,
stylesMapping={}, formats=None, getChecked=None, mailing=None, stylesMapping={}, formats=None, getChecked=None, mailing=None,
mailingName=None, showMailing=None, mailingInfo=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 # 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 # a single template, a string is expected. Else, a list or tuple of
# strings is expected. Every such path must be relative to your # strings is expected. Every such path must be relative to your
@ -276,7 +276,7 @@ class Pod(Field):
move, indexed, searchable, specificReadPermission, move, indexed, searchable, specificReadPermission,
specificWritePermission, width, height, None, colspan, specificWritePermission, width, height, None, colspan,
master, masterValue, focus, historized, mapping, label, 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 # Param "persist" is set to True but actually, persistence for a pod
# field is determined by freezing. # field is determined by freezing.
self.validable = False self.validable = False

View file

@ -528,7 +528,7 @@ class Ref(Field):
checkboxes=True, checkboxesDefault=None, sdefault='', checkboxes=True, checkboxesDefault=None, sdefault='',
scolspan=1, swidth=None, sheight=None, sselect=None, scolspan=1, swidth=None, sheight=None, sselect=None,
persist=True, render='list', menuIdMethod=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.klass = klass
self.attribute = attribute self.attribute = attribute
# May the user add new objects through this ref ? "add" may also contain # May the user add new objects through this ref ? "add" may also contain
@ -714,7 +714,7 @@ class Ref(Field):
specificReadPermission, specificWritePermission, width, specificReadPermission, specificWritePermission, width,
height, None, colspan, master, masterValue, focus, height, None, colspan, master, masterValue, focus,
historized, mapping, label, sdefault, scolspan, swidth, historized, mapping, label, sdefault, scolspan, swidth,
sheight, persist, xml) sheight, persist, view, xml)
self.validable = bool(self.link) self.validable = bool(self.link)
self.checkParameters() self.checkParameters()

View file

@ -381,7 +381,7 @@ class String(Field):
persist=True, transform='none', placeholder=None, persist=True, transform='none', placeholder=None,
styles=('p','h1','h2','h3','h4'), allowImageUpload=True, styles=('p','h1','h2','h3','h4'), allowImageUpload=True,
spellcheck=False, languages=('en',), languagesLayouts=None, 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, # According to format, the widget will be different: input field,
# textarea, inline editor... Note that there can be only one String # textarea, inline editor... Note that there can be only one String
# field of format CAPTCHA by page, because the captcha challenge is # field of format CAPTCHA by page, because the captcha challenge is
@ -425,7 +425,7 @@ class String(Field):
specificReadPermission, specificWritePermission, width, specificReadPermission, specificWritePermission, width,
height, maxChars, colspan, master, masterValue, focus, height, maxChars, colspan, master, masterValue, focus,
historized, mapping, label, sdefault, scolspan, swidth, historized, mapping, label, sdefault, scolspan, swidth,
sheight, persist, xml) sheight, persist, view, xml)
self.isSelect = self.isSelection() self.isSelect = self.isSelection()
# If self.isSelect, self.sdefault must be a list of value(s). # If self.isSelect, self.sdefault must be a list of value(s).
if self.isSelect and not sdefault: if self.isSelect and not sdefault:

View file

@ -533,6 +533,8 @@ class BaseMixin:
except Exception, e: except Exception, e:
tb = sutils.Traceback.get() tb = sutils.Traceback.get()
res = XmlMarshaller(rootTag='exception').marshall(tb) res = XmlMarshaller(rootTag='exception').marshall(tb)
import transaction
transaction.abort()
return res return res
def say(self, msg, type='info'): def say(self, msg, type='info'):

View file

@ -553,7 +553,7 @@ class AbstractWrapper(object):
</x> </x>
</div>''') </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(''' pxFields = Px('''
<table width=":layout.width"> <table width=":layout.width">
<tr for="field in groupedFields"> <tr for="field in groupedFields">