コード例 #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)
コード例 #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))
コード例 #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
コード例 #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)
コード例 #5
0
ファイル: event.py プロジェクト: senner/plone.app.event
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))
コード例 #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()
コード例 #7
0
ファイル: remotetext.py プロジェクト: a25kk/stv2
 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='')
コード例 #8
0
ファイル: remotetext.py プロジェクト: a25kk/stv2
 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
コード例 #9
0
ファイル: remotetext.py プロジェクト: a25kk/stv2
 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)
コード例 #10
0
ファイル: remotetext.py プロジェクト: a25kk/stv2
 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)
コード例 #11
0
ファイル: remotetext.py プロジェクト: a25kk/stv2
 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)
コード例 #12
0
ファイル: remotetext.py プロジェクト: a25kk/stv2
 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)
コード例 #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)
コード例 #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)
コード例 #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
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #20
0
ファイル: remotetext.py プロジェクト: a25kk/stv2
 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)
コード例 #21
0
ファイル: remotetext.py プロジェクト: a25kk/stv2
 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)
コード例 #22
0
 def unset(self, name, instance, **kwargs):
     ann = getAnnotation(instance)
     try:
         ann.delSubkey(self._key, subkey=name)
     except KeyError:
         pass
コード例 #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='')