Back to index

plone3  3.1.7
_schema.py
Go to the documentation of this file.
00001 from zope.interface import Interface
00002 
00003 class ISchemata(Interface):
00004     """Schemata (roughly) represents a group of fields"""
00005 
00006     def getName():
00007         """Return Schemata name"""
00008 
00009     def __add__(other):
00010         """Add two schematas"""
00011 
00012     def copy():
00013         """Return a deep copy"""
00014 
00015     def fields():
00016         """Return a list of fields"""
00017 
00018     def widgets():
00019         """Return a dictionary that contains a widget for
00020         each field, using the field name as key
00021         """
00022 
00023     def filterFields(*predicates, **values):
00024         """Returns a subset of self.fields(), containing only fields that
00025         satisfy the given conditions.
00026 
00027         You can either specify predicates or values or both. If you provide
00028         both, all conditions must be satisfied.
00029 
00030         For each ``predicate`` (positional argument), ``predicate(field)`` must
00031         return 1 for a Field ``field`` to be returned as part of the result.
00032 
00033         Each ``attr=val`` function argument defines an additional predicate:
00034         A field must have the attribute ``attr`` and field.attr must be equal
00035         to value ``val`` for it to be in the returned list.
00036         """
00037 
00038     def __setitem__(name, field):
00039         """Add a field under key ``name`` (possibly
00040         overriding an existing one)
00041         """
00042 
00043     def addField(field):
00044         """Add a field (possibly overriding an existing one)"""
00045 
00046     def updateField(field):
00047         """Update a field (possibly overriding an existing one)"""
00048 
00049     def __delitem__(name):
00050         """Delete field by name ``name`` """
00051 
00052     def delField(name):
00053         """Delete field by name ``name`` """
00054 
00055     def __getitem__(name):
00056         """Get field by name.
00057 
00058         Raises KeyError if the field does not exist.
00059         """
00060 
00061     def get(name, default=None):
00062         """Get field by name, using a default value
00063         for missing
00064         """
00065 
00066     def has_key(name):
00067         """Check if a field by the given name exists"""
00068 
00069     def keys():
00070         """Return the names of the fields present
00071         on this schema"""
00072 
00073     def searchable():
00074         """Return a list containing names of all
00075         the fields present on this schema that are
00076         searchable.
00077         """
00078 
00079 class ISchema(ISchemata):
00080     """ Schema """
00081 
00082     def edit(instance, name, value):
00083         """Call the mutator by name on instance,
00084         setting the value.
00085         """
00086 
00087     def setDefaults(instance):
00088         """Only call during object initialization.
00089 
00090         Sets fields to schema defaults.
00091         """
00092 
00093     def updateAll(instance, **kwargs):
00094         """This method mutates fields in the given instance.
00095 
00096         For each keyword argument k, the key indicates the name of the
00097         field to mutate while the value is used to call the mutator.
00098 
00099         E.g. updateAll(instance, id='123', amount=500) will, depending on the
00100         actual mutators set, result in two calls: ``instance.setId('123')`` and
00101         ``instance.setAmount(500)``.
00102         """
00103 
00104     def allow(name):
00105         """Check if a field by the given name exists"""
00106 
00107     def validate(instance=None, REQUEST=None,
00108                  errors=None, data=None, metadata=None):
00109         """Validate the state of the entire object.
00110 
00111         The passed dictionary ``errors`` will be filled with human readable
00112         error messages as values and the corresponding fields' names as
00113         keys.
00114         """
00115 
00116     def toString():
00117         """Utility method for converting a Schema to a string for the
00118         purpose of comparing schema.
00119 
00120         This is used for determining whether a schema
00121         has changed in the auto update function.
00122         """
00123 
00124     def signature():
00125         """Return an md5 sum of the the schema.
00126 
00127         This is used for determining whether a schema
00128         has changed in the auto update function.
00129         """
00130 
00131     def changeSchemataForField(fieldname, schemataname):
00132         """Change the schemata for a field """
00133 
00134     def getSchemataNames():
00135         """Return list of schemata names in order of appearing"""
00136 
00137     def getSchemataFields(name):
00138         """Return list of fields belong to schema 'name'
00139         in order of appearing
00140         """
00141 
00142     def replaceField(name, field):
00143         """Replace field under ``name`` with ``field``"""
00144         
00145     def moveField(name, direction=None, pos=None, after=None, before=None):
00146         """Move a field
00147         
00148         name:
00149             name of the field
00150         direction:
00151             Move a field inside its schemata to the left (-1) or to the right (+1)
00152         pos:
00153             Moves a field to a position in the whole schema. pos is either a number
00154             or 'top' or 'bottom'
00155         after:
00156             Moves the field 'name' after the field 'after'
00157         before:
00158             Moves the field 'name' before the field 'before'
00159          
00160         """
00161 
00162 class ICompositeSchema(ISchema):
00163     """A composite schema that delegates to underlying ones"""
00164 
00165     def getSchemas():
00166         """Return a list of underlying schemas in order"""
00167 
00168     def addSchemas(schemas):
00169         """Append schemas to composite"""
00170 
00171 class IBindableSchema(ISchema):
00172     """A Schema that can be bound to a context object"""
00173 
00174     def bind(context):
00175         """Bind schema to context"""
00176 
00177 class IManagedSchema(ISchema):
00178     """A schema that can be managed (ordering schemata,
00179     ordering fields, moving fields between schematas)
00180     """
00181 
00182     def delSchemata(name):
00183         """Remove all fields belonging to schemata 'name'"""
00184 
00185     def addSchemata(name):
00186         """Create a new schema by adding a new field with schemata 'name' """
00187 
00188     def moveSchemata(name, direction):
00189         """Move a schemata to left (direction=-1) or to right
00190         (direction=1)
00191         """
00192 
00193 class IMultiPageSchema(Interface):
00194     """A marker interface for schemas which have to be loaded on seperate
00195     HTML pages instead of beeing displayed on one page. This should only be
00196     used in wizard like cases where one schema depends on the values in a
00197     previous one.
00198     """
00199     pass