Back to index

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

List of all members.

Public Member Functions

def __init__
def getSchemas
def addSchemas
def getName
def __add__
def copy
def fields
def widgets
def filterFields
def __setitem__
def addField
def __delitem__
def __getitem__
def get
def has_key
def keys
def searchable
def edit
def setDefaults
def updateAll
def validate
def toString
def signature
def changeSchemataForField
def replaceField
def initializeLayers
def cleanupLayers

Static Public Attributes

tuple security = ClassSecurityInfo()
 updateField = addField
 delField = __delitem__
 allow = has_key

Private Attributes

 _schemas

Static Private Attributes

 __implements__ = ICompositeSchema,ILayerRuntime,ILayerContainer

Detailed Description

Act on behalf of a set of Schemas, pretending it
was a single one.

Note that if field names overlap, they last schema wins.

Definition at line 14 of file Composite.py.


Constructor & Destructor Documentation

def Archetypes.Schema.Composite.CompositeSchema.__init__ (   self,
  schemas = None 
)

Definition at line 26 of file Composite.py.

00026 
00027     def __init__(self, schemas=None):
00028         self._schemas = [Schema()]
00029         self.addSchemas(schemas)

Here is the caller graph for this function:


Member Function Documentation

Add two composite schemas

Definition at line 53 of file Composite.py.

00053 
00054     def __add__(self, other):
00055         """Add two composite schemas"""
00056         c = CompositeSchema()
00057         c.addSchemas((self, other))
00058         return c

Delete field by name ``name`` 

Definition at line 130 of file Composite.py.

00130 
00131     def __delitem__(self, name):
00132         """Delete field by name ``name`` """
00133         for s in self.getSchemas():
00134             if s.has_key(name):
00135                 del s[name]
00136                 return
00137         del self.getSchemas()[0][name]

Here is the call graph for this function:

Get field by name.

Raises KeyError if the field does not exist.

Definition at line 141 of file Composite.py.

00141 
00142     def __getitem__(self, name):
00143         """Get field by name.
00144 
00145         Raises KeyError if the field does not exist.
00146         """
00147         for s in self.getSchemas():
00148             if s.has_key(name):
00149                 return s[name]
00150         return self.getSchemas()[0][name]

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Schema.Composite.CompositeSchema.__setitem__ (   self,
  name,
  field 
)
Add a field under key ``name`` (possibly
overriding an existing one)

Definition at line 107 of file Composite.py.

00107 
00108     def __setitem__(self, name, field):
00109         """Add a field under key ``name`` (possibly
00110         overriding an existing one)
00111         """
00112         for s in self.getSchemas():
00113             if s.has_key(name):
00114                 s[name] = field
00115                 return
00116         self.getSchemas()[0][name] = field

Here is the call graph for this function:

Here is the caller graph for this function:

Add a field (possibly overriding an existing one)

Definition at line 118 of file Composite.py.

00118 
00119     def addField(self, field):
00120         """Add a field (possibly overriding an existing one)"""
00121         name = field.getName()
00122         for s in self.getSchemas():
00123             if s.has_key(name):
00124                 s.addField(field)
00125                 return
00126         self.getSchemas()[0].addField(field)

Here is the call graph for this function:

Append to the underlying schemas

Definition at line 40 of file Composite.py.

00040 
00041     def addSchemas(self, schemas):
00042         """Append to the underlying schemas"""
00043         if type(schemas) not in [ListType, TupleType]:
00044             schemas = (schemas, )
00045 
00046         for schema in schemas:
00047             self._schemas.append(schema)

def Archetypes.Schema.Composite.CompositeSchema.changeSchemataForField (   self,
  fieldname,
  schemataname 
)
Change the schemata for a field 

Definition at line 263 of file Composite.py.

00263 
00264     def changeSchemataForField(self, fieldname, schemataname):
00265         """Change the schemata for a field """
00266         for s in self.getSchemas():
00267             if s.has_key(fieldname):
00268                 s.changeSchemataForField(fieldname, schemataname)

Here is the call graph for this function:

def Archetypes.Schema.Composite.CompositeSchema.cleanupLayers (   self,
  instance,
  item = None,
  container = None 
)
Layer cleaning

Definition at line 284 of file Composite.py.

00284 
00285     def cleanupLayers(self, instance, item=None, container=None):
00286         """Layer cleaning"""
00287         for s in self.getSchemas():
00288             if ILayerContainer.isImplementedBy(s):
00289                 s.cleanupLayers(instance, item, container)
00290 
00291 InitializeClass(CompositeSchema)

