Back to index

plone3  3.1.7
Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes
Archetypes.Schema.Schemata Class Reference
Inheritance diagram for Archetypes.Schema.Schemata:
Inheritance graph
[legend]
Collaboration diagram for Archetypes.Schema.Schemata:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def getName
def __add__
def copy
def fields
def editableFields
def viewableFields
def widgets
def filterFields
def __setitem__
def addField
def __delitem__
def __getitem__
def get
def has_key
def keys
def searchable
def hasPrimary

Static Public Attributes

tuple security = ClassSecurityInfo()
 values = fields
 delField = __delitem__
 updateField = addField

Private Member Functions

def _validateOnAdd
def _checkPropertyDupe

Private Attributes

 __name__
 _names
 _fields

Static Private Attributes

 __implements__ = ISchemata
 __contains__ = has_key

Detailed Description

Manage a list of fields by grouping them together.

Schematas are identified by their names.

Definition at line 42 of file __init__.py.


Constructor & Destructor Documentation

def Archetypes.Schema.Schemata.__init__ (   self,
  name = 'default',
  fields = None 
)
Initialize Schemata and add optional fields.

Reimplemented in Archetypes.Schema.Schema, and Archetypes.Schema.BasicSchema.

Definition at line 53 of file __init__.py.

00053 
00054     def __init__(self, name='default', fields=None):
00055         """Initialize Schemata and add optional fields."""
00056 
00057         self.__name__ = name
00058         self._names = []
00059         self._fields = {}
00060 
00061         if fields is not None:
00062             if type(fields) not in [ListType, TupleType]:
00063                 fields = (fields, )
00064 
00065             for field in fields:
00066                 self.addField(field)

Here is the caller graph for this function:


Member Function Documentation

def Archetypes.Schema.Schemata.__add__ (   self,
  other 
)
Returns a new Schemata object that contains all fields and layers
from ``self`` and ``other``.

Reimplemented in Archetypes.Schema.Schema, and Archetypes.Schema.BasicSchema.

Definition at line 73 of file __init__.py.

00073 
00074     def __add__(self, other):
00075         """Returns a new Schemata object that contains all fields and layers
00076         from ``self`` and ``other``.
00077         """
00078 
00079         c = Schemata()
00080         for field in self.fields():
00081             c.addField(field)
00082         for field in other.fields():
00083             c.addField(field)
00084 
00085         return c
00086 

Here is the call graph for this function:

def Archetypes.Schema.Schemata.__delitem__ (   self,
  name 
)

Definition at line 226 of file __init__.py.

00226 
00227     def __delitem__(self, name):
00228         if not self._fields.has_key(name):
00229             raise KeyError("Schemata has no field '%s'" % name)
00230         del self._fields[name]
00231         self._names.remove(name)

def Archetypes.Schema.Schemata.__getitem__ (   self,
  name 
)

Definition at line 232 of file __init__.py.

00232 
00233     def __getitem__(self, name):
00234         return self._fields[name]

Here is the caller graph for this function:

def Archetypes.Schema.Schemata.__setitem__ (   self,
  name,
  field 
)

Definition at line 174 of file __init__.py.

00174 
00175     def __setitem__(self, name, field):
00176         assert name == field.getName()
00177         self.addField(field)

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Schema.Schemata._checkPropertyDupe (   self,
  field,
  propname 
) [private]

Definition at line 270 of file __init__.py.

00270 
00271     def _checkPropertyDupe(self, field, propname):
00272         check_value = getattr(field, propname, _marker)
00273         # None is fine too.
00274         if check_value is _marker or check_value is None:
00275             return False
00276         check_name = field.getName()
00277         for f in self.fields():
00278             got = getattr(f, propname, _marker)
00279             if got == check_value and f.getName() != check_name:
00280                 return f, got
00281         return False
00282 
00283 InitializeClass(Schemata)
00284 

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Schema.Schemata._validateOnAdd (   self,
  field 
) [private]
Validates fields on adding and bootstrapping

