Back to index

plone3  3.1.7
Classes | Functions
Archetypes.Storage.annotation Namespace Reference

Classes

class  BaseAnnotationStorage
class  AnnotationStorage
class  MetadataAnnotationStorage

Functions

def migrateStorageOfType
def _attr2ann
def _meta2ann

Function Documentation

def Archetypes.Storage.annotation._attr2ann (   clean_obj,
  ann,
  fields 
) [private]
Attribute 2 annotation

Definition at line 215 of file annotation.py.

00215 
00216 def _attr2ann(clean_obj, ann, fields):
00217     """Attribute 2 annotation
00218     """
00219     for field in fields:
00220         if not ann.hasSubkey(AT_ANN_STORAGE, field):
00221             value = getattr(clean_obj, field, _marker)
00222             if value is not _marker:
00223                 delattr(clean_obj, field)
00224                 ann.setSubkey(AT_ANN_STORAGE, value, subkey=field)
00225         else:
00226             value = getattr(clean_obj, field, _marker)
00227             if value is not _marker:
00228                 delattr(clean_obj, field)
    

Here is the caller graph for this function:

def Archetypes.Storage.annotation._meta2ann (   clean_obj,
  ann,
  fields 
) [private]
metadata 2 annotation

Definition at line 229 of file annotation.py.

00229 
00230 def _meta2ann(clean_obj, ann, fields):
00231     """metadata 2 annotation
00232     """
00233     md = clean_obj._md
00234     for field in fields:
00235         if not ann.hasSubkey(AT_MD_STORAGE, field):
00236             value = md.get(field, _marker)
00237             if value is not _marker:
00238                 del md[field]
00239                 ann.setSubkey(AT_MD_STORAGE, value, subkey=field)
00240         else:
00241             try:
00242                 del md[field]
00243             except KeyError:
00244                 pass

Here is the caller graph for this function:

def Archetypes.Storage.annotation.migrateStorageOfType (   portal,
  portal_type,
  schema 
)
Migrate storage from attribute to annotation storage

portal - portal
portal_type - portal type name to migrate
schema - schema of the type

The schema is used to detect annotation and metadata annotation stored field for
migration.

Definition at line 178 of file annotation.py.

00178 
00179 def migrateStorageOfType(portal, portal_type, schema):
00180     """Migrate storage from attribute to annotation storage
00181     
00182     portal - portal
00183     portal_type - portal type name to migrate
00184     schema - schema of the type
00185     
00186     The schema is used to detect annotation and metadata annotation stored field for
00187     migration.
00188     """
00189     catalog = getToolByName(portal, 'portal_catalog')
00190     brains = catalog(Type = portal_type)
00191     
00192     fields = [ field.getName()
00193         for field in schema.fields() 
00194         if field.storage.__class__ == AnnotationStorage
00195         ]
00196     md_fields = [ field.getName()
00197         for field in schema.fields() 
00198         if field.storage.__class__ == MetadataAnnotationStorage
00199         ]
00200     
00201     for brain in brains:
00202         obj = brain.getObject()
00203         if obj is None:
00204             continue
00205         
00206         try: state = obj._p_changed
00207         except: state = 0
00208         
00209         ann = getAnnotation(obj)
00210         clean_obj = aq_base(obj)
00211         _attr2ann(clean_obj, ann, fields)
00212         _meta2ann(clean_obj, ann, md_fields)
00213         
00214         if state is None: obj._p_deactivate()

Here is the call graph for this function: