Beispiel #1
0
 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)
Beispiel #2
0
 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
Beispiel #3
0
 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
Beispiel #4
0
 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=None,
              height=None,
              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):
     Field.__init__(self, validator, 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, persist)
     self.pythonType = bool
Beispiel #5
0
 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
Beispiel #6
0
 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
Beispiel #7
0
 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
Beispiel #8
0
 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, False, mapping,
                    label, None, None, None, None)
     self.validable = False
Beispiel #9
0
 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
Beispiel #10
0
 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.
Beispiel #11
0
 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
Beispiel #12
0
 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)
Beispiel #13
0
 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)
Beispiel #14
0
 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
Beispiel #15
0
 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
Beispiel #16
0
 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
Beispiel #17
0
 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
Beispiel #18
0
 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
Beispiel #19
0
 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
Beispiel #20
0
 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
Beispiel #21
0
 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
Beispiel #22
0
 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
Beispiel #23
0
 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
Beispiel #24
0
 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
Beispiel #25
0
 def valueIsInRequest(self, obj, request, name):
     languages = self.getAttribute(obj, 'languages')
     if len(languages) == 1:
         return Field.valueIsInRequest(self, obj, request, name)
     # Is is sufficient to check that at least one of the language-specific
     # values is in the request.
     return request.has_key('%s_%s' % (name, languages[0]))
Beispiel #26
0
 def valueIsInRequest(self, obj, request, name):
     languages = self.getAttribute(obj, 'languages')
     if len(languages) == 1:
         return Field.valueIsInRequest(self, obj, request, name)
     # Is is sufficient to check that at least one of the language-specific
     # values is in the request.
     return request.has_key('%s_%s' % (name, languages[0]))
Beispiel #27
0
    def getValue(self,
                 obj,
                 type='objects',
                 noListIfSingleObj=False,
                 startNumber=None,
                 someObjects=False):
        '''Returns the objects linked to p_obj through this Ref field.
           - If p_type is "objects",  it returns the Appy wrappers;
           - If p_type is "zobjects", it returns the Zope objects;
           - If p_type is "uids",     it returns UIDs of objects (= strings).

           * If p_startNumber is None, it returns all referred objects.
           * If p_startNumber is a number, it returns self.maxPerPage objects,
             starting at p_startNumber.

           If p_noListIfSingleObj is True, it returns the single reference as
           an object and not as a list.

           If p_someObjects is True, it returns an instance of SomeObjects
           instead of returning a list of references.'''
        uids = getattr(obj.aq_base, self.name, [])
        if not uids:
            # Maybe is there a default value?
            defValue = Field.getValue(self, obj)
            if defValue:
                # I must prefix call to function "type" with "__builtins__"
                # because this name was overridden by a method parameter.
                if __builtins__['type'](defValue) in sutils.sequenceTypes:
                    uids = [o.o.UID() for o in defValue]
                else:
                    uids = [defValue.o.UID()]
        # Prepare the result: an instance of SomeObjects, that will be unwrapped
        # if not required.
        res = gutils.SomeObjects()
        res.totalNumber = res.batchSize = len(uids)
        batchNeeded = startNumber != None
        if batchNeeded:
            res.batchSize = self.maxPerPage
        if startNumber != None:
            res.startNumber = startNumber
        # Get the objects given their uids
        i = res.startNumber
        while i < (res.startNumber + res.batchSize):
            if i >= res.totalNumber: break
            # Retrieve every reference in the correct format according to p_type
            if type == 'uids':
                ref = uids[i]
            else:
                ref = obj.getTool().getObject(uids[i])
                if type == 'objects':
                    ref = ref.appy()
            res.objects.append(ref)
            i += 1
        # Manage parameter p_noListIfSingleObj
        if res.objects and noListIfSingleObj:
            if self.multiplicity[1] == 1:
                res.objects = res.objects[0]
        if someObjects: return res
        return res.objects
Beispiel #28
0
 def __init__(self,
              validator=None,
              multiplicity=(0, 1),
              default=None,
              format=WITH_HOUR,
              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,
              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):
     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
     Field.__init__(self, validator, 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, persist)
Beispiel #29
0
 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=None, height=None,
              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'):
     # By default, a boolean is edited via a checkbox. It can also be edited
     # via 2 radio buttons (p_render="radios").
     self.render = render
     Field.__init__(self, validator, 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, persist)
     self.pythonType = bool
Beispiel #30
0
    def getValue(self, obj, type='objects', noListIfSingleObj=False,
                 startNumber=None, someObjects=False):
        '''Returns the objects linked to p_obj through this Ref field.
           - If p_type is "objects",  it returns the Appy wrappers;
           - If p_type is "zobjects", it returns the Zope objects;
           - If p_type is "uids",     it returns UIDs of objects (= strings).

           * If p_startNumber is None, it returns all referred objects.
           * If p_startNumber is a number, it returns self.maxPerPage objects,
             starting at p_startNumber.

           If p_noListIfSingleObj is True, it returns the single reference as
           an object and not as a list.

           If p_someObjects is True, it returns an instance of SomeObjects
           instead of returning a list of references.'''
        uids = getattr(obj.aq_base, self.name, [])
        if not uids:
            # Maybe is there a default value?
            defValue = Field.getValue(self, obj)
            if defValue:
                # I must prefix call to function "type" with "__builtins__"
                # because this name was overridden by a method parameter.
                if __builtins__['type'](defValue) in sutils.sequenceTypes:
                    uids = [o.o.UID() for o in defValue]
                else:
                    uids = [defValue.o.UID()]
        # Prepare the result: an instance of SomeObjects, that will be unwrapped
        # if not required.
        res = gutils.SomeObjects()
        res.totalNumber = res.batchSize = len(uids)
        batchNeeded = startNumber != None
        if batchNeeded:
            res.batchSize = self.maxPerPage
        if startNumber != None:
            res.startNumber = startNumber
        # Get the objects given their uids
        i = res.startNumber
        while i < (res.startNumber + res.batchSize):
            if i >= res.totalNumber: break
            # Retrieve every reference in the correct format according to p_type
            if type == 'uids':
                ref = uids[i]
            else:
                ref = obj.getTool().getObject(uids[i])
                if type == 'objects':
                    ref = ref.appy()
            res.objects.append(ref)
            i += 1
        # Manage parameter p_noListIfSingleObj
        if res.objects and noListIfSingleObj:
            if self.multiplicity[1] == 1:
                res.objects = res.objects[0]
        if someObjects: return res
        return res.objects
Beispiel #31
0
 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=None,
              height=None,
              maxChars=None,
              colspan=1,
              master=None,
              masterValue=None,
              focus=False,
              historized=False,
              mapping=None,
              label=None,
              subLayouts=Table('fv', width=None)):
     Field.__init__(self, validator, multiplicity, default, show, page,
                    group, layouts, move, indexed, False,
                    specificReadPermission, specificWritePermission, width,
                    height, None, colspan, master, masterValue, focus,
                    historized, True, mapping, label, None, None, None,
                    None)
     self.validable = True
     # Tuples of (names, Field instances) determining the format of every
     # element in the list.
     self.fields = fields
     self.fieldsd = [(n, f.__dict__) for (n, f) in self.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)
Beispiel #32
0
 def getIndexType(self):
     '''Index type varies depending on String parameters.'''
     # If String.isSelect, be it multivalued or not, we define a ListIndex:
     # this way we can use AND/OR operator.
     if self.isSelect:
         return 'ListIndex'
     elif self.format == String.TEXT:
         return 'TextIndex'
     elif self.format == String.XHTML:
         return 'XhtmlIndex'
     return Field.getIndexType(self)
Beispiel #33
0
 def isShowable(self, obj, layoutType):
     res = Field.isShowable(self, obj, layoutType)
     if not res: return res
     # We add here specific Ref rules for preventing to show the field under
     # some inappropriate circumstances.
     if (layoutType == 'edit') and \
        (self.mayAdd(obj) or not self.link): return False
     if self.isBack:
         if layoutType == 'edit': return False
         else: return getattr(obj.aq_base, self.name, None)
     return res
Beispiel #34
0
 def getIndexType(self):
     '''Index type varies depending on String parameters.'''
     # If String.isSelect, be it multivalued or not, we define a ListIndex:
     # this way we can use AND/OR operator.
     if self.isSelect:
         return 'ListIndex'
     elif self.format == String.TEXT:
         return 'TextIndex'
     elif self.format == String.XHTML:
         return 'XhtmlIndex'
     return Field.getIndexType(self)
Beispiel #35
0
 def getValue(self, obj):
     # Cheat if this field represents p_obj's state
     if self.name == 'state': return obj.State()
     value = Field.getValue(self, obj)
     if not value:
         if self.isMultiValued(): return emptyTuple
         else: return value
     if isinstance(value, basestring) and self.isMultiValued():
         value = [value]
     elif isinstance(value, tuple):
         value = list(value)
     return value