Here is the call graph for this function:

Return a deep copy

Definition at line 60 of file Composite.py.

00060 
00061     def copy(self):
00062         """Return a deep copy"""
00063         c = CompositeSchema()
00064         c.addSchemas([s.copy() for s in self._schemas()])
00065         return c

def Archetypes.Schema.Composite.CompositeSchema.edit (   self,
  instance,
  name,
  value 
)
Call the mutator by name on instance,
setting the value.

Definition at line 192 of file Composite.py.

00192 
00193     def edit(self, instance, name, value):
00194         """Call the mutator by name on instance,
00195         setting the value.
00196         """
00197         if self.has_key(name):
00198             instance[name] = value

Here is the call graph for this function:

Here is the caller graph for this function:

Return a list of fields

Definition at line 67 of file Composite.py.

00067 
00068     def fields(self):
00069         """Return a list of fields"""
00070         result = []
00071         for s in self.getSchemas():
00072             result.extend(s.fields())
00073         return result

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Schema.Composite.CompositeSchema.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 88 of file Composite.py.

00088 
00089     def filterFields(self, *predicates, **values):
00090         """Returns a subset of self.fields(), containing only fields that
00091         satisfy the given conditions.
00092 
00093         You can either specify predicates or values or both. If you provide
00094         both, all conditions must be satisfied.
00095 
00096         For each ``predicate`` (positional argument), ``predicate(field)`` must
00097         return 1 for a Field ``field`` to be returned as part of the result.
00098 
00099         Each ``attr=val`` function argument defines an additional predicate:
00100         A field must have the attribute ``attr`` and field.attr must be equal
00101         to value ``val`` for it to be in the returned list.
00102         """
00103         result = []
00104         for s in self.getSchemas():
00105             result.extend(s.filterFields(*predicates, **values))
00106         return result

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Schema.Composite.CompositeSchema.get (   self,
  name,
  default = None 
)
Get field by name, using a default value
for missing

Definition at line 152 of file Composite.py.

00152 
00153     def get(self, name, default=None):
00154         """Get field by name, using a default value
00155         for missing
00156         """
00157         for s in self.getSchemas():
00158             if s.has_key(name):
00159                 return s.get(name)
00160         return self.getSchemas()[0].get(name, default)

Here is the call graph for this function:

Here is the caller graph for this function:

Return Schemata name

Definition at line 49 of file Composite.py.

00049 
00050     def getName(self):
00051         """Return Schemata name"""
00052         return '-'.join([s.getName() for s in self.getSchemas()])

Here is the call graph for this function:

Here is the caller graph for this function:

Return the underlying schemas

Definition at line 30 of file Composite.py.

00030 
00031     def getSchemas(self):
00032         """Return the underlying schemas"""
00033         schemas = []
00034         context = aq_parent(aq_inner(self))
00035         for s in self._schemas:
00036             if IBindableSchema.isImplementedBy(s):
00037                 s.bind(context)
00038             schemas.append(s)
00039         return schemas

Here is the caller graph for this function:

Check if a field by the given name exists

Definition at line 162 of file Composite.py.

00162 
00163     def has_key(self, name):
00164         """Check if a field by the given name exists"""
00165         for s in self.getSchemas():
00166             if s.has_key(name):
00167                 return True
00168         return self.getSchemas()[0].has_key(name)
00169 

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Schema.Composite.CompositeSchema.initializeLayers (   self,
  instance,
  item = None,
  container = None 
)
Layer initialization

Definition at line 277 of file Composite.py.

00277 
00278     def initializeLayers(self, instance, item=None, container=None):
00279         """Layer initialization"""
00280         for s in self.getSchemas():
00281             if ILayerContainer.isImplementedBy(s):
00282                 s.initializeLayers(instance, item, container)

Here is the call graph for this function:

Here is the caller graph for this function:

Return the names of the fields present
on this schema

Definition at line 171 of file Composite.py.

00171 
00172     def keys(self, name):
00173         """Return the names of the fields present
00174         on this schema
00175         """
00176         result = []
00177         for s in self.getSchemas():
00178             result.extend(s.keys())
00179         return result

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Schema.Composite.CompositeSchema.replaceField (   self,
  name,
  field 
)
Replace field under ``name`` with ``field``

Definition at line 270 of file Composite.py.

00270 
00271     def replaceField(self, name, field):
00272         """Replace field under ``name`` with ``field``"""
00273         for s in self.getSchemas():
00274             if s.has_key(name):
00275                 s.replaceField(name, field)

