Skip to content
Browse files

added first experimental release

  • Loading branch information...
1 parent fdd5d82 commit 41c2c3d791a2bc59e1882109c37399036583dfa8 @phgross phgross committed
View
5 IGNORE.txt
@@ -0,0 +1,5 @@
+# created by: svn propset svn:ignore -F ./IGNORE.TXT .
+
+transmogrify.dexterity.egg-info
+build
+dist
View
4 README.txt
@@ -0,0 +1,4 @@
+Introduction
+============
+
+
View
8 docs/HISTORY.txt
@@ -0,0 +1,8 @@
+Changelog
+=========
+
+1.0 - Unreleased
+----------------
+
+* Initial release
+
View
32 setup.py
@@ -0,0 +1,32 @@
+from setuptools import setup, find_packages
+import os
+
+version = '1.0'
+
+setup(name='transmogrify.dexterity',
+ version=version,
+ description="",
+ long_description=open("README.txt").read() + "\n" +
+ open(os.path.join("docs", "HISTORY.txt")).read(),
+ # Get more strings from http://www.python.org/pypi?%3Aaction=list_classifiers
+ classifiers=[
+ "Programming Language :: Python",
+ "Topic :: Software Development :: Libraries :: Python Modules",
+ ],
+ keywords='',
+ author='',
+ author_email='',
+ url='',
+ license='GPL',
+ packages=find_packages(exclude=['ez_setup']),
+ namespace_packages=['transmogrify'],
+ include_package_data=True,
+ zip_safe=False,
+ install_requires=[
+ 'setuptools',
+ # -*- Extra requirements: -*-
+ ],
+ entry_points="""
+ # -*- Entry points: -*-
+ """,
+ )
View
6 transmogrify/__init__.py
@@ -0,0 +1,6 @@
+# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
+try:
+ __import__('pkg_resources').declare_namespace(__name__)
+except ImportError:
+ from pkgutil import extend_path
+ __path__ = extend_path(__path__, __name__)
View
0 transmogrify/dexterity/__init__.py
No changes.
View
10 transmogrify/dexterity/configure.zcml
@@ -0,0 +1,10 @@
+<configure
+ xmlns="http://namespaces.zope.org/zope"
+ i18n_domain="transmogrify.dexterity">
+
+
+<utility
+ component=".dexterityupdater.DexterityUpdateSection"
+ name="transmogrify.dexterity.dexterityupdater"
+ />
+</configure>
View
78 transmogrify/dexterity/dexterityupdater.py
@@ -0,0 +1,78 @@
+from zope import event
+from zope.interface import classProvides, implements
+from collective.transmogrifier.interfaces import ISectionBlueprint, ISection
+from collective.transmogrifier.utils import Matcher, defaultKeys
+
+from Products.Archetypes.interfaces import IBaseObject
+from Products.Archetypes.event import ObjectInitializedEvent
+from Products.Archetypes.event import ObjectEditedEvent
+from plone.dexterity.utils import iterSchemata
+from zope.schema import getFieldsInOrder
+
+class DexterityUpdateSection(object):
+ classProvides(ISectionBlueprint)
+ implements(ISection)
+
+ def __init__(self, transmogrifier, name, options, previous):
+ self.previous = previous
+ self.context = transmogrifier.context
+ self.name = name
+
+ if 'path-key' in options:
+ pathkeys = options['paht-key'].splitlines()
+ else:
+ pathkeys = defaultKeys(options['blueprint'], name, 'path')
+ self.pathkey = Matcher(*pathkeys)
+
+
+ def __iter__(self):
+ for item in self.previous:
+ pathkey = self.pathkey(*item.keys())[0]
+
+ if not pathkey: # not enough info
+ yield item; continue
+
+ path = item[pathkey]
+
+ obj = self.context.unrestrictedTraverse(path.lstrip('/'), None)
+ if obj is None: # path doesn't exist
+ yield item; continue
+
+ #get all fields for this obj
+ fields = {}
+ for schemata in iterSchemata(obj):
+ for name, field in getFieldsInOrder(schemata):
+ fields[name] = field
+ for k,v in item.iteritems():
+ if k.startswith('_'):
+ continue
+ field = fields[k]
+ #TODO implements different types (boolean, int, list, file ect)
+ field.set(field.interface(obj), v.decode('iso-8859-1'))
+
+
+ if IBaseObject.providedBy(obj):
+ changed = False
+ is_new_object = obj.checkCreationFlag()
+ for k,v in item.iteritems():
+ if k.startswith('_'):
+ continue
+ field = obj.getField(k)
+ if field is None:
+ continue
+ field.set(obj, v)
+ changed = True
+ obj.unmarkCreationFlag()
+
+ if is_new_object:
+ event.notify(ObjectInitializedEvent(obj))
+ obj.at_post_create_script()
+ elif changed:
+ event.notify(ObjectEditedEvent(obj))
+ obj.at_post_edit_script()
+
+ yield item
+
+
+
+

0 comments on commit 41c2c3d

Please sign in to comment.
Something went wrong with that request. Please try again.