Beispiel #36
0
 def isShowable(self, obj, layoutType):
     res = Field.isShowable(self, obj, layoutType)
     if not res: return res
     # We add here specific Ref rules for preventing to show the field under
     # some inappropriate circumstances.
     if (layoutType == 'edit') and \
        (self.mayAdd(obj) or not self.link):
         return False
     if self.isBack:
         if layoutType == 'edit': return False
         else: return getattr(obj.aq_base, self.name, None)
     return res
Beispiel #37
0
 def getValue(self, obj):
     # Cheat if this field represents p_obj's state
     if self.name == 'state': return obj.State()
     value = Field.getValue(self, obj)
     if not value:
         if self.isMultiValued(): return emptyTuple
         else: return value
     if isinstance(value, basestring) and self.isMultiValued():
         value = [value]
     elif isinstance(value, tuple):
         value = list(value)
     return value
Beispiel #38
0
 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=None,
              height=None,
              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'):
     # By default, a boolean is edited via a checkbox. It can also be edited
     # via 2 radio buttons (p_render="radios").
     self.render = render
     Field.__init__(self, validator, 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, persist)
     self.pythonType = bool
Beispiel #39
0
 def __init__(self, validator=None, multiplicity=(0,1), default=None,
              format=WITH_HOUR, 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, 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):
     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
     Field.__init__(self, validator, multiplicity, default, show, page,
                    group, layouts, move, indexed, searchable,
                    specificReadPermission, specificWritePermission, width,
                    height, None, colspan, master, masterValue, focus,
                    historized, True, mapping, label, sdefault, scolspan,
                    swidth, sheight)
Beispiel #40
0
 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=None, height=None,
              maxChars=None, colspan=1, master=None, masterValue=None,
              focus=False, historized=False, mapping=None, label=None,
              subLayouts=Table('fv', width=None)):
     Field.__init__(self, validator, multiplicity, default, show, page,
                    group, layouts, move, indexed, False,
                    specificReadPermission, specificWritePermission, width,
                    height, None, colspan, master, masterValue, focus,
                    historized, True, mapping, label, None, None, None, None)
     self.validable = True
     # Tuples of (names, Field instances) determining the format of every
     # element in the list.
     self.fields = fields
     self.fieldsd = [(n, f.__dict__) for (n,f) in self.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)
Beispiel #41
0
 def getUnilingualStorableValue(self, obj, value):
     isString = isinstance(value, basestring)
     isEmpty = Field.isEmptyValue(self, obj, value)
     # Apply transform if required
     if isString and not isEmpty and (self.transform != 'none'):
         value = self.applyTransform(value)
     # Clean XHTML strings
     if not isEmpty and (self.format == String.XHTML):
         # When image upload is allowed, ckeditor inserts some "style" attrs
         # (ie for image size when images are resized). So in this case we
         # can't remove style-related information.
         try:
             value = XhtmlCleaner(keepStyles=False).clean(value)
         except XhtmlCleaner.Error, e:
             # Errors while parsing p_value can't prevent the user from
             # storing it.
             pass
Beispiel #42
0
 def getIndexValue(self, obj, forSearch=False):
     '''For indexing purposes, we return only strings, not unicodes.'''
     res = Field.getIndexValue(self, obj, forSearch)
     if isinstance(res, unicode):
         res = res.encode('utf-8')
     if res and forSearch and (self.format == String.XHTML):
         # Convert the value to simple text.
         extractor = XhtmlTextExtractor(raiseOnError=False)
         res = extractor.parse('<p>%s</p>' % res)
     # Ugly catalog: if I give an empty tuple as index value, it keeps the
     # previous value. If I give him a tuple containing an empty string, it
     # is ok.
     if isinstance(res, tuple) and not res: res = self.emptyStringTuple
     # Ugly catalog: if value is an empty string or None, it keeps the
     # previous index value.
     if res in self.emptyValuesCatalogIgnored: res = ' '
     return res
