Back to index

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

List of all members.

Public Member Functions

def __init__
def initializeArchetype
def manage_afterAdd
def manage_afterClone
def manage_beforeDelete
def initializeLayers
def cleanupLayers
def title_or_id
def getId
def setId
def Type
def getField
def getWrappedField
def getDefault
def isBinary
def isTransformable
def widget
def getFilename
def getContentType
def setContentType
def setFilename
def getPrimaryField
def get_portal_metadata
def Vocabulary
def __getitem__
def setDefaults
def update
def validate_field
def pre_validate
 Pre/post validate hooks that will need to write errors into the errors dict directly using errors[fieldname] = "".
def post_validate
def validate
def SearchableText
def getCharset
def get_size
def processForm
def at_post_create_script
def at_post_edit_script
def markCreationFlag
def unmarkCreationFlag
def checkCreationFlag
def generateNewId
def Schemata
def Schema
def isTemporary
def getFolderWhenPortalFactory
def addSubObjects
def getSubObject
def __bobo_traverse__

Public Attributes

 id

Static Public Attributes

tuple security = ClassSecurityInfo()
tuple attr_security = AttributeValidator()
 schema = typecontent_type
list installMode = ['type', 'actions', 'indexes']
tuple content_type = ComputedAttribute(getContentType, 1)
 get_content_type = getContentType
 edit = update

Private Member Functions

def _processForm
 The product of the widgets processing should be: (value, **kwargs) which will be passed to the mutator or None which will simply pass.
def _renameAfterCreation
def _findUniqueId
def _isIDAutoGenerated
def _isSchemaCurrent
def _updateSchema
def _migrateGetValue
def _migrateSetValue

Private Attributes

 _v_cp_refs
 _p_changed
 _at_creation_flag

Static Private Attributes

 _signature = None
 _at_rename_after_creation = False
tuple __implements__ = (z2IBaseObject, )

Detailed Description

Definition at line 116 of file BaseObject.py.


Constructor & Destructor Documentation

def Archetypes.BaseObject.BaseObject.__init__ (   self,
  oid,
  kwargs 
)

Definition at line 138 of file BaseObject.py.

00138 
00139     def __init__(self, oid, **kwargs):
00140         self.id = oid

Here is the caller graph for this function:


Member Function Documentation

def Archetypes.BaseObject.BaseObject.__bobo_traverse__ (   self,
  REQUEST,
  name 
)
Allows transparent access to session subobjects.

Definition at line 1109 of file BaseObject.py.

01109 
01110     def __bobo_traverse__(self, REQUEST, name):
01111         """Allows transparent access to session subobjects.
01112         """
01113         # sometimes, the request doesn't have a response, e.g. when
01114         # PageTemplates traverse through the object path, they pass in
01115         # a phony request (a dict).
01116         RESPONSE = getattr(REQUEST, 'RESPONSE', None)
01117 
01118         # Is it a registered sub object
01119         data = self.getSubObject(name, REQUEST, RESPONSE)
01120         if data is not None:
01121             return data
01122         # Or a standard attribute (maybe acquired...)
01123         target = None
01124         method = REQUEST.get('REQUEST_METHOD', 'GET').upper()
01125         # Logic from "ZPublisher.BaseRequest.BaseRequest.traverse"
01126         # to check whether this is a browser request
01127         if (len(REQUEST.get('TraversalRequestNameStack', ())) == 0 and
01128             not (method in ('GET', 'HEAD', 'POST') and not
01129                  isinstance(RESPONSE, xmlrpc.Response))):
01130             if shasattr(self, name):
01131                 target = getattr(self, name)
01132         else:
01133             if shasattr(self, name): # attributes of self come first
01134                 target = getattr(self, name)
01135             else: # then views
01136                 target = queryMultiAdapter((self, REQUEST), Interface, name)
01137                 if target is not None:
01138                     # We don't return the view, we raise an
01139                     # AttributeError instead (below)
01140                     target = None
01141                 else: # then acquired attributes
01142                     target = getattr(self, name, None)
01143 
01144         if target is not None:
01145             return target
01146         elif (method not in ('GET', 'POST') and not
01147               isinstance(RESPONSE, xmlrpc.Response) and
01148               REQUEST.maybe_webdav_client):
01149             return NullResource(self, name, REQUEST).__of__(self)
01150         else:
01151             # Raising AttributeError will look up views for us
01152             raise AttributeError(name)
01153 
01154 InitializeClass(BaseObject)

Here is the call graph for this function:

Overloads the object's item access.

Definition at line 406 of file BaseObject.py.

00406 
00407     def __getitem__(self, key):
00408         """Overloads the object's item access.
00409         """
00410         # Don't allow key access to hidden attributes
00411         if key.startswith('_'):
00412             raise Unauthorized, key
00413 
00414         schema = self.Schema()
00415         keys = schema.keys()
00416 
00417         if key not in keys and not key.startswith('_'):
00418             # XXX Fix this in AT 1.4
00419             value= getattr(aq_inner(self).aq_explicit, key, _marker) or \
00420                    getattr(aq_parent(aq_inner(self)).aq_explicit, key, _marker)
00421             if value is _marker:
00422                 raise KeyError, key
00423             else:
00424                 return value
00425 
00426         field = schema[key]
00427         accessor = field.getEditAccessor(self)
00428         if not accessor:
00429             accessor = field.getAccessor(self)
00430 
00431         # This is the access mode used by external editor. We need the
00432         # handling provided by BaseUnit when its available
00433         kw = {'raw':1, 'field': field.__name__}
00434         value = mapply(accessor, **kw)
00435         return value

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.BaseObject.BaseObject._findUniqueId (   self,
  id 
) [private]
Find a unique id in the parent folder, based on the given id, by
appending -n, where n is a number between 1 and the constant
RENAME_AFTER_CREATION_ATTEMPTS, set in config.py. If no id can be
found, return None.

Definition at line 779 of file BaseObject.py.

00779 
00780     def _findUniqueId(self, id):
00781         """Find a unique id in the parent folder, based on the given id, by
00782         appending -n, where n is a number between 1 and the constant
00783         RENAME_AFTER_CREATION_ATTEMPTS, set in config.py. If no id can be
00784         found, return None.
00785         """
00786         check_id = getattr(self, 'check_id', None)
00787         if check_id is None:
00788             parent = aq_parent(aq_inner(self))
00789             parent_ids = parent.objectIds()
00790             check_id = lambda id, required: id in parent_ids
00791 
00792         invalid_id = check_id(id, required=1)
00793         if not invalid_id:
00794             return id
00795 
00796         idx = 1
00797         while idx <= RENAME_AFTER_CREATION_ATTEMPTS:
00798             new_id = "%s-%d" % (id, idx)
00799             if not check_id(new_id, required=1):
00800                 return new_id
00801             idx += 1
00802 
00803         return None

Here is the caller graph for this function:

def Archetypes.BaseObject.BaseObject._isIDAutoGenerated (   self,
  id 
) [private]
Avoid busting setDefaults if we don't have a proper acquisition
context.

Definition at line 805 of file BaseObject.py.

00805 
00806     def _isIDAutoGenerated(self, id):
00807         """Avoid busting setDefaults if we don't have a proper acquisition
00808         context.
00809         """
00810         plone_tool = getToolByName(self, 'plone_utils', None)
00811         if plone_tool is not None and \
00812            shasattr(plone_tool, 'isIDAutoGenerated'):
00813             return plone_tool.isIDAutoGenerated(id)
00814         # Plone 2.0 compatibility
00815         script = getattr(self, 'isIDAutoGenerated', None)
00816         if script is not None:
00817             return script(id)
00818         return False

Here is the call graph for this function:

Here is the caller graph for this function:

Determines whether the current object's schema is up to date.

Definition at line 832 of file BaseObject.py.

00832 
00833     def _isSchemaCurrent(self):
00834         """Determines whether the current object's schema is up to date.
00835         """
00836         return self._signature == self.Schema().signature()

Here is the call graph for this function:

def Archetypes.BaseObject.BaseObject._migrateGetValue (   self,
  name,
  new_schema = None 
) [private]
Try to get a value from an object using a variety of methods.

Definition at line 915 of file BaseObject.py.

00915 
00916     def _migrateGetValue(self, name, new_schema=None):
00917         """Try to get a value from an object using a variety of methods."""
00918         schema = self.Schema()
00919         # Migrate pre-AT 1.3 schemas.
00920         schema = fixSchema(schema)
00921         # First see if the new field name is managed by the current schema
00922         field = schema.get(getattr(new_schema.get(name,None),'old_field_name',name), None)
00923         if field:
00924             # At very first try to use the BaseUnit itself
00925             try:
00926                 if IFileField.isImplementedBy(field):
00927                     return field.getBaseUnit(self)
00928 
00929             except (ConflictError, KeyboardInterrupt):
00930                 raise
00931             except:
00932                 pass
00933 
00934             # First try the edit accessor
00935             try:
00936                 editAccessor = field.getEditAccessor(self)
00937                 if editAccessor:
00938                     return editAccessor()
00939 
00940             except (ConflictError, KeyboardInterrupt):
00941                 raise
00942             except:
00943                 pass
00944 
00945             # No luck -- now try the accessor
00946             try:
00947                 accessor = field.getAccessor(self)
00948                 if accessor:
00949                     return accessor()
00950 
00951             except (ConflictError, KeyboardInterrupt):
00952                 raise
00953             except:
00954                 pass
00955             # No luck use standard method to get the value
00956             return field.get(self)
00957 
00958             # Still no luck -- try to get the value directly
00959             # this part should be remove because for some fields this will fail
00960             # if you get the value directly for example for FixPointField
00961             # stored value is (0,0) but the input value is a string.
00962             # at this time FixPointField fails if he got a tuple as input value
00963             # Because of this line value = value.replace(',','.')
00964             try:
00965                 return self[field.getName()]
00966 
00967             except (ConflictError, KeyboardInterrupt):
00968                 raise
00969             except:
00970                 pass
00971 
00972         # Nope -- see if the new accessor method is present
00973         # in the current object.
00974         if new_schema:
00975             new_field = new_schema.get(name)
00976             # Try the new edit accessor
00977             try:
00978                 editAccessor = new_field.getEditAccessor(self)
00979                 if editAccessor:
00980                     return editAccessor()
00981 
00982             except (ConflictError, KeyboardInterrupt):
00983                 raise
00984             except:
00985                 pass
00986 
00987             # Nope -- now try the accessor
00988             try:
00989                 accessor = new_field.getAccessor(self)
00990                 if accessor:
00991                     return accessor()
00992 
00993             except (ConflictError, KeyboardInterrupt):
00994                 raise
00995             except:
00996                 pass
00997 
00998             # Still no luck -- try to get the value directly using the new name
00999             try:
01000                 return self[new_field.getName()]
01001 
01002             except (ConflictError, KeyboardInterrupt):
01003                 raise
01004             except:
01005                 pass
01006 
01007         # Nope -- now see if the current object has an attribute
01008         # with the same name
01009         # as the new field
01010         if shasattr(self, name):
01011             return getattr(self, name)
01012 
01013         raise ValueError, 'name = %s' % (name)

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.BaseObject.BaseObject._migrateSetValue (   self,
  name,
  value,
  old_schema = None,
  kw 
) [private]
Try to set an object value using a variety of methods.

Definition at line 1015 of file BaseObject.py.

01015 
01016     def _migrateSetValue(self, name, value, old_schema=None, **kw):
01017         """Try to set an object value using a variety of methods."""
01018         schema = self.Schema()
01019         # Migrate pre-AT 1.3 schemas.
01020         schema = fixSchema(schema)
01021         field = schema.get(name, None)
01022         # Try using the field's mutator
01023         if field:
01024             mutator = field.getMutator(self)
01025             if mutator is not None:
01026                 try:
01027                     args = [value,]
01028                     mapply(mutator, *args, **kw)
01029                     return
01030 
01031                 except (ConflictError, KeyboardInterrupt):
01032                     raise
01033                 except:
01034                     log_exc()
01035         else:
01036             # Try setting an existing attribute
01037             if shasattr(self, name):
01038                 setattr(self, name, value)
01039                 return
01040         raise ValueError, 'name = %s, value = %s' % (name, value)

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.BaseObject.BaseObject._processForm (   self,
  data = 1,
  metadata = None,
  REQUEST = None,
  values = None 
) [private]

The product of the widgets processing should be: (value, **kwargs) which will be passed to the mutator or None which will simply pass.

Definition at line 592 of file BaseObject.py.

00592 
00593     def _processForm(self, data=1, metadata=None, REQUEST=None, values=None):
00594         request = REQUEST or self.REQUEST
00595         if values:
00596             form = values
00597         else:
00598             form = request.form
00599         fieldset = form.get('fieldset', None)
00600         schema = self.Schema()
00601         schemata = self.Schemata()
00602         fields = []
00603 
00604         if not IMultiPageSchema.providedBy(self):
00605             fields = schema.fields()
00606         elif fieldset is not None:
00607             fields = schemata[fieldset].fields()
00608         else:
00609             if data: fields += schema.filterFields(isMetadata=0)
00610             if metadata: fields += schema.filterFields(isMetadata=1)
00611 
00612         form_keys = form.keys()
00613 
00614         for field in fields:
00615             ## Delegate to the widget for processing of the form
00616             ## element.  This means that if the widget needs _n_
00617             ## fields under a naming convention it can handle this
00618             ## internally.  The calling API is process_form(instance,
00619             ## field, form) where instance should rarely be needed,
00620             ## field is the field object and form is the dict. of
00621             ## kv_pairs from the REQUEST
00622             ##
00623             ## The product of the widgets processing should be:
00624             ##   (value, **kwargs) which will be passed to the mutator
00625             ##   or None which will simply pass
00626 
00627             if not field.writeable(self):
00628                 # If the field has no 'w' in mode, or the user doesn't
00629                 # have the required permission, or the mutator doesn't
00630                 # exist just bail out.
00631                 continue
00632 
00633             try:
00634                 # Pass validating=False to inform the widget that we
00635                 # aren't in the validation phase, IOW, the returned
00636                 # data will be forwarded to the storage
00637                 result = field.widget.process_form(self, field, form,
00638                                                    empty_marker=_marker,
00639                                                    validating=False)
00640             except TypeError:
00641                 # Support for old-style process_form methods
00642                 result = field.widget.process_form(self, field, form,
00643                                                    empty_marker=_marker)
00644 
00645             if result is _marker or result is None:
00646                 continue
00647 
00648             # Set things by calling the mutator
00649             mutator = field.getMutator(self)
00650             __traceback_info__ = (self, field, mutator)
00651             result[1]['field'] = field.__name__
00652             mapply(mutator, result[0], **result[1])
00653 
00654         self.reindexObject()

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.BaseObject.BaseObject._renameAfterCreation (   self,
  check_auto_id = False 
) [private]
Renames an object like its normalized title.

Definition at line 743 of file BaseObject.py.

00743 
00744     def _renameAfterCreation(self, check_auto_id=False):
00745         """Renames an object like its normalized title.
00746         """
00747         old_id = self.getId()
00748         if check_auto_id and not self._isIDAutoGenerated(old_id):
00749             # No auto generated id
00750             return False
00751 
00752         new_id = self.generateNewId()
00753         if new_id is None:
00754             return False
00755 
00756         invalid_id = True
00757         check_id = getattr(self, 'check_id', None)
00758         if check_id is not None:
00759             invalid_id = check_id(new_id, required=1)
00760 
00761         # If check_id told us no, or if it was not found, make sure we have an
00762         # id unique in the parent folder.
00763         if invalid_id:
00764             unique_id = self._findUniqueId(new_id)
00765             if unique_id is not None:
00766                 if check_id is None or check_id(new_id, required=1):
00767                     new_id = unique_id
00768                     invalid_id = False
00769 
00770         if not invalid_id:
00771             # Can't rename without a subtransaction commit when using
00772             # portal_factory!
00773             transaction.savepoint(optimistic=True)
00774             self.setId(new_id)
00775             return new_id
00776 
00777         return False

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.BaseObject.BaseObject._updateSchema (   self,
  excluded_fields = [],
  out = None,
  remove_instance_schemas = False 
) [private]
Updates an object's schema when the class schema changes.

For each field we use the existing accessor to get its value,
then we re-initialize the class, then use the new schema
mutator for each field to set the values again.

We also copy over any class methods to handle product
refreshes gracefully (when a product refreshes, you end up
with both the old version of the class and the new in memory
at the same time -- you really should restart zope after doing
a schema update).

Definition at line 839 of file BaseObject.py.

00839 
00840                       remove_instance_schemas=False):
00841         """Updates an object's schema when the class schema changes.
00842 
00843         For each field we use the existing accessor to get its value,
00844         then we re-initialize the class, then use the new schema
00845         mutator for each field to set the values again.
00846 
00847         We also copy over any class methods to handle product
00848         refreshes gracefully (when a product refreshes, you end up
00849         with both the old version of the class and the new in memory
00850         at the same time -- you really should restart zope after doing
00851         a schema update).
00852         """
00853         if out is not None:
00854             print >> out, 'Updating %s' % (self.getId())
00855 
00856         if remove_instance_schemas and 'schema' in self.__dict__:
00857             if out is not None:
00858                 print >> out, 'Removing schema from instance dict.'
00859             del self.schema
00860         new_schema = self.Schema()
00861 
00862         # Read all the old values into a dict
00863         values = {}
00864         mimes = {}
00865         for f in new_schema.fields():
00866             name = f.getName()
00867             if name in excluded_fields: continue
00868             if f.type == "reference": continue
00869             try:
00870                 values[name] = self._migrateGetValue(name, new_schema)
00871             except ValueError:
00872                 if out is not None:
00873                     print >> out, ('Unable to get %s.%s'
00874                                    % (str(self.getId()), name))
00875             else:
00876                 if shasattr(f, 'getContentType'):
00877                     mimes[name] = f.getContentType(self)
00878 
00879         obj_class = self.__class__
00880         current_class = getattr(sys.modules[self.__module__],
00881                                 self.__class__.__name__)
00882         if obj_class.schema != current_class.schema:
00883             # XXX This is kind of brutish.  We do this to make sure that old
00884             # class instances have the proper methods after a refresh.  The
00885             # best thing to do is to restart Zope after doing an update, and
00886             # the old versions of the class will disappear.
00887 
00888             for k in current_class.__dict__.keys():
00889                 obj_class.__dict__[k] = current_class.__dict__[k]
00890 
00891         # Set a request variable to avoid resetting the newly created flag
00892         req = getattr(self, 'REQUEST', None)
00893         if req is not None:
00894             req.set('SCHEMA_UPDATE','1')
00895         self.initializeArchetype()
00896 
00897         for f in new_schema.fields():
00898             name = f.getName()
00899             kw = {}
00900             if name not in excluded_fields and values.has_key(name):
00901                 if mimes.has_key(name):
00902                     kw['mimetype'] = mimes[name]
00903                 try:
00904                     self._migrateSetValue(name, values[name], **kw)
00905                 except ValueError:
00906                     if out is not None:
00907                         print >> out, ('Unable to set %s.%s to '
00908                                        '%s' % (str(self.getId()),
00909                                                name, str(values[name])))
00910         # Make sure the changes are persisted
00911         self._p_changed = 1
00912         if out is not None:
00913             return out

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.BaseObject.BaseObject.addSubObjects (   self,
  objects,
  REQUEST = None 
)
Adds a dictionary of objects to a volatile attribute.

Definition at line 1082 of file BaseObject.py.

01082 
01083     def addSubObjects(self, objects, REQUEST=None):
01084         """Adds a dictionary of objects to a volatile attribute.
01085         """
01086         if objects:
01087             storage = getattr(aq_base(self), '_v_at_subobjects', None)
01088             if storage is None:
01089                 setattr(self, '_v_at_subobjects', {})
01090                 storage = getattr(aq_base(self), '_v_at_subobjects')
01091             for name, obj in objects.items():
01092                 storage[name] = aq_base(obj)

Definition at line 676 of file BaseObject.py.

00676 
00677     def at_post_create_script(self):
00678         pass

Here is the caller graph for this function:

Definition at line 681 of file BaseObject.py.

00681 
00682     def at_post_edit_script(self):
00683         pass

Here is the caller graph for this function:

Returns True if the object has been fully saved, False otherwise.

Definition at line 714 of file BaseObject.py.

00714 
00715     def checkCreationFlag(self):
00716         """Returns True if the object has been fully saved, False otherwise.
00717         """
00718         return getattr(aq_base(self), '_at_creation_flag', False)

Here is the caller graph for this function:

def Archetypes.BaseObject.BaseObject.cleanupLayers (   self,
  item = None,
  container = None 
)

Definition at line 181 of file BaseObject.py.

00181 
00182     def cleanupLayers(self, item=None, container=None):
00183         self.Schema().cleanupLayers(self, item, container)

Here is the call graph for this function:

Here is the caller graph for this function:

Suggest an id for this object.
This id is used when automatically renaming an object after creation.

Definition at line 719 of file BaseObject.py.

00719 
00720     def generateNewId(self):
00721         """Suggest an id for this object.
00722         This id is used when automatically renaming an object after creation.
00723         """
00724         title = self.Title()
00725         # Can't work w/o a title
00726         if not title:
00727             return None
00728 
00729         # Don't do anything without the plone.i18n package
00730         if not URL_NORMALIZER:
00731             return None
00732 
00733         if not isinstance(title, unicode):
00734             charset = self.getCharset()
00735             title = unicode(title, charset)
00736 
00737         request = getattr(self, 'REQUEST', None)
00738         if request is not None:
00739             return IUserPreferredURLNormalizer(request).normalize(title)
00740 
00741         return queryUtility(IURLNormalizer).normalize(title)

Here is the call graph for this function:

Here is the caller graph for this function:

Returns the portal_metadata for a field.

Definition at line 368 of file BaseObject.py.

00368 
00369     def get_portal_metadata(self, field):
00370         """Returns the portal_metadata for a field.
00371         """
00372         pmt = getToolByName(self, 'portal_metadata')
00373         policy = None
00374         try:
00375             schema = getattr(pmt, 'DCMI', None)
00376             spec = schema.getElementSpec(field.accessor)
00377             policy = spec.getPolicy(self.portal_type)
00378         except (ConflictError, KeyboardInterrupt):
00379             raise
00380         except:
00381             log_exc()
00382             return None, False
00383 
00384         if not policy:
00385             policy = spec.getPolicy(None)
00386 
00387         return DisplayList(map(lambda x: (x,x), policy.allowedVocabulary())), \
00388                policy.enforceVocabulary()

Here is the call graph for this function:

Here is the caller graph for this function:

Used for FTP and apparently the ZMI now too.

Definition at line 583 of file BaseObject.py.

00583 
00584     def get_size(self):
00585         """Used for FTP and apparently the ZMI now too.
00586         """
00587         size = 0
00588         for field in self.Schema().fields():
00589             size+=field.get_size(self)
00590         return size

Here is the call graph for this function:

Here is the caller graph for this function:

Returns the site default charset, or utf-8.

Definition at line 572 of file BaseObject.py.

00572 
00573     def getCharset(self):
00574         """Returns the site default charset, or utf-8.
00575         """
00576         properties = getToolByName(self, 'portal_properties', None)
00577         if properties is not None:
00578             site_properties = getattr(properties, 'site_properties', None)
00579             if site_properties is not None:
00580                 return site_properties.getProperty('default_charset')
00581         return 'utf-8'

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.BaseObject.BaseObject.getContentType (   self,
  key = None 
)
Returns the content type from a field.

Definition at line 307 of file BaseObject.py.

00307 
00308     def getContentType(self, key=None):
00309         """Returns the content type from a field.
00310         """
00311         value = 'text/plain'
00312 
00313         if key is None:
00314             field = self.getPrimaryField()
00315         else:
00316             field = self.getField(key) or getattr(self, key, None)
00317 
00318         if field and shasattr(field, 'getContentType'):
00319             return field.getContentType(self)
00320 
00321         return value

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.BaseObject.BaseObject.getDefault (   self,
  field 
)
Return the default value of a field.

Definition at line 252 of file BaseObject.py.

00252 
00253     def getDefault(self, field):
00254         """Return the default value of a field.
00255         """
00256         field = self.getField(field)
00257         return field.getDefault(self)

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.BaseObject.BaseObject.getField (   self,
  key,
  wrapped = False 
)
Returns a field object.

Definition at line 238 of file BaseObject.py.

00238 
00239     def getField(self, key, wrapped=False):
00240         """Returns a field object.
00241         """
00242         return self.Schema().get(key)

Here is the call graph for this function:

def Archetypes.BaseObject.BaseObject.getFilename (   self,
  key = None 
)
Returns the filename from a field.

Definition at line 291 of file BaseObject.py.

00291 
00292     def getFilename(self, key=None):
00293         """Returns the filename from a field.
00294         """
00295         value = None
00296 
00297         if key is None:
00298             field = self.getPrimaryField()
00299         else:
00300             field = self.getField(key) or getattr(self, key, None)
00301 
00302         if field and shasattr(field, 'getFilename'):
00303             return field.getFilename(self)
00304 
00305         return value

Here is the call graph for this function:

Here is the caller graph for this function:

Returns the folder where this object was created temporarily.

Definition at line 1051 of file BaseObject.py.

01051 
01052     def getFolderWhenPortalFactory(self):
01053         """Returns the folder where this object was created temporarily.
01054         """
01055         ctx = aq_inner(self)
01056         if not ctx.isTemporary():
01057             # Not a temporary object!
01058             return aq_parent(ctx)
01059         utool = getToolByName(self, 'portal_url')
01060         portal_object = utool.getPortalObject()
01061 
01062         while ctx.getId() != 'portal_factory':
01063             # Find the portal factory object
01064             if ctx == portal_object:
01065                 # uups, shouldn't happen!
01066                 return ctx
01067             ctx = aq_parent(ctx)
01068         # ctx is now the portal_factory in our parent folder
01069         return aq_parent(ctx)

Here is the call graph for this function:

Gets the object id.

Definition at line 195 of file BaseObject.py.

00195 
00196     def getId(self):
00197         """Gets the object id.
00198         """
00199         return self.id

The primary field is some object that responds to
PUT/manage_FTPget events.

Definition at line 358 of file BaseObject.py.

00358 
00359     def getPrimaryField(self):
00360         """The primary field is some object that responds to
00361         PUT/manage_FTPget events.
00362         """
00363         fields = self.Schema().filterFields(primary=1)
00364         if fields:
00365             return fields[0]
00366         return None

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.BaseObject.BaseObject.getSubObject (   self,
  name,
  REQUEST,
  RESPONSE = None 
)
Gets a dictionary of objects from a volatile attribute.

Definition at line 1094 of file BaseObject.py.

01094 
01095     def getSubObject(self, name, REQUEST, RESPONSE=None):
01096         """Gets a dictionary of objects from a volatile attribute.
01097         """
01098         storage = getattr(aq_base(self), '_v_at_subobjects', None)
01099         if storage is None:
01100             return None
01101 
01102         data = storage.get(name, None)
01103         if data is None:
01104             return None
01105 
01106         mtr = self.mimetypes_registry
01107         mt = mtr.classify(data, filename=name)
01108         return Wrapper(data, name, str(mt) or 'application/octet-stream').__of__(self)

Here is the caller graph for this function:

Gets a field by id which is explicitly wrapped.

XXX Maybe we should subclass field from Acquisition.Explicit?

Definition at line 244 of file BaseObject.py.

00244 
00245     def getWrappedField(self, key):
00246         """Gets a field by id which is explicitly wrapped.
00247 
00248         XXX Maybe we should subclass field from Acquisition.Explicit?
00249         """
00250         return ExplicitAcquisitionWrapper(self.getField(key), self)

Here is the call graph for this function:

Called by the generated add* factory in types tool.

Definition at line 143 of file BaseObject.py.

00143 
00144     def initializeArchetype(self, **kwargs):
00145         """Called by the generated add* factory in types tool.
00146         """
00147         try:
00148             self.initializeLayers()
00149             self.markCreationFlag()
00150             self.setDefaults()
00151             if kwargs:
00152                 kwargs['_initializing_'] = True
00153                 self.edit(**kwargs)
00154             self._signature = self.Schema().signature()
00155         except (ConflictError, KeyboardInterrupt):
00156             raise
00157         except:
00158             log_exc()

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.BaseObject.BaseObject.initializeLayers (   self,
  item = None,
  container = None 
)

Definition at line 177 of file BaseObject.py.

00177 
00178     def initializeLayers(self, item=None, container=None):
00179         self.Schema().initializeLayers(self, item, container)

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.BaseObject.BaseObject.isBinary (   self,
  key 
)
Return wether a field contains binary data.

Definition at line 259 of file BaseObject.py.

00259 
00260     def isBinary(self, key):
00261         """Return wether a field contains binary data.
00262         """
00263         field = self.getField(key)
00264         if IFileField.isImplementedBy(field):
00265             value = field.getBaseUnit(self)
00266             return value.isBinary()
00267         mimetype = self.getContentType(key)
00268         if mimetype and shasattr(mimetype, 'binary'):
00269             return mimetype.binary
00270         elif mimetype and mimetype.find('text') >= 0:
00271             return 0
00272         return 1

Here is the call graph for this function:

Here is the caller graph for this function:

Checks to see if we are created as temporary object by
portal factory.

Definition at line 1042 of file BaseObject.py.

01042 
01043     def isTemporary(self):
01044         """Checks to see if we are created as temporary object by
01045         portal factory.
01046         """
01047         parent = aq_parent(aq_inner(self))
01048         return shasattr(parent, 'meta_type') and \
01049                parent.meta_type == 'TempFolder'

Here is the call graph for this function:

Here is the caller graph for this function:

Returns wether a field is transformable.

Definition at line 274 of file BaseObject.py.

00274 
00275     def isTransformable(self, name):
00276         """Returns wether a field is transformable.
00277         """
00278         field = self.getField(name)
00279         return isinstance(field, TextField) or not self.isBinary(name)

Here is the call graph for this function:

def Archetypes.BaseObject.BaseObject.manage_afterAdd (   self,
  item,
  container 
)

Definition at line 160 of file BaseObject.py.

00160 
00161     def manage_afterAdd(self, item, container):
00162         __traceback_info__ = (self, item, container)
00163         Referenceable.manage_afterAdd(self, item, container)
00164         self.initializeLayers(item, container)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 166 of file BaseObject.py.

00166 
00167     def manage_afterClone(self, item):
00168         __traceback_info__ = (self, item)
00169         Referenceable.manage_afterClone(self, item)

def Archetypes.BaseObject.BaseObject.manage_beforeDelete (   self,
  item,
  container 
)

Definition at line 171 of file BaseObject.py.

00171 
00172     def manage_beforeDelete(self, item, container):
00173         __traceback_info__ = (self, item, container)
00174         self.cleanupLayers(item, container)
00175         Referenceable.manage_beforeDelete(self, item, container)

Here is the call graph for this function:

Sets flag on the instance to indicate that the object hasn't been
saved properly (unset in content_edit).

This will only be done if a REQUEST is present to ensure that objects
created programmatically are considered fully created.

Definition at line 686 of file BaseObject.py.

00686 
00687     def markCreationFlag(self):
00688         """Sets flag on the instance to indicate that the object hasn't been
00689         saved properly (unset in content_edit).
00690 
00691         This will only be done if a REQUEST is present to ensure that objects
00692         created programmatically are considered fully created.
00693         """
00694         req = getattr(self, 'REQUEST', None)
00695         if shasattr(req, 'get'):
00696             if req.get('SCHEMA_UPDATE', None) is not None:
00697                 return
00698             meth = req.get('REQUEST_METHOD', None)
00699             # Ensure that we have an HTTP request, if you're creating an
00700             # object with something other than a GET or POST, then we assume
00701             # you are making a complete object.
00702             if meth in ('GET', 'POST'):
00703                 self._at_creation_flag = True

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.BaseObject.BaseObject.post_validate (   self,
  REQUEST = None,
  errors = None 
)

Definition at line 486 of file BaseObject.py.

00486 
00487     def post_validate(self, REQUEST=None, errors=None):
00488         pass

Here is the caller graph for this function:

def Archetypes.BaseObject.BaseObject.pre_validate (   self,
  REQUEST = None,
  errors = None 
)

Pre/post validate hooks that will need to write errors into the errors dict directly using errors[fieldname] = "".

Definition at line 482 of file BaseObject.py.

00482 
00483     def pre_validate(self, REQUEST=None, errors=None):
00484         pass

Here is the caller graph for this function:

def Archetypes.BaseObject.BaseObject.processForm (   self,
  data = 1,
  metadata = 0,
  REQUEST = None,
  values = None 
)
Processes the schema looking for data in the form.

Definition at line 656 of file BaseObject.py.

00656 
00657     def processForm(self, data=1, metadata=0, REQUEST=None, values=None):
00658         """Processes the schema looking for data in the form.
00659         """
00660         is_new_object = self.checkCreationFlag()
00661         self._processForm(data=data, metadata=metadata,
00662                           REQUEST=REQUEST, values=values)
00663         self.unmarkCreationFlag()
00664         if self._at_rename_after_creation and is_new_object:
00665             self._renameAfterCreation(check_auto_id=True)
00666 
00667         # Post create/edit hooks
00668         if is_new_object:
00669             event.notify(ObjectInitializedEvent(self))
00670             self.at_post_create_script()
00671         else:
00672             event.notify(ObjectEditedEvent(self))
00673             self.at_post_edit_script()

Here is the call graph for this function:

Return a (wrapped) schema instance for this object instance.

Definition at line 825 of file BaseObject.py.

00825 
00826     def Schema(self):
00827         """Return a (wrapped) schema instance for this object instance.
00828         """
00829         schema = ISchema(self)
00830         return ImplicitAcquisitionWrapper(schema, self)

Here is the caller graph for this function:

Returns the Schemata for the Object.

Definition at line 820 of file BaseObject.py.

00820 
00821     def Schemata(self):
00822         """Returns the Schemata for the Object.
00823         """
00824         return getSchemata(self)

Here is the call graph for this function:

Here is the caller graph for this function:

All fields marked as 'searchable' are concatenated together
here for indexing purpose.

Definition at line 526 of file BaseObject.py.

00526 
00527     def SearchableText(self):
00528         """All fields marked as 'searchable' are concatenated together
00529         here for indexing purpose.
00530         """
00531         data = []
00532         charset = self.getCharset()
00533         for field in self.Schema().fields():
00534             if not field.searchable:
00535                 continue
00536             method = field.getIndexAccessor(self)
00537             try:
00538                 datum =  method(mimetype="text/plain")
00539             except TypeError:
00540                 # Retry in case typeerror was raised because accessor doesn't
00541                 # handle the mimetype argument
00542                 try:
00543                     datum =  method()
00544                 except (ConflictError, KeyboardInterrupt):
00545                     raise
00546                 except:
00547                     continue
00548             if datum:
00549                 type_datum = type(datum)
00550                 vocab = field.Vocabulary(self)
00551                 if isinstance(datum, list) or isinstance(datum, tuple):
00552                     # Unmangle vocabulary: we index key AND value
00553                     vocab_values = map(lambda value, vocab=vocab: vocab.getValue(value, ''), datum)
00554                     datum = list(datum)
00555                     datum.extend(vocab_values)
00556                     datum = ' '.join(datum)
00557                 elif isinstance(datum, basestring):
00558                     if isinstance(datum, unicode):
00559                         datum = datum.encode(charset)
00560                     value = vocab.getValue(datum, '')
00561                     if isinstance(value, unicode):
00562                         value = value.encode(charset)
00563                     datum = "%s %s" % (datum, value, )
00564 
00565                 if isinstance(datum, unicode):
00566                     datum = datum.encode(charset)
00567                 data.append(str(datum))
00568 
00569         data = ' '.join(data)
00570         return data

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.BaseObject.BaseObject.setContentType (   self,
  value,
  key = None 
)
Sets the content type of a field.

Definition at line 334 of file BaseObject.py.

00334 
00335     def setContentType(self, value, key=None):
00336         """Sets the content type of a field.
00337         """
00338         if key is None:
00339             field = self.getPrimaryField()
00340         else:
00341             field = self.getField(key) or getattr(self, key, None)
00342 
00343         if field and IFileField.isImplementedBy(field):
00344             field.setContentType(self, value)

Here is the call graph for this function:

Here is the caller graph for this function:

Sets the field values to the default values.

Definition at line 437 of file BaseObject.py.

00437 
00438     def setDefaults(self):
00439         """Sets the field values to the default values.
00440         """
00441         self.Schema().setDefaults(self)

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.BaseObject.BaseObject.setFilename (   self,
  value,
  key = None 
)
Sets the filename of a field.

Definition at line 346 of file BaseObject.py.

00346 
00347     def setFilename(self, value, key=None):
00348         """Sets the filename of a field.
00349         """
00350         if key is None:
00351             field = self.getPrimaryField()
00352         else:
00353             field = self.getField(key) or getattr(self, key, None)
00354 
00355         if field and IFileField.isImplementedBy(field):
00356             field.setFilename(self, value)

Here is the call graph for this function:

def Archetypes.BaseObject.BaseObject.setId (   self,
  value 
)
Sets the object id.

Definition at line 201 of file BaseObject.py.

00201 
00202     def setId(self, value):
00203         """Sets the object id.
00204         """
00205         if value != self.getId():
00206             parent = aq_parent(aq_inner(self))
00207             if parent is not None:
00208                 # See Referenceable, keep refs on what is a move/rename
00209                 self._v_cp_refs = 1
00210                 # We can't rename if the object is locked
00211                 if HAS_LOCKING:
00212                     lockable = ILockable(self)
00213                     was_locked = False
00214                     if lockable.locked():
00215                         was_locked = True
00216                         lockable.unlock()
00217                     parent.manage_renameObject(self.id, value)
00218                     if was_locked:
00219                         lockable.lock()
00220                 else:
00221                     parent.manage_renameObject(self.id, value)
00222             self._setId(value)

Here is the call graph for this function:

Here is the caller graph for this function:

Returns the title if it is not blank and the id otherwise.

Definition at line 185 of file BaseObject.py.

00185 
00186     def title_or_id(self):
00187         """Returns the title if it is not blank and the id otherwise.
00188         """
00189         if shasattr(self, 'Title'):
00190             if callable(self.Title):
00191                 return self.Title() or self.getId()
00192 
00193         return self.getId()

Here is the call graph for this function:

Dublin Core element - Object type.

this method is redefined in ExtensibleMetadata but we need this
at the object level (i.e. with or without metadata) to interact
with the uid catalog.

Definition at line 224 of file BaseObject.py.

00224 
00225     def Type(self):
00226         """Dublin Core element - Object type.
00227 
00228         this method is redefined in ExtensibleMetadata but we need this
00229         at the object level (i.e. with or without metadata) to interact
00230         with the uid catalog.
00231         """
00232         if shasattr(self, 'getTypeInfo'):
00233             ti = self.getTypeInfo()
00234             if ti is not None:
00235                 return ti.Title()
00236         return self.meta_type

Here is the call graph for this function:

Here is the caller graph for this function:

Removes the creation flag.

Definition at line 706 of file BaseObject.py.

00706 
00707     def unmarkCreationFlag(self):
00708         """Removes the creation flag.
00709         """
00710         if shasattr(aq_inner(self), '_at_creation_flag'):
00711             self._at_creation_flag = False

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.BaseObject.BaseObject.update (   self,
  kwargs 
)
Changes the values of the field and reindex the object.

Definition at line 443 of file BaseObject.py.

00443 
00444     def update(self, **kwargs):
00445         """Changes the values of the field and reindex the object.
00446         """
00447         initializing = kwargs.get('_initializing_', False)
00448         if initializing:
00449             del kwargs['_initializing_']
00450         self.Schema().updateAll(self, **kwargs)
00451         self._p_changed = 1
00452         if not initializing:
00453             # Avoid double indexing during initialization.
00454             self.reindexObject()

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.BaseObject.BaseObject.validate (   self,
  REQUEST = None,
  errors = None,
  data = None,
  metadata = None 
)
Validates the form data from the request.

Definition at line 490 of file BaseObject.py.

00490 
00491     def validate(self, REQUEST=None, errors=None, data=None, metadata=None):
00492         """Validates the form data from the request.
00493         """
00494         if errors is None:
00495             errors = {}
00496 
00497         self.pre_validate(REQUEST, errors)
00498 
00499         for pre_validator in subscribers((self,), IObjectPreValidation):
00500             pre_errors = pre_validator(REQUEST)
00501             if pre_errors is not None:
00502                 for field_name, error_message in pre_errors.items():
00503                     if field_name in errors:
00504                         errors[field_name] += " %s" % error_message
00505                     else:
00506                         errors[field_name] = error_message
00507 
00508         if errors:
00509             return errors
00510         self.Schema().validate(instance=self, REQUEST=REQUEST,
00511                                errors=errors, data=data, metadata=metadata)
00512 
00513         self.post_validate(REQUEST, errors)
00514 
00515         for post_validator in subscribers((self,), IObjectPostValidation):
00516             post_errors = post_validator(REQUEST)
00517             if post_errors is not None:
00518                 for field_name, error_message in post_errors.items():
00519                     if field_name in errors:
00520                         errors[field_name] += " %s" % error_message
00521                     else:
00522                         errors[field_name] = error_message
00523 
00524         return errors

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.BaseObject.BaseObject.validate_field (   self,
  name,
  value,
  errors 
)
Field's validate hook.

Write a method: validate_foo(new_value) -> "error" or None
If there is a validate method defined for a given field invoke
it by name
name -- the name to register errors under
value -- the proposed new value
errors -- dict to record errors in

Definition at line 460 of file BaseObject.py.

00460 
00461     def validate_field(self, name, value, errors):
00462         """Field's validate hook.
00463 
00464         Write a method: validate_foo(new_value) -> "error" or None
00465         If there is a validate method defined for a given field invoke
00466         it by name
00467         name -- the name to register errors under
00468         value -- the proposed new value
00469         errors -- dict to record errors in
00470         """
00471         methodName = "validate_%s" % name
00472         result = None
00473         if shasattr(self, methodName):
00474             method = getattr(self, methodName)
00475             result = method(value)
00476             if result is not None:
00477                 errors[name] = result
00478         return result

Here is the call graph for this function:

Returns the vocabulary for a specified field.

Definition at line 390 of file BaseObject.py.

00390 
00391     def Vocabulary(self, key):
00392         """Returns the vocabulary for a specified field.
00393         """
00394         vocab, enforce = None, 0
00395         field = self.getField(key)
00396         if field:
00397             if field.isMetadata:
00398                 vocab, enforce = self.get_portal_metadata(field)
00399 
00400             if vocab is None:
00401                 vocab, enforce = field.Vocabulary(self), \
00402                                  field.enforceVocabulary
00403         if vocab is None:
00404             vocab = DisplayList()
00405         return vocab, enforce

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.BaseObject.BaseObject.widget (   self,
  field_name,
  mode = "view",
  field = None,
  kwargs 
)
Returns the rendered widget.

Definition at line 281 of file BaseObject.py.

00281 
00282     def widget(self, field_name, mode="view", field=None, **kwargs):
00283         """Returns the rendered widget.
00284         """
00285         if field is None:
00286             field = self.Schema()[field_name]
00287         widget = field.widget
00288         return renderer.render(field_name, mode, widget, self, field=field,
00289                                **kwargs)

Here is the call graph for this function:


Member Data Documentation

tuple Archetypes.BaseObject.BaseObject.__implements__ = (z2IBaseObject, ) [static, private]

Definition at line 135 of file BaseObject.py.

Definition at line 702 of file BaseObject.py.

Definition at line 133 of file BaseObject.py.

Definition at line 450 of file BaseObject.py.

Definition at line 129 of file BaseObject.py.

Definition at line 208 of file BaseObject.py.

tuple Archetypes.BaseObject.BaseObject.attr_security = AttributeValidator() [static]

Definition at line 123 of file BaseObject.py.

tuple Archetypes.BaseObject.BaseObject.content_type = ComputedAttribute(getContentType, 1) [static]

Definition at line 325 of file BaseObject.py.

Definition at line 456 of file BaseObject.py.

Definition at line 330 of file BaseObject.py.

Definition at line 139 of file BaseObject.py.

list Archetypes.BaseObject.BaseObject.installMode = ['type', 'actions', 'indexes'] [static]

Definition at line 131 of file BaseObject.py.

Archetypes.BaseObject.BaseObject.schema = typecontent_type [static]

Definition at line 128 of file BaseObject.py.

tuple Archetypes.BaseObject.BaseObject.security = ClassSecurityInfo() [static]

Definition at line 118 of file BaseObject.py.


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