Permalink
Browse files

merge with master

  • Loading branch information...
2 parents 58b8298 + f283abd commit f12850d7cad85c9f98a778d988ba0432e8cfdb52 @ebrehault ebrehault committed Nov 4, 2013
View
@@ -2,18 +2,31 @@ Changelog
=========
-1.0.1 (unreleased)
-------------------
+1.3 (unreleased)
+----------------
+
+- Add 'logger' and 'loglevel' options so invalid fields are logged when
+ disable-constraints is True [ebrehault]
+
+
+1.2 (2013-08-29)
+----------------
+
+- Only update with a default value if there isn't a value already set
+ on the field. (NB: before a default value would be set, regardless
+ of the current field value).
+ [lentinj]
+
+
+1.1 (2013-07-23)
+----------------
- Don't try to write readonly fields
[djowett]
- Added in a generic CSV -> content pipeline
[lentinj]
-- Add 'logger' and 'loglevel' options so invalid fields are logged when
- disable-constraints is True [ebrehault]
-
1.0 (2011-11-17)
----------------
@@ -7,9 +7,9 @@
from plone.dexterity.utils import iterSchemata
from plone.uuid.interfaces import IMutableUUID
-from z3c.form.interfaces import IValue
+from z3c.form import interfaces
-from zope.component import queryMultiAdapter
+from zope.component import queryMultiAdapter, getMultiAdapter
from zope.event import notify
from zope.interface import classProvides, implements
from zope.lifecycleevent import ObjectModifiedEvent
@@ -19,6 +19,7 @@
_marker = object()
+
class DexterityUpdateSection(object):
classProvides(ISectionBlueprint)
@@ -30,8 +31,12 @@ def __init__(self, transmogrifier, name, options, previous):
self.name = name
self.pathkey = defaultMatcher(options, 'path-key', name, 'path')
self.fileskey = options.get('files-key', '_files').strip()
- self.disable_constraints = Expression(options.get('disable-constraints', 'python: False'),
- transmogrifier, name, options)
+ self.disable_constraints = Expression(
+ options.get('disable-constraints', 'python: False'),
+ transmogrifier,
+ name,
+ options,
+ )
# create logger
if options.get('logger'):
@@ -73,38 +78,54 @@ def __iter__(self):
files = item.setdefault(self.fileskey, {})
- #get all fields for this obj
+ # For all fields in the schema, update in roughly the same way
+ # z3c.form.widget.py would
for schemata in iterSchemata(obj):
for name, field in getFieldsInOrder(schemata):
if field.readonly:
continue
#setting value from the blueprint cue
value = item.get(name, _marker)
- if value is _marker:
- # No value is given from the pipeline,
- # so we try to set the default value
- # otherwise we set the missing value
- default = queryMultiAdapter((
- obj,
- obj.REQUEST, # request
- None, # form
- field,
- None, # Widget
- ), IValue, name='default')
- if default is not None:
- default = default.get()
- if default is None:
- default = getattr(field, 'default', None)
- if default is None:
- try:
- default = field.missing_value
- except AttributeError:
- pass
- value = default
- else:
+ if value is not _marker:
+ # Value was given in pipeline, so set it
deserializer = IDeserializer(field)
- value = deserializer(value, files, item, self.disable_constraints, logger=self.log)
- field.set(field.interface(obj), value)
+ value = deserializer(
+ value,
+ files,
+ item,
+ self.disable_constraints,
+ logger=self.log,
+ )
+ field.set(field.interface(obj), value)
+ continue
+
+ # Get the widget's current value, if it has one then leave
+ # it alone
+ value = getMultiAdapter(
+ (obj, field),
+ interfaces.IDataManager).query()
+ if not(value is field.missing_value
+ or value is interfaces.NO_VALUE):
+ continue
+
+ # Finally, set a default value if nothing is set so far
+ default = queryMultiAdapter((
+ obj,
+ obj.REQUEST, # request
+ None, # form
+ field,
+ None, # Widget
+ ), interfaces.IValue, name='default')
+ if default is not None:
+ default = default.get()
+ if default is None:
+ default = getattr(field, 'default', None)
+ if default is None:
+ try:
+ default = field.missing_value
+ except AttributeError:
+ pass
+ field.set(field.interface(obj), default)
notify(ObjectModifiedEvent(obj))
yield item
@@ -34,8 +34,6 @@ def __iter__(self):
yield item
continue
- if None in item:
- import pdb; pdb.set_trace()
data = dict((key, value) for key, value in item.iteritems() if not key.startswith('_'))
if not data:
yield item
@@ -103,31 +103,42 @@ class SchemaSource(SampleSource):
classProvides(ISectionBlueprint)
implements(ISection)
- def __init__(self, *args, **kw):
- super(SchemaSource, self).__init__(*args, **kw)
- self.sample = (
- dict(_path='/spam',
- foo='one value',
- _type='TransmogrifyDexterityFTI',
- title='Spam',
- description='Lorem Ipsum bla bla!',
- test_file={
- 'data': zptlogo,
- 'filename': 'zptlogo.gif'},
- test_date='2010-10-12',
- fieldnotchanged='nochange',
- ),
- dict(_path='/two',
- foo='Bla',
- _type='TransmogrifyDexterityFTI',
- title='My Second Object',
- #description=None, # None is not valid for this field.
- test_file=zptlogo,
- _filename="testlogo.gif",
- test_date=date(2010, 01, 01, ),
- fieldnotchanged='nochange',
- ),
- )
+ def __init__(self, transmogrifier, name, options, previous):
+ super(SchemaSource, self).__init__(transmogrifier, name, options, previous)
+ sourcecontent = options.get('source-content', 'full')
+ if sourcecontent == 'full':
+ self.sample = (
+ dict(_path='/spam',
+ foo='one value',
+ _type='TransmogrifyDexterityFTI',
+ title='Spam',
+ description='Lorem Ipsum bla bla!',
+ test_file={
+ 'data': zptlogo,
+ 'filename': 'zptlogo.gif'},
+ test_date='2010-10-12',
+ fieldnotchanged='nochange',
+ ),
+ dict(_path='/two',
+ foo='Bla',
+ _type='TransmogrifyDexterityFTI',
+ title='My Second Object',
+ #description=None, # None is not valid for this field.
+ test_file=zptlogo,
+ _filename="testlogo.gif",
+ test_date=date(2010, 01, 01, ),
+ fieldnotchanged='nochange',
+ ),
+ )
+ elif sourcecontent == 'onlytitle':
+ self.sample = (
+ dict(_path='/spam',
+ _type='TransmogrifyDexterityFTI',
+ title='Spammety spam'),
+ dict(_path='/two',
+ _type='TransmogrifyDexterityFTI',
+ title='My Awesome Second Object'),
+ )
provideUtility(SchemaSource,
name=u'transmogrify.dexterity.testsource')
@@ -15,26 +15,7 @@ Do some imports
>>> from plone.app.dexterity.behaviors.metadata import IBasic
>>> from transmogrify.dexterity.testing import zptlogo
-Test configuration for transmogrifier (registered by tests.zcml):
-
- >>> dexterityconfig = """
- ... [transmogrifier]
- ... pipeline =
- ... testsource
- ... testcreator
- ... schemaupdater
- ...
- ... [testsource]
- ... blueprint = transmogrify.dexterity.testsource
- ...
- ... [testcreator]
- ... blueprint = collective.transmogrifier.sections.constructor
- ...
- ... [schemaupdater]
- ... blueprint = transmogrify.dexterity.schemaupdater
- ... """
-
-Let transmorifier to his work!
+Run transmogrifier pipeline with default settings (pipeline in tests.cfg)
>>> transmogrifier = Transmogrifier(portal)
>>> output = transmogrifier(u'transmogrify.dexterity.testconfiguration')
@@ -84,4 +65,16 @@ DateFields:
>>> two.test_date
datetime.date(2010, 1, 1)
+Won't touch already existing values
+ >>> transmogrifier = Transmogrifier(portal)
+ >>> output = transmogrifier(u'transmogrify.dexterity.testconfiguration')
+ >>> transmogrifier = Transmogrifier(portal)
+ >>> output = transmogrifier(u'transmogrify.dexterity.testconfiguration', definitions={
+ ... 'source-content': 'onlytitle',
+ ... })
+ >>> spam = portal.get('spam')
+ >>> IBasic(spam).title
+ u'Spammety spam'
+ >>> spam.foo
+ u'one value'
@@ -4,8 +4,12 @@ pipeline =
testcreator
schemaupdater
+[definitions]
+source-content = full
+
[testsource]
blueprint = transmogrify.dexterity.testsource
+source-content = ${definitions:source-content}
[testcreator]
blueprint = collective.transmogrifier.sections.constructor
@@ -1 +1 @@
-1.0.1dev
+1.3.dev0

0 comments on commit f12850d

Please sign in to comment.