Beispiel #43
0
 def getIndexValue(self, obj, forSearch=False):
     '''For indexing purposes, we return only strings, not unicodes.'''
     res = Field.getIndexValue(self, obj, forSearch)
     if isinstance(res, unicode):
         res = res.encode('utf-8')
     if res and forSearch and (self.format == String.XHTML):
         # Convert the value to simple text.
         extractor = XhtmlTextExtractor(raiseOnError=False)
         res = extractor.parse('<p>%s</p>' % res)
     # Ugly catalog: if I give an empty tuple as index value, it keeps the
     # previous value. If I give him a tuple containing an empty string, it
     # is ok.
     if isinstance(res, tuple) and not res: res = self.emptyStringTuple
     # Ugly catalog: if value is an empty string or None, it keeps the
     # previous index value.
     if res in self.emptyValuesCatalogIgnored: res = ' '
     return res
Beispiel #44
0
 def getUnilingualStorableValue(self, obj, value):
     isString = isinstance(value, basestring)
     isEmpty = Field.isEmptyValue(self, obj, value)
     # Apply transform if required
     if isString and not isEmpty and (self.transform != 'none'):
        value = self.applyTransform(value)
     # Clean XHTML strings
     if not isEmpty and (self.format == String.XHTML):
         # When image upload is allowed, ckeditor inserts some "style" attrs
         # (ie for image size when images are resized). So in this case we
         # can't remove style-related information.
         try:
             value = XhtmlCleaner(keepStyles=False).clean(value)
         except XhtmlCleaner.Error, e:
             # Errors while parsing p_value can't prevent the user from
             # storing it.
             pass
Beispiel #45
0
 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
Beispiel #46
0
 def getIndexValue(self, obj, forSearch=False):
     '''Pure text must be extracted from rich content; multilingual content
        must be concatenated.'''
     isXhtml = self.format == String.XHTML
     if self.isMultilingual(obj):
         res = self.getValue(obj)
         if res:
             vals = []
             for v in res.itervalues():
                 if isinstance(v, unicode): v = v.encode('utf-8')
                 if isXhtml: vals.append(self.extractText(v))
                 else: vals.append(v)
             res = ' '.join(vals)
     else:
         res = Field.getIndexValue(self, obj, forSearch)
         if res and isXhtml: res = self.extractText(res)
     # Ugly catalog: if I give an empty tuple as index value, it keeps the
     # previous value. If I give him a tuple containing an empty string, it
     # is ok.
     if isinstance(res, tuple) and not res: res = self.emptyStringTuple
     # Ugly catalog: if value is an empty string or None, it keeps the
     # previous index value.
     if res in self.emptyValuesCatalogIgnored: res = ' '
     return res
Beispiel #47
0
 def getIndexValue(self, obj, forSearch=False):
     '''Pure text must be extracted from rich content; multilingual content
        must be concatenated.'''
     isXhtml = self.format == String.XHTML
     if self.isMultilingual(obj):
         res = self.getValue(obj)
         if res:
             vals = []
             for v in res.itervalues():
                 if isinstance(v, unicode): v = v.encode('utf-8')
                 if isXhtml: vals.append(self.extractText(v))
                 else: vals.append(v)
             res = ' '.join(vals)
     else:
         res = Field.getIndexValue(self, obj, forSearch)
         if res and isXhtml: res = self.extractText(res)
     # Ugly catalog: if I give an empty tuple as index value, it keeps the
     # previous value. If I give him a tuple containing an empty string, it
     # is ok.
     if isinstance(res, tuple) and not res: res = self.emptyStringTuple
     # Ugly catalog: if value is an empty string or None, it keeps the
     # previous index value.
     if res in self.emptyValuesCatalogIgnored: res = ' '
     return res
