def setSlave(self, slaveField, masterValue): '''Sets p_slaveField as slave of this field. Normally, master/slave relationships are defined when a slave field is defined. At this time you specify parameters "master" and "masterValue" for this field and that's all. This method is used to add a master/slave relationship that was not initially foreseen.''' slaveField.master = self slaveField.masterValue = gutils.initMasterValue(masterValue) if slaveField not in self.slaves: self.slaves.append(slaveField) # Master's init method may not have been called yet. slaveField.masterName = getattr(self, 'name', None)
def __init__( self, name, columns=["100%"], wide=True, style="section2", hasLabel=True, hasDescr=False, hasHelp=False, hasHeaders=False, group=None, colspan=1, align="center", valign="top", css_class="", master=None, masterValue=None, cellpadding=1, cellspacing=1, cellgap="0.6em", label=None, translated=None, ): self.name = name # In its simpler form, field "columns" below can hold a list or tuple # of column widths expressed as strings, that will be given as is in # the "width" attributes of the corresponding "td" tags. Instead of # strings, within this list or tuple, you may give Column instances # (see below). self.columns = columns self._setColumns() # If field "wide" below is True, the HTML table corresponding to this # group will have width 100%. You can also specify some string value, # which will be used for HTML param "width". if wide == True: self.wide = "100%" elif isinstance(wide, basestring): self.wide = wide else: self.wide = "" # If style = 'fieldset', all widgets within the group will be rendered # within an HTML fieldset. If style is 'section1' or 'section2', widgets # will be rendered after the group title. self.style = style # If hasLabel is True, the group will have a name and the corresponding # i18n label will be generated. self.hasLabel = hasLabel # If hasDescr is True, the group will have a description and the # corresponding i18n label will be generated. self.hasDescr = hasDescr # If hasHelp is True, the group will have a help text associated and the # corresponding i18n label will be generated. self.hasHelp = hasHelp # If hasheaders is True, group content will begin with a row of headers, # and a i18n label will be generated for every header. self.hasHeaders = hasHeaders self.nbOfHeaders = len(columns) # If this group is himself contained in another group, the following # attribute is filled. self.group = Group.get(group) # If the group is rendered into another group, we can specify the number # of columns that this group will span. self.colspan = colspan self.align = align self.valign = valign self.cellpadding = cellpadding self.cellspacing = cellspacing # Beyond standard cellpadding and cellspacing, cellgap can define an # additional horizontal gap between cells in a row. So this value does # not add space before the first cell or after the last one. self.cellgap = cellgap if style == "tabs": # Group content will be rendered as tabs. In this case, some # param combinations have no sense. self.hasLabel = self.hasDescr = self.hasHelp = False # The rendering is forced to a single column self.columns = self.columns[:1] # Inner field/group labels will be used as tab labels. self.css_class = css_class self.master = master self.masterValue = gutils.initMasterValue(masterValue) if master: master.slaves.append(self) self.label = label # See similar attr of Type class. # If a translated name is already given here, we will use it instead of # trying to translate the group label. self.translated = translated
def __init__(self, name, columns=['100%'], wide=True, style='section2', hasLabel=True, hasDescr=False, hasHelp=False, hasHeaders=False, group=None, colspan=1, align='center', valign='top', css_class='', master=None, masterValue=None, cellpadding=1, cellspacing=1, cellgap='0.6em', label=None, translated=None): self.name = name # In its simpler form, field "columns" below can hold a list or tuple # of column widths expressed as strings, that will be given as is in # the "width" attributes of the corresponding "td" tags. Instead of # strings, within this list or tuple, you may give Column instances # (see below). self.columns = columns self._setColumns() # If field "wide" below is True, the HTML table corresponding to this # group will have width 100%. You can also specify some string value, # which will be used for HTML param "width". if wide == True: self.wide = '100%' elif isinstance(wide, basestring): self.wide = wide else: self.wide = '' # If style = 'fieldset', all widgets within the group will be rendered # within an HTML fieldset. If style is 'section1' or 'section2', widgets # will be rendered after the group title. self.style = style # If hasLabel is True, the group will have a name and the corresponding # i18n label will be generated. self.hasLabel = hasLabel # If hasDescr is True, the group will have a description and the # corresponding i18n label will be generated. self.hasDescr = hasDescr # If hasHelp is True, the group will have a help text associated and the # corresponding i18n label will be generated. self.hasHelp = hasHelp # If hasheaders is True, group content will begin with a row of headers, # and a i18n label will be generated for every header. self.hasHeaders = hasHeaders self.nbOfHeaders = len(columns) # If this group is himself contained in another group, the following # attribute is filled. self.group = Group.get(group) # If the group is rendered into another group, we can specify the number # of columns that this group will span. self.colspan = colspan self.align = align self.valign = valign self.cellpadding = cellpadding self.cellspacing = cellspacing # Beyond standard cellpadding and cellspacing, cellgap can define an # additional horizontal gap between cells in a row. So this value does # not add space before the first cell or after the last one. self.cellgap = cellgap if style == 'tabs': # Group content will be rendered as tabs. In this case, some # param combinations have no sense. self.hasLabel = self.hasDescr = self.hasHelp = False # The rendering is forced to a single column self.columns = self.columns[:1] # Inner field/group labels will be used as tab labels. self.css_class = css_class self.master = master self.masterValue = gutils.initMasterValue(masterValue) if master: master.slaves.append(self) self.label = label # See similar attr of Type class. # If a translated name is already given here, we will use it instead of # trying to translate the group label. self.translated = translated
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
def __init__(self, name, columns=None, wide=True, style='section2', hasLabel=True, hasDescr=False, hasHelp=False, hasHeaders=False, group=None, colspan=1, align='center', valign='top', css_class='', labelCss=None, master=None, masterValue=None, cellpadding=1, cellspacing=1, cellgap='0.6em', label=None, translated=None): self.name = name # In its simpler form, field "columns" below can hold a list or tuple # of column widths expressed as strings, that will be given as is in # the "width" attributes of the corresponding "td" tags. Instead of # strings, within this list or tuple, you may give Column instances # (see below). self.columns = columns self._setColumns(style) # If field "wide" below is True, the HTML table corresponding to this # group will have width 100%. You can also specify some string value, # which will be used for HTML param "width". if wide == True: self.wide = '100%' elif isinstance(wide, basestring): self.wide = wide else: self.wide = '' # Groups of various styles can be rendered. If "style" is: # - 'sectionX' (X can be 1, 2, 3...) # the group will be rendered as a "section": the group # title will be rendered in some style (depending on X) # before the widgets; # - 'fieldset' all widgets within the group will be rendered within an # HTML fieldset; # - 'tabs' the group will be rendered as tabs. One tab will be # rendered for every inner widget. If you want some tab to # contain several widgets, specify a group as sub-group of # the group having style 'tabs'; # - 'grid' the widgets will be rendered in some standardized, # tabular way. self.style = style # If hasLabel is True, the group will have a name and the corresponding # i18n label will be generated. self.hasLabel = hasLabel # If hasDescr is True, the group will have a description and the # corresponding i18n label will be generated. self.hasDescr = hasDescr # If hasHelp is True, the group will have a help text associated and the # corresponding i18n label will be generated. self.hasHelp = hasHelp # If hasheaders is True, group content will begin with a row of headers, # and a i18n label will be generated for every header. self.hasHeaders = hasHeaders self.nbOfHeaders = len(self.columns) # If this group is himself contained in another group, the following # attribute is filled. self.group = Group.get(group) # If the group is rendered into another group, we can specify the number # of columns that this group will span. self.colspan = colspan self.align = align self.valign = valign self.cellpadding = cellpadding self.cellspacing = cellspacing # Beyond standard cellpadding and cellspacing, cellgap can define an # additional horizontal gap between cells in a row. So this value does # not add space before the first cell or after the last one. self.cellgap = cellgap if style == 'tabs': # Group content will be rendered as tabs. In this case, some # param combinations have no sense. self.hasLabel = self.hasDescr = self.hasHelp = False # Inner field/group labels will be used as tab labels # "css_class", if specified, will be applied to the whole group self.css_class = css_class # "labelCss" is the CSS class that will be applied to the group label self._setLabelCss(labelCss, style) self.master = master self.masterValue = gutils.initMasterValue(masterValue) if master: master.slaves.append(self) self.label = label # See similar attr of Type class # If a translated name is already given here, we will use it instead of # trying to translate the group label. self.translated = translated