Here is the call graph for this function:

Return a list containing names of all
the fields present on this schema that are
searchable.

Definition at line 181 of file Composite.py.

00181 
00182     def searchable(self):
00183         """Return a list containing names of all
00184         the fields present on this schema that are
00185         searchable.
00186         """
00187         result = []
00188         for s in self.getSchemas():
00189             result.extend(s.searchable())
00190         return result

Here is the call graph for this function:

Only call during object initialization.

Sets fields to schema defaults.

Definition at line 200 of file Composite.py.

00200 
00201     def setDefaults(self, instance):
00202         """Only call during object initialization.
00203 
00204         Sets fields to schema defaults.
00205         """
00206         for s in self.getSchemas():
00207             s.setDefaults(instance)

Here is the call graph for this function:

Here is the caller graph for this function:

Return an md5 sum of the the schema.

This is used for determining whether a schema
has changed in the auto update function.

Definition at line 253 of file Composite.py.

00253 
00254     def signature(self):
00255         """Return an md5 sum of the the schema.
00256 
00257         This is used for determining whether a schema
00258         has changed in the auto update function.
00259         """
00260         from md5 import md5
00261         return md5(self.toString()).digest()

Here is the call graph for this function:

Utility method for converting a Schema to a string for the
purpose of comparing schema.

This is used for determining whether a schema
has changed in the auto update function.

Definition at line 240 of file Composite.py.

00240 
00241     def toString(self):
00242         """Utility method for converting a Schema to a string for the
00243         purpose of comparing schema.
00244 
00245         This is used for determining whether a schema
00246         has changed in the auto update function.
00247         """
00248         result = ''
00249         for s in self.getSchemas():
00250             result += s.toString()
00251         return result

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Schema.Composite.CompositeSchema.updateAll (   self,
  instance,
  kwargs 
)
This method mutates fields in the given instance.

For each keyword argument k, the key indicates the name of the
field to mutate while the value is used to call the mutator.

E.g. updateAll(instance, id='123', amount=500) will, depending on the
actual mutators set, result in two calls: ``instance.setId('123')`` and
``instance.setAmount(500)``.

Definition at line 209 of file Composite.py.

00209 
00210     def updateAll(self, instance, **kwargs):
00211         """This method mutates fields in the given instance.
00212 
00213         For each keyword argument k, the key indicates the name of the
00214         field to mutate while the value is used to call the mutator.
00215 
00216         E.g. updateAll(instance, id='123', amount=500) will, depending on the
00217         actual mutators set, result in two calls: ``instance.setId('123')`` and
00218         ``instance.setAmount(500)``.
00219         """
00220         for s in self.getSchemas():
00221             s.updateAll(instance, **kwargs)

Here is the call graph for this function:

def Archetypes.Schema.Composite.CompositeSchema.validate (   self,
  instance = None,
  REQUEST = None,
  errors = None,
  data = None,
  metadata = None 
)
Validate the state of the entire object.

The passed dictionary ``errors`` will be filled with human readable
error messages as values and the corresponding fields' names as
keys.

Definition at line 227 of file Composite.py.

00227 
00228                  errors=None, data=None, metadata=None):
00229         """Validate the state of the entire object.
00230 
00231         The passed dictionary ``errors`` will be filled with human readable
00232         error messages as values and the corresponding fields' names as
00233         keys.
00234         """
00235         for s in self.getSchemas():
00236             s.validate(instance=instance, REQUEST=REQUEST,
00237                        errors=errors, data=data, metadata=metadata)
00238         return errors

Here is the call graph for this function:

Here is the caller graph for this function:

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

Note that if there are fields with the same name, they
will be overriden by the last schema.

Definition at line 75 of file Composite.py.

00075 
00076     def widgets(self):
00077         """Return a dictionary that contains a widget for
00078         each field, using the field name as key.
00079 
00080         Note that if there are fields with the same name, they
00081         will be overriden by the last schema.
00082         """
00083         result = {}
00084         for s in self.getSchemas():
00085             result.update(s.widgets())
00086         return result

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Archetypes.Schema.Composite.CompositeSchema.__implements__ = ICompositeSchema,ILayerRuntime,ILayerContainer [static, private]

Definition at line 21 of file Composite.py.

Definition at line 27 of file Composite.py.

Definition at line 223 of file Composite.py.

Definition at line 139 of file Composite.py.

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

Definition at line 23 of file Composite.py.

Definition at line 128 of file Composite.py.


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