def testAddData(self):
        page = Page(12)
        entry = page.add(b"123")
        self.assertEqual(entry.page, 12)
        self.assertEqual(entry.offset, 2)
        self.assertEqual(page.offsetEmpty, 7)

        entry = page.add(b"one two three")
        self.assertEqual(entry.page, 12)
        self.assertEqual(entry.offset, 7)
        self.assertEqual(page.offsetEmpty, 22)

        data = page.get(2)
        self.assertEqual(data, b"123")

        data = page.get(7)
        self.assertEqual(data, b"one two three")
Beispiel #2
0
 def __init__(self, validator, multiplicity, default, show, page, group,
              layouts, move, indexed, searchable, specificReadPermission,
              specificWritePermission, width, height, maxChars, colspan,
              master, masterValue, focus, historized, mapping, label,
              sdefault, scolspan, swidth, sheight, persist):
     # The validator restricts which values may be defined. It can be an
     # interval (1,None), a list of string values ['choice1', 'choice2'],
     # a regular expression, a custom function, a Selection instance, etc.
     self.validator = validator
     # Multiplicity is a 2-tuple indicating the minimum and maximum
     # occurrences of values.
     self.multiplicity = multiplicity
     # Is the field required or not ? (derived from multiplicity)
     self.required = self.multiplicity[0] > 0
     # Default value
     self.default = default
     # Must the field be visible or not?
     self.show = show
     # When displaying/editing the whole object, on what page and phase must
     # this field value appear?
     self.page = Page.get(page)
     self.pageName = self.page.name
     # Within self.page, in what group of fields must this one appear?
     self.group = Group.get(group)
     # The following attribute allows to move a field back to a previous
     # position (useful for moving fields above predefined ones).
     self.move = move
     # If indexed is True, a database index will be set on the field for
     # fast access.
     self.indexed = indexed
     # If specified "searchable", the field will be added to some global
     # index allowing to perform application-wide, keyword searches.
     self.searchable = searchable
     # Normally, permissions to read or write every attribute in a type are
     # granted if the user has the global permission to read or
     # edit instances of the whole type. If you want a given attribute
     # to be protected by specific permissions, set one or the 2 next boolean
     # values to "True". In this case, you will create a new "field-only"
     # read and/or write permission. If you need to protect several fields
     # with the same read/write permission, you can avoid defining one
     # specific permission for every field by specifying a "named"
     # permission (string) instead of assigning "True" to the following
     # arg(s). A named permission will be global to your whole Zope site, so
     # take care to the naming convention. Typically, a named permission is
     # of the form: "<yourAppName>: Write|Read ---". If, for example, I want
     # to define, for my application "MedicalFolder" a specific permission
     # for a bunch of fields that can only be modified by a doctor, I can
     # define a permission "MedicalFolder: Write medical information" and
     # assign it to the "specificWritePermission" of every impacted field.
     self.specificReadPermission = specificReadPermission
     self.specificWritePermission = specificWritePermission
     # Widget width and height
     self.width = width
     self.height = height
     # While width and height refer to widget dimensions, maxChars hereafter
     # represents the maximum number of chars that a given input field may
     # accept (corresponds to HTML "maxlength" property). "None" means
     # "unlimited".
     self.maxChars = maxChars or ''
     # If the widget is in a group with multiple columns, the following
     # attribute specifies on how many columns to span the widget.
     self.colspan = colspan or 1
     # The list of slaves of this field, if it is a master
     self.slaves = []
     # The behaviour of this field may depend on another, "master" field
     self.master = master
     if master: self.master.slaves.append(self)
     # The semantics of attribute "masterValue" below is as follows:
     # - if "masterValue" is anything but a method, the field will be shown
     #   only when the master has this value, or one of it if multivalued;
     # - if "masterValue" is a method, the value(s) of the slave field will
     #   be returned by this method, depending on the master value(s) that
     #   are given to it, as its unique parameter.
     self.masterValue = gutils.initMasterValue(masterValue)
     # If a field must retain attention in a particular way, set focus=True.
     # It will be rendered in a special way.
     self.focus = focus
     # If we must keep track of changes performed on a field, "historized"
     # must be set to True.
     self.historized = historized
     # Mapping is a dict of contexts that, if specified, are given when
     # translating the label, descr or help related to this field.
     self.mapping = self.formatMapping(mapping)
     self.id = id(self)
     self.type = self.__class__.__name__
     self.pythonType = None  # The True corresponding Python type
     # Get the layouts. Consult layout.py for more info about layouts.
     self.layouts = self.formatLayouts(layouts)
     # Can we filter this field?
     self.filterable = False
     # Can this field have values that can be edited and validated?
     self.validable = True
     # The base label for translations is normally generated automatically.
     # It is made of 2 parts: the prefix, based on class name, and the name,
     # which is the field name by default. You can change this by specifying
     # a value for param "label". If this value is a string, it will be
     # understood as a new prefix. If it is a tuple, it will represent the
     # prefix and another name. If you want to specify a new name only, and
     # not a prefix, write (None, newName).
     self.label = label
     # When you specify a default value "for search" (= "sdefault"), on a
     # search screen, in the search field corresponding to this field, this
     # default value will be present.
     self.sdefault = sdefault
     # Colspan for rendering the search widget corresponding to this field.
     self.scolspan = scolspan or 1
     # Width and height for the search widget
     self.swidth = swidth or width
     self.sheight = sheight or height
     # "persist" indicates if field content must be stored in the database.
     # For some fields it is not wanted (ie, fields used only as masters to
     # update slave's selectable values).
     self.persist = persist
