Beispiel #1
0
 def set(self, name, instance, value, **kwargs):
     # Remove acquisition wrappers
     value = aq_base(value)
     ann = getAnnotation(instance)
     ann.setSubkey(self._key, value, subkey=name)
     if self._migrate:
         self._cleanup(name, instance, value, **kwargs)
Beispiel #2
0
 def initializeField(self, instance, field):
     # Check for already existing field to avoid  the reinitialization
     # (which means overwriting) of an already existing field after a
     # copy or rename operation
     ann = getAnnotation(instance)
     if not ann.hasSubkey(self._key, subkey=field.getName()):
         self.set(field.getName(), instance, field.getDefault(instance))
Beispiel #3
0
 def get(self, name, instance, **kwargs):
     ann = getAnnotation(instance)
     value = ann.getSubkey(self._key, subkey=name, default=_marker)
     if value is _marker:
         if self._migrate:
             value = self._migration(name, instance, **kwargs)
         else:
             raise AttributeError(name)
     return value
Beispiel #4
0
def _migrate_book(obj):
    fields = [
        'title', 'description', 'use_titlepage', 'use_toc', 'use_lot',
        'use_loi'
    ]

    ann = getAnnotation(obj)

    for name in fields:
        value = ann.getSubkey(AT_ANN_STORAGE, subkey=name, default=_marker)

        if value is not _marker:
            obj.getField(name).set(obj, value)
Beispiel #5
0
def upgrade_step_2(context):
    """Upgrade timezone and recurrence from AnnotationStorage to new storage
    (AttributeStorage).

    Using Products.contentmigration doesn't work here, since on migration time,
    the fields' storage is already an AttributeStorage.

    !!! ATTENTION !!!
    This upgrade steps migrates fields if there is a AnnotationStorage entry
    for it, even if there is already a value in AttributeStorage. We have to
    do so, because there is a default value for the timezone, which might not
    be the value previously set with AnnotationStorage.

    """
    migrate_fields = ['timezone', 'recurrence']

    query = {}
    query['object_provides'] = IATEvent_PAE.__identifier__
    cat = getToolByName(context, 'portal_catalog')
    result = cat(**query)

    for brain in result:
        obj = brain.getObject()
        ann = getAnnotation(obj)

        for field in migrate_fields:
            key = 'Archetypes.storage.AnnotationStorage-%s' % field
            if key in ann:
                val = key in ann and ann[key] or None
                del ann[key] # Delete the annotation entry

                getter = getattr(obj, 'get%s' % field.title()) # Get the getter
                prev_val = getter()

                setter = getattr(obj, 'set%s' % field.title()) # Get the setter
                setter(val) # Set the val on new storage

                logger.info("""'Field migration for obj %s, field %s from
                AnnotationStorage to AttributeStorage done. Previous value: %s,
                new value from AnnotationStorage: %s."""
                % (obj, field, prev_val, val))