Beispiel #48
0
 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, templateName=None, showTemplate=None,
              freezeTemplate=None, context=None, stylesMapping={},
              formats=None):
     # Param "template" stores the path to the pod template(s).
     if not template: raise Exception(Pod.NO_TEMPLATE)
     if isinstance(template, basestring):
         self.template = [template]
     else:
         self.template = template
     # Param "templateName", if specified, is a method that will be called
     # with the current template (from self.template) as single arg and must
     # return the name of this template. If self.template stores a single
     # template, you have no need to use param "templateName". Simply use the
     # field label to name the template. But if you have a multi-pod field
     # (with several templates specified as a list or tuple in param
     # "template"), you will probably choose to hide the field label and use
     # param "templateName" to give a specific name to every template. If
     # "template" contains several templates and "templateName" is None, Appy
     # will produce names from template filenames.
     self.templateName = templateName
     # "showTemplate" determines if the current user may generate documents
     # based on this pod field. More precisely, "showTemplate", if specified,
     # must be a method that will be called with the current template as
     # single arg (one among self.template) and that must return the list or
     # tuple of formats that the current user may use as output formats for
     # generating a document. If the current user is not allowed at all to
     # generate documents based on the current template, "showTemplate" must
     # return an empty tuple/list. If "showTemplate" is not specified, the
     # user will be able to generate documents based on the current template,
     # in any format from self.formats (see below).
     # "showTemplate" comes in addition to self.show. self.show dictates the
     # visibility of the whole field (ie, all templates from self.template)
     # while "showTemplate" dictates the visiblity of a specific template
     # within self.template.
     self.showTemplate = showTemplate
     # "freezeTemplate" determines if the current user may freeze documents
     # normally generated dynamically from this pod field. More precisely,
     # "freezeTemplate", if specified, must be a method that will be called
     # with the current template as single arg and must return the (possibly
     # empty) list or tuple of formats the current user may freeze. The
     # "freezing-related actions" that are granted by "freezeTemplate" are
     # the following. When no document is frozen yet for a given
     # template/format, the user may:
     # - freeze the document: pod will be called to produce a document from
     #   the current database content and will store it in the database.
     #   Subsequent user requests for this pod field will return the frozen
     #   doc instead of generating on-the-fly documents;
     # - upload a document: the user will be able to upload a document that
     #   will be stored in the database. Subsequent user requests for this
     #   pod field will return this doc instead of generating on-the-fly
     #   documents.
     # When a document is already frozen or uploaded for a given
     # template/format, the user may:
     # - unfreeze the document: the frozen or uploaded document will be
     #   deleted from the database and subsequent user requests for the pod
     #   field will again generate on-the-fly documents;
     # - re-freeze the document: the frozen or uploaded document will be
     #   deleted, a new document will be generated from the current database
     #   content and will be frozen as a replacement to the deleted one;
     # - upload a document: the frozen or uploaded document will be replaced
     #   by a new document uploaded by the current user.
     self.freezeTemplate = freezeTemplate
     # The context is a dict containing a specific pod context, or a method
     # that returns such a dict.
     self.context = context
     # A global styles mapping that would apply to the whole template
     self.stylesMapping = stylesMapping
     # What are the output formats when generating documents from this pod ?
     self.formats = formats
     if not formats:
         # Compute default ones
         if self.template[0].endswith('.ods'):
             self.formats = ('xls', 'ods')
         else:
             self.formats = ('pdf', 'doc', 'odt')
     Field.__init__(self, None, (0,1), default, show, page, group, layouts,
                    move, indexed, searchable, specificReadPermission,
                    specificWritePermission, width, height, None, colspan,
                    master, masterValue, focus, historized, mapping, label,
                    None, None, None, None, True)
     # Param "persist" is set to True but actually, persistence for a pod
     # field is determined by freezing.
     self.validable = False
Beispiel #49
0
 def getValue(self, obj):
     '''Never returns "None". Returns always "True" or "False", even if
        "None" is stored in the DB.'''
     value = Field.getValue(self, obj)
     if value == None: return False
     return value
Beispiel #50
0
 def getJs(self, layoutType, res):
     # Javascript files are only required if the calendar must be shown.
     if self.calendar: Field.getJs(self, layoutType, res)
Beispiel #51
0
 def getCss(self, layoutType, res):
     # CSS files are only required if the calendar must be shown.
     if self.calendar: Field.getCss(self, layoutType, res)
Beispiel #52
0
 def isEmptyValue(self, value, obj=None):
     '''Must p_value be considered as empty?'''
     if not obj: return Field.isEmptyValue(self, value)
     if value: return False
     # If "nochange", the value must not be considered as empty
     return obj.REQUEST.get('%s_delete' % self.name) != 'nochange'
Beispiel #53
0
 def getValue(self, obj):
     value = Field.getValue(self, obj)
     if value: value = sutils.FileWrapper(value)
     return value
Beispiel #54
0
 def getJs(self, layoutType, res):
     if self.format == String.XHTML: Field.getJs(self, layoutType, res)
Beispiel #55
0
 def isShowable(self, obj, layoutType):
     if layoutType == 'edit': return
     return Field.isShowable(self, obj, layoutType)
Beispiel #56
0
 def getJs(self, layoutType, res, config):
     # Javascript files are only required if the calendar must be shown
     if self.calendar: Field.getJs(self, layoutType, res, config)