Beispiel #3
0
 def __init__(self, validator, multiplicity, default, show, page, group,
              layouts, move, indexed, searchable, specificReadPermission,
              specificWritePermission, width, height, maxChars, colspan,
              master, masterValue, focus, historized, mapping, label,
              sdefault, scolspan, swidth, sheight, persist):
     # The validator restricts which values may be defined. It can be an
     # interval (1,None), a list of string values ['choice1', 'choice2'],
     # a regular expression, a custom function, a Selection instance, etc.
     self.validator = validator
     # Multiplicity is a 2-tuple indicating the minimum and maximum
     # occurrences of values.
     self.multiplicity = multiplicity
     # Is the field required or not ? (derived from multiplicity)
     self.required = self.multiplicity[0] > 0
     # Default value
     self.default = default
     # Must the field be visible or not?
     self.show = show
     # When displaying/editing the whole object, on what page and phase must
     # this field value appear?
     self.page = Page.get(page)
     self.pageName = self.page.name
     # Within self.page, in what group of fields must this one appear?
     self.group = Group.get(group)
     # The following attribute allows to move a field back to a previous
     # position (useful for moving fields above predefined ones).
     self.move = move
     # If indexed is True, a database index will be set on the field for
     # fast access.
     self.indexed = indexed
     # If specified "searchable", the field will be added to some global
     # index allowing to perform application-wide, keyword searches.
     self.searchable = searchable
     # Normally, permissions to read or write every attribute in a type are
     # granted if the user has the global permission to read or
     # edit instances of the whole type. If you want a given attribute
     # to be protected by specific permissions, set one or the 2 next boolean
     # values to "True". In this case, you will create a new "field-only"
     # read and/or write permission. If you need to protect several fields
     # with the same read/write permission, you can avoid defining one
     # specific permission for every field by specifying a "named"
     # permission (string) instead of assigning "True" to the following
     # arg(s). A named permission will be global to your whole Zope site, so
     # take care to the naming convention. Typically, a named permission is
     # of the form: "<yourAppName>: Write|Read ---". If, for example, I want
     # to define, for my application "MedicalFolder" a specific permission
     # for a bunch of fields that can only be modified by a doctor, I can
     # define a permission "MedicalFolder: Write medical information" and
     # assign it to the "specificWritePermission" of every impacted field.
     self.specificReadPermission = specificReadPermission
     self.specificWritePermission = specificWritePermission
     # Widget width and height
     self.width = width
     self.height = height
     # While width and height refer to widget dimensions, maxChars hereafter
     # represents the maximum number of chars that a given input field may
     # accept (corresponds to HTML "maxlength" property). "None" means
     # "unlimited".
     self.maxChars = maxChars or ''
     # If the widget is in a group with multiple columns, the following
     # attribute specifies on how many columns to span the widget.
     self.colspan = colspan or 1
     # The list of slaves of this field, if it is a master
     self.slaves = []
     # The behaviour of this field may depend on another, "master" field
     self.master = master
     if master: self.master.slaves.append(self)
     # The semantics of attribute "masterValue" below is as follows:
     # - if "masterValue" is anything but a method, the field will be shown
     #   only when the master has this value, or one of it if multivalued;
     # - if "masterValue" is a method, the value(s) of the slave field will
     #   be returned by this method, depending on the master value(s) that
     #   are given to it, as its unique parameter.
     self.masterValue = gutils.initMasterValue(masterValue)
     # If a field must retain attention in a particular way, set focus=True.
     # It will be rendered in a special way.
     self.focus = focus
     # If we must keep track of changes performed on a field, "historized"
     # must be set to True.
     self.historized = historized
     # Mapping is a dict of contexts that, if specified, are given when
     # translating the label, descr or help related to this field.
     self.mapping = self.formatMapping(mapping)
     self.id = id(self)
     self.type = self.__class__.__name__
     self.pythonType = None # The True corresponding Python type
     # Get the layouts. Consult layout.py for more info about layouts.
     self.layouts = self.formatLayouts(layouts)
     # Can we filter this field?
     self.filterable = False
     # Can this field have values that can be edited and validated?
     self.validable = True
     # The base label for translations is normally generated automatically.
     # It is made of 2 parts: the prefix, based on class name, and the name,
     # which is the field name by default. You can change this by specifying
     # a value for param "label". If this value is a string, it will be
     # understood as a new prefix. If it is a tuple, it will represent the
     # prefix and another name. If you want to specify a new name only, and
     # not a prefix, write (None, newName).
     self.label = label
     # When you specify a default value "for search" (= "sdefault"), on a
     # search screen, in the search field corresponding to this field, this
     # default value will be present.
     self.sdefault = sdefault
     # Colspan for rendering the search widget corresponding to this field.
     self.scolspan = scolspan or 1
     # Width and height for the search widget
     self.swidth = swidth or width
     self.sheight = sheight or height
     # "persist" indicates if field content must be stored in the database.
     # For some fields it is not wanted (ie, fields used only as masters to
     # update slave's selectable values).
     self.persist = persist