本文整理汇总了Python中appy.fields.Field类的典型用法代码示例。如果您正苦于以下问题:Python Field类的具体用法?Python Field怎么用?Python Field使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Field类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, validator=None, multiplicity=(0,1), default=None,
show=('view', 'result'), page='main', group=None,
layouts=None, move=0, indexed=False, searchable=False,
specificReadPermission=False, specificWritePermission=False,
width=None, height=None, 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):
# 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.
# This way, if, for example, the value is a DateTime instance which is
# indexed, you can specify in m_formatMethod the way to format it in
# the user interface while m_method computes the value stored in the
# catalog.
self.formatMethod = formatMethod
if isinstance(self.method, basestring):
# A legacy macro identifier. Raise an exception
raise Exception(self.WRONG_METHOD % self.method)
# Does field computation produce plain text or XHTML?
self.plainText = plainText
if isinstance(method, Px):
# When field computation is done with a PX, the result is XHTML.
self.plainText = False
# If method is a PX, its context can be given in p_context.
self.context = context
Field.__init__(self, None, multiplicity, default, show, page, group,
layouts, move, indexed, searchable,
specificReadPermission, specificWritePermission, width,
height, None, colspan, master, masterValue, focus,
historized, mapping, label, sdefault, scolspan, swidth,
sheight, False)
self.validable = False
示例2: __init__
def __init__(self, validator=None, default=None, show=('view', 'result'),
page='main', group=None, layouts=None, move=0, indexed=False,
searchable=False, specificReadPermission=False,
specificWritePermission=False, width=None, height=None,
maxChars=None, colspan=1, master=None, masterValue=None,
focus=False, historized=False, mapping=None, label=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
# The context is a dict containing a specific pod context, or a method
# that returns such a dict.
self.context = context
# Next one is a method that will be triggered after the document has
# been generated.
self.action = action
# If askAction is True, the action will be triggered only if the user
# checks a checkbox, which, by default, will be unchecked.
self.askAction = askAction
# A global styles mapping that would apply to the whole template
self.stylesMapping = stylesMapping
# Freeze format is by PDF by default
self.freezeFormat = freezeFormat
Field.__init__(self, None, (0,1), default, show, page, group, layouts,
move, indexed, searchable, specificReadPermission,
specificWritePermission, width, height, None, colspan,
master, masterValue, focus, historized, False, mapping,
label, None, None, None, None)
self.validable = False
示例3: __init__
def __init__(self, fields, 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='', 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):
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)
self.validable = True
# Tuples of (names, Field instances) determining the format of every
# element in the list.
self.fields = fields
# Force some layouting for sub-fields, if subLayouts are given. So the
# one who wants freedom on tuning layouts at the field level must
# specify subLayouts=None.
if subLayouts:
for name, field in self.fields:
field.layouts = field.formatLayouts(subLayouts)
# One may specify the width of every column in the list. Indeed, using
# widths and layouts of sub-fields may not be sufficient.
if not widths:
self.widths = [''] * len(self.fields)
else:
self.widths = widths
示例4: __init__
def __init__(self, validator=None, multiplicity=(1,1), default=None,
show=True, page='main', group=None, layouts=None, move=0,
indexed=False, searchable=False, specificReadPermission=False,
specificWritePermission=False, 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):
# Can be a single method or a list/tuple of methods
self.action = action
# For the 'result' param:
# * value 'computation' means that the action will simply compute
# things and redirect the user to the same page, with some status
# message about execution of the action;
# * 'file' means that the result is the binary content of a file that
# the user will download.
# * 'redirect' means that the action will lead to the user being
# redirected to some other page.
self.result = result
# If following field "confirm" is True, a popup will ask the user if
# she is really sure about triggering this action.
self.confirm = confirm
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)
self.validable = False
self.renderLabel = False # Label is rendered directly within the button.
示例5: __init__
def __init__(self, validator=None, multiplicity=(0,1), default=None,
format=WITH_HOUR, dateFormat=None, hourFormat=None,
calendar=True, startYear=time.localtime()[0]-10,
endYear=time.localtime()[0]+10, reverseYears=False,
show=True, page='main', group=None, layouts=None, move=0,
indexed=False, mustIndex=True, searchable=False,
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=None, scolspan=1, swidth=None,
sheight=None, persist=True, view=None, xml=None, showDay=True):
self.format = format
self.calendar = calendar
self.startYear = startYear
self.endYear = endYear
# If reverseYears is True, in the selection box, available years, from
# self.startYear to self.endYear will be listed in reverse order.
self.reverseYears = reverseYears
# If p_showDay is False, the list for choosing a day will be hidden.
self.showDay = showDay
# If no p_dateFormat/p_hourFormat is specified, the application-wide
# tool.dateFormat/tool.hourFormat instead.
self.dateFormat = dateFormat
self.hourFormat = hourFormat
Field.__init__(self, validator, multiplicity, default, show, page,
group, layouts, move, indexed, mustIndex, searchable,
specificReadPermission, specificWritePermission, width,
height, None, colspan, master, masterValue, focus,
historized, mapping, label, sdefault, scolspan, swidth,
sheight, persist, False, view, xml)
示例6: __init__
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=5, height=None,
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, 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.
self.precision = precision
# The decimal separator can be a tuple if several are allowed, ie
# ('.', ',')
if type(sep) not in sutils.sequenceTypes:
self.sep = (sep,)
else:
self.sep = sep
# Check that the separator(s) are among allowed decimal separators
for sep in self.sep:
if sep not in Float.allowedDecimalSeps:
raise Exception('Char "%s" is not allowed as decimal ' \
'separator.' % sep)
self.tsep = tsep
Field.__init__(self, validator, multiplicity, default, show, page,
group, layouts, move, indexed, False,
specificReadPermission, specificWritePermission, width,
height, maxChars, colspan, master, masterValue, focus,
historized, mapping, label, sdefault, scolspan, swidth,
sheight, persist)
self.pythonType = float
示例7: __init__
def __init__(self, validator=None, multiplicity=(0,1), default=None,
show='view', page='main', group=None, layouts=None, move=0,
indexed=False, searchable=False, specificReadPermission=False,
specificWritePermission=False, width=None, height=None,
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,
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?
self.plainText = plainText
if isinstance(method, basestring):
# When field computation is done with a macro, we know the result
# will be HTML.
self.plainText = False
# The context is a dict (or method returning a dict) that will be given
# to the macro specified in self.method. If the dict contains key
# "someKey", it will be available to the macro as "options/someKey".
self.context = context
Field.__init__(self, None, multiplicity, default, show, page, group,
layouts, move, indexed, searchable,
specificReadPermission, specificWritePermission, width,
height, None, colspan, master, masterValue, focus,
historized, sync, mapping, label, sdefault, scolspan,
swidth, sheight)
self.validable = False
示例8: __init__
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=5,
height=None,
maxChars=13,
colspan=1,
master=None,
masterValue=None,
focus=False,
historized=False,
mapping=None,
label=None,
sdefault=("", ""),
scolspan=1,
swidth=None,
sheight=None,
):
Field.__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,
swidth,
sheight,
)
self.pythonType = long
示例9: __init__
def __init__(self, validator=None, multiplicity=(0,1), default=None,
format=LINE, show=True, page='main', group=None, layouts=None,
move=0, indexed=False, searchable=False,
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, swidth=None, sheight=None,
transform='none', styles=('p','h1','h2','h3','h4'),
allowImageUpload=True, inlineEdit=False):
# 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
# stored in the session at some global key.
self.format = format
self.isUrl = validator == String.URL
# When format is XHTML, the list of styles that the user will be able to
# select in the styles dropdown is defined hereafter.
self.styles = styles
# When format is XHTML, do we allow the user to upload images in it ?
self.allowImageUpload = allowImageUpload
# When format in XHTML, can the field be inline-edited (ckeditor)?
self.inlineEdit = inlineEdit
# The following field has a direct impact on the text entered by the
# user. It applies a transformation on it, exactly as does the CSS
# "text-transform" property. Allowed values are those allowed for the
# CSS property: "none" (default), "uppercase", "capitalize" or
# "lowercase".
self.transform = transform
Field.__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,
swidth, sheight)
self.isSelect = self.isSelection()
# If self.isSelect, self.sdefault must be a list of value(s).
if self.isSelect and not sdefault:
self.sdefault = []
# Default width, height and maxChars vary according to String format
if width == None:
if format == String.TEXT: self.width = 60
# This width corresponds to the standard width of an Appy page.
if format == String.XHTML: self.width = None
else: self.width = 30
if height == None:
if format == String.TEXT: self.height = 5
elif self.isSelect: self.height = 4
else: self.height = 1
if maxChars == None:
if self.isSelect: pass
elif format == String.LINE: self.maxChars = 256
elif format == String.TEXT: self.maxChars = 9999
elif format == String.XHTML: self.maxChars = 99999
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
示例10: store
def store(self, obj, value):
'''Stores p_value on p_obj for this field.'''
languages = self.getAttribute(obj, 'languages')
if (len(languages) > 1) and value and \
(not isinstance(value, dict) or (len(value) != len(languages))):
raise Exception('Multilingual field "%s" accepts a dict whose '\
'keys are in field.languages and whose ' \
'values are strings.' % self.name)
Field.store(self, obj, value)
示例11: isEmptyValue
def isEmptyValue(self, obj, value):
'''Returns True if the p_value must be considered as an empty value.'''
if not self.isMultilingual(obj):
return Field.isEmptyValue(self, obj, value)
# For a multilingual value, as soon as a value is not empty for a given
# language, the whole value is considered as not being empty.
if not value: return True
for v in value.itervalues():
if not Field.isEmptyValue(self, obj, v): return
return True
示例12: __init__
def __init__(self, multiplicity=(0,1), default=None, show=None, page='main',
group=None, layouts=None, move=0, indexed=False, mustIndex=True,
searchable=False, specificReadPermission=False,
specificWritePermission=False, width=None, height=None, 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,
view=None, xml=None, unfreezable=False, validable=False):
# 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.
# This way, if, for example, the value is a DateTime instance which is
# indexed, you can specify in m_formatMethod the way to format it in
# the user interface while m_method computes the value stored in the
# catalog.
self.formatMethod = formatMethod
if isinstance(self.method, basestring):
# A legacy macro identifier. Raise an exception
raise Exception(self.WRONG_METHOD % self.method)
# Does field computation produce plain text or XHTML?
self.plainText = plainText
if isinstance(method, Px):
# When field computation is done with a PX, the result is XHTML
self.plainText = False
# Determine default value for "show"
if show == None:
# XHTML content in a Computed field generally corresponds to some
# custom XHTML widget. This is why, by default, we do not render it
# in the xml layout.
show = self.plainText and ('view', 'result', 'xml') or \
('view', 'result')
# If method is a PX, its context can be given in p_context
self.context = context
Field.__init__(self, None, multiplicity, default, show, page, group,
layouts, move, indexed, mustIndex, searchable,
specificReadPermission, specificWritePermission, width,
height, None, colspan, master, masterValue, focus,
historized, mapping, label, sdefault, scolspan, swidth,
sheight, False, False, view, xml)
# When a custom widget is built from a computed field, its values are
# potentially editable an validable, so "validable" must be True.
self.validable = validable
# One classic use case for a Computed field is to build a custom widget.
# In this case, self.method stores a PX or method that produces, on
# view or edit, the custom widget. Logically, you will need to store a
# custom data structure on obj.o, in an attribute named according to
# this field, ie self.name. Typically, you will set or update a value
# for this attribute in obj.onEdit, by getting, on the obj.request
# object, values encoded by the user in your custom widget (edit mode).
# This "custom widget" use case is incompatible with "freezing". Indeed,
# freezing a Computed field implies storing the computed value at
# obj.o.[self.name] instead of recomputing it as usual. So if you want
# to build a custom widget, specify the field as being unfreezable.
self.unfreezable = unfreezable
示例13: __init__
def __init__(self, validator=None, multiplicity=(1,1), default=None,
show='view', page='main', group=None, layouts=None, move=0,
indexed=False, searchable=False, specificReadPermission=False,
specificWritePermission=False, width=None, height=None,
maxChars=None, colspan=1, master=None, masterValue=None,
focus=False, historized=False, mapping=None, label=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)
self.validable = False
示例14: isCompleteValue
def isCompleteValue(self, obj, value):
'''Returns True if the p_value must be considered as complete. For a
unilingual field, being complete simply means not being empty. For a
multilingual field, being complete means that a value is present for
every language.'''
if not self.isMultilingual(obj):
return Field.isCompleteValue(self, obj, value)
# As soon as a given language value is empty, the global value is not
# complete.
if not value: return True
for v in value.itervalues():
if Field.isEmptyValue(self, obj, v): return
return True
示例15: getUnilingualFormattedValue
def getUnilingualFormattedValue(self, obj, value, showChanges=False,
userLanguage=None, language=None):
'''If no p_language is specified, this method is called by
m_getFormattedValue for getting a non-multilingual value (ie, in
most cases). Else, this method returns a formatted value for the
p_language-specific part of a multilingual value.'''
if Field.isEmptyValue(self, obj, value): return ''
res = value
if self.isSelect:
if isinstance(self.validator, Selection):
# Value(s) come from a dynamic vocabulary
val = self.validator
if self.isMultiValued():
return [val.getText(obj, v, self, language=userLanguage) \
for v in value]
else:
return val.getText(obj, value, self, language=userLanguage)
else:
# Value(s) come from a fixed vocabulary whose texts are in
# i18n files.
_ = obj.translate
if self.isMultiValued():
res = [_('%s_list_%s' % (self.labelId, v), \
language=userLanguage) for v in value]
else:
res = _('%s_list_%s' % (self.labelId, value), \
language=userLanguage)
elif (self.format == String.XHTML) and showChanges:
# Compute the successive changes that occurred on p_value.
res = self.getDiffValue(obj, res, language)
# If value starts with a carriage return, add a space; else, it will
# be ignored.
if isinstance(res, basestring) and \
(res.startswith('\n') or res.startswith('\r\n')): res = ' ' + res
return res