Definition at line 189 of file __init__.py.

00189 
00190     def _validateOnAdd(self, field):
00191         """Validates fields on adding and bootstrapping
00192         """
00193         # interface test
00194         if not IField.isImplementedBy(field):
00195             raise ValueError, "Object doesn't implement IField: %r" % field
00196         name = field.getName()
00197         # two primary fields are forbidden
00198         if getattr(field, 'primary', False):
00199             res = self.hasPrimary()
00200             if res is not False and name != res.getName():
00201                 raise SchemaException(
00202                     "Tried to add '%s' as primary field "
00203                     "but %s already has the primary field '%s'." %
00204                     (name, repr(self), res.getName())
00205                     )
00206         for pname in ('accessor', 'edit_accessor', 'mutator'):
00207             res = self._checkPropertyDupe(field, pname)
00208             if res is not False:
00209                 res, value = res
00210                 raise SchemaException(
00211                     "Tried to add '%s' with property '%s' set "
00212                     "to %s but '%s' has the same value." %
00213                     (name, pname, repr(value), res.getName())
00214                     )
00215         # Do not allowed unqualified references
00216         if field.type in ('reference', ):
00217             relationship = getattr(field, 'relationship', '')
00218             if type(relationship) is not StringType or len(relationship) == 0:
00219                 raise ReferenceException(
00220                     "Unqualified relationship or "
00221                     "unsupported relationship var type in field '%s'. "
00222                     "The relationship qualifer must be a non empty "
00223                     "string." % name
00224                     )
00225 

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Schema.Schemata.addField (   self,
  field 
)
Adds a given field to my dictionary of fields.

Reimplemented in Archetypes.Schema.MetadataSchema.

Definition at line 180 of file __init__.py.

00180 
00181     def addField(self, field):
00182         """Adds a given field to my dictionary of fields."""
00183         field = aq_base(field)
00184         self._validateOnAdd(field)
00185         name = field.getName()
00186         if name not in self._names:
00187             self._names.append(name)
00188         self._fields[name] = field

Here is the call graph for this function:

Here is the caller graph for this function:

Returns a deep copy of this Schemata.

Reimplemented in Archetypes.Schema.BasicSchema.

Definition at line 88 of file __init__.py.

00088 
00089     def copy(self):
00090         """Returns a deep copy of this Schemata.
00091         """
00092         c = Schemata()
00093         for field in self.fields():
00094             c.addField(field.copy())
00095         return c
00096 

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Schema.Schemata.editableFields (   self,
  instance,
  visible_only = False 
)
Returns a list of editable fields for the given instance

Definition at line 107 of file __init__.py.

00107 
00108     def editableFields(self, instance, visible_only=False):
00109         """Returns a list of editable fields for the given instance
00110         """
00111         ret = []
00112         for field in self.fields():
00113             if field.writeable(instance, debug=False) and    \
00114                    (not visible_only or
00115                     field.widget.isVisible(instance, 'edit') != 'invisible'):
00116                 ret.append(field)
00117         return ret

Here is the call graph for this function:

Returns a list of my fields in order of their indices.

Definition at line 98 of file __init__.py.

00098 
00099     def fields(self):
00100         """Returns a list of my fields in order of their indices."""
00101         return [self._fields[name] for name in self._names]
00102 

Here is the caller graph for this function:

def Archetypes.Schema.Schemata.filterFields (   self,
  predicates,
  values 
)
Returns a subset of self.fields(), containing only fields that
satisfy the given conditions.

You can either specify predicates or values or both. If you provide
both, all conditions must be satisfied.

For each ``predicate`` (positional argument), ``predicate(field)`` must
return 1 for a Field ``field`` to be returned as part of the result.

Each ``attr=val`` function argument defines an additional predicate:
A field must have the attribute ``attr`` and field.attr must be equal
to value ``val`` for it to be in the returned list.

Definition at line 137 of file __init__.py.