Beispiel #6
0
def 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.
    """
    catalog = getToolByName(portal, 'portal_catalog')
    brains = catalog(dict(Type=portal_type))

    fields = [field.getName()
              for field in schema.fields()
              if field.storage.__class__ == AnnotationStorage
              ]
    md_fields = [field.getName()
                 for field in schema.fields()
                 if field.storage.__class__ == MetadataAnnotationStorage
                 ]

    for brain in brains:
        obj = brain.getObject()
        if obj is None:
            continue

        try:
            state = obj._p_changed
        except:
            state = 0

        ann = getAnnotation(obj)
        clean_obj = aq_base(obj)
        _attr2ann(clean_obj, ann, fields)
        _meta2ann(clean_obj, ann, md_fields)

        if state is None:
            obj._p_deactivate()
Beispiel #7
0
 def getSourceType(self, instance):
     """the source path from the instance annotations or empty string"""
     ann = getAnnotation(instance)
     subkey = "%s-source-type" % self.getName()
     return ann.getSubkey(KEY, subkey, default='')
Beispiel #8
0
 def customize(self, instance):
     """Set the customize flag to True"""
     ann = getAnnotation(instance)
     subkey = "%s-customized" % self.getName()
     ann.setSubkey(KEY, True, subkey)
     return None
Beispiel #9
0
 def is_customized(self, instance):
     """Flag whether this field has been customized"""
     ann = getAnnotation(instance)
     subkey = "%s-customized" % self.getName()
     return ann.getSubkey(KEY, subkey, default=self.customized)
Beispiel #10
0
 def setLastUpdate(self, instance, value):
     """Stores the time of the last update in the instance annotations"""
     ann = getAnnotation(instance)
     subkey = "%s-last-update" % self.getName()
     return ann.setSubkey(KEY, value, subkey)
Beispiel #11
0
 def getLastUpdate(self, instance):
     """time of the last update or None"""
     ann = getAnnotation(instance)
     subkey = "%s-last-update" % self.getName()
     return ann.getSubkey(KEY, subkey, default=None)
Beispiel #12
0
 def setTimeout(self, instance, value):
     """Stores the timeout in the instance annotations"""
     ann = getAnnotation(instance)
     subkey = "%s-timeout" % self.getName()
     return ann.setSubkey(KEY, value, subkey)
Beispiel #13
0
 def setSourceType(self, instance, value):
     """Stores source path in the instance annotations"""
     ann = getAnnotation(instance)
     subkey = "%s-source-type" % self.getName()
     return ann.setSubkey(KEY, value, subkey)
Beispiel #14
0
 def getTimeout(self, instance):
     """the timeout from the instance annotations or empty string"""
     ann = getAnnotation(instance)
     subkey = "%s-timeout" % self.getName()
     return ann.getSubkey(KEY, subkey, default=self.timeout)
Beispiel #15
0
 def customize(self, instance):
     """Set the customize flag to True"""
     ann = getAnnotation(instance)
     subkey = "%s-customized" % self.getName()
     ann.setSubkey(KEY, True, subkey)
     return None
Beispiel #16
0
 def is_customized(self, instance):
     """Flag whether this field has been customized"""
     ann = getAnnotation(instance)
     subkey = "%s-customized" % self.getName()
     return ann.getSubkey(KEY, subkey, default=self.customized)
Beispiel #17
0
 def setLastUpdate(self, instance, value):
     """Stores the time of the last update in the instance annotations"""
     ann = getAnnotation(instance)
     subkey = "%s-last-update" % self.getName()
     return ann.setSubkey(KEY, value, subkey)
Beispiel #18
0
 def getLastUpdate(self, instance):
     """time of the last update or None"""
     ann = getAnnotation(instance)
     subkey = "%s-last-update" % self.getName()
     return ann.getSubkey(KEY, subkey, default=None)
Beispiel #19
0
 def setTimeout(self, instance, value):
     """Stores the timeout in the instance annotations"""
     ann = getAnnotation(instance)
     subkey = "%s-timeout" % self.getName()
     return ann.setSubkey(KEY, value, subkey)
Beispiel #20
0
 def setSourceType(self, instance, value):
     """Stores source path in the instance annotations"""
     ann = getAnnotation(instance)
     subkey = "%s-source-type" % self.getName()
     return ann.setSubkey(KEY, value, subkey)
Beispiel #21
0
 def getTimeout(self, instance):
     """the timeout from the instance annotations or empty string"""
     ann = getAnnotation(instance)
     subkey = "%s-timeout" % self.getName()
     return ann.getSubkey(KEY, subkey, default=self.timeout)
Beispiel #22
0
 def unset(self, name, instance, **kwargs):
     ann = getAnnotation(instance)
     try:
         ann.delSubkey(self._key, subkey=name)
     except KeyError:
         pass
Beispiel #23
0
 def getSourceType(self, instance):
     """the source path from the instance annotations or empty string"""
     ann = getAnnotation(instance)
     subkey = "%s-source-type" % self.getName()
     return ann.getSubkey(KEY, subkey, default='')