00137 
00138     def filterFields(self, *predicates, **values):
00139         """Returns a subset of self.fields(), containing only fields that
00140         satisfy the given conditions.
00141 
00142         You can either specify predicates or values or both. If you provide
00143         both, all conditions must be satisfied.
00144 
00145         For each ``predicate`` (positional argument), ``predicate(field)`` must
00146         return 1 for a Field ``field`` to be returned as part of the result.
00147 
00148         Each ``attr=val`` function argument defines an additional predicate:
00149         A field must have the attribute ``attr`` and field.attr must be equal
00150         to value ``val`` for it to be in the returned list.
00151         """
00152 
00153         results = []
00154 
00155         for field in self.fields(): # step through each of my fields
00156 
00157             # predicate failed:
00158             failed = [pred for pred in predicates if not pred(field)]
00159             if failed: continue
00160 
00161             # attribute missing:
00162             missing_attrs = [attr for attr in values.keys() \
00163                              if not shasattr(field, attr)]
00164             if missing_attrs: continue
00165 
00166             # attribute value unequal:
00167             diff_values = [attr for attr in values.keys() \
00168                            if getattr(field, attr) != values[attr]]
00169             if diff_values: continue
00170 
00171             results.append(field)
00172 
00173         return results

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Schema.Schemata.get (   self,
  name,
  default = None 
)

Definition at line 236 of file __init__.py.

00236 
00237     def get(self, name, default=None):
00238         return self._fields.get(name, default)

Here is the caller graph for this function:

Returns the Schemata's name.

Definition at line 68 of file __init__.py.

00068 
00069     def getName(self):
00070         """Returns the Schemata's name."""
00071         return self.__name__
00072 

Here is the caller graph for this function:

def Archetypes.Schema.Schemata.has_key (   self,
  name 
)

Definition at line 240 of file __init__.py.

00240 
00241     def has_key(self, name):
00242         return self._fields.has_key(name)

Here is the caller graph for this function:

Returns the first primary field or False

Definition at line 263 of file __init__.py.

00263 
00264     def hasPrimary(self):
00265         """Returns the first primary field or False"""
00266         for f in self.fields():
00267             if getattr(f, 'primary', False):
00268                 return f
00269         return False

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 246 of file __init__.py.

00246 
00247     def keys(self):
00248         return self._names

Here is the caller graph for this function:

Returns a list containing names of all searchable fields.

Definition at line 258 of file __init__.py.

00258 
00259     def searchable(self):
00260         """Returns a list containing names of all searchable fields."""
00261 
00262         return [f.getName() for f in self.fields() if f.searchable]

Here is the call graph for this function:

def Archetypes.Schema.Schemata.viewableFields (   self,
  instance 
)
Returns a list of viewable fields for the given instance

Definition at line 119 of file __init__.py.

00119 
00120     def viewableFields(self, instance):
00121         """Returns a list of viewable fields for the given instance
00122         """
00123         return [field for field in self.fields()
00124                 if field.checkPermission('view', instance)]

Here is the call graph for this function:

Returns a dictionary that contains a widget for
each field, using the field name as key.

Definition at line 126 of file __init__.py.

00126 
00127     def widgets(self):
00128         """Returns a dictionary that contains a widget for
00129         each field, using the field name as key."""
00130 
00131         widgets = {}
00132         for f in self.fields():
00133             widgets[f.getName()] = f.widget
00134         return widgets

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 243 of file __init__.py.

Archetypes.Schema.Schemata.__implements__ = ISchemata [static, private]

Definition at line 56 of file __init__.py.

Definition at line 58 of file __init__.py.

Reimplemented in Archetypes.Schema.Schema.

Definition at line 57 of file __init__.py.

Definition at line 251 of file __init__.py.

tuple Archetypes.Schema.Schemata.security = ClassSecurityInfo() [static]

Definition at line 255 of file __init__.py.

Definition at line 104 of file __init__.py.


The documentation for this class was generated from the following file: