bluszcz
bluszcz

Reputation: 4128

Object doesn't implement IField

I have following piece of code to patch the Folder:

ATFolderSchema = ATContentTypeSchema.copy() + \
    ConstrainTypesMixinSchema.copy() + NextPreviousAwareSchema.copy()
finalizeATCTSchema(ATFolderSchema, folderish=True, moveDiscussion=False)

field =  StringField("rafal_shortdescription",
            schemata = "default",
            widget = StringWidget(
                label = _(u"label_shortdescription",
                    default=u"Short Description"),
                description = _(u"help_shortdescription",
                    default=u"Used in tabs."),
                ),
            ),

ATFolderSchema.addField(field)   

and last line throws:

 File "/home/rafal/projects/vidensportalen_v2/eggs/Products.Archetypes-1.6.4-py2.6.egg/Products/Archetypes/Schema/__init__.py", line 198, in _validateOnAdd
    raise ValueError, "Object doesn't implement IField: %r" % field
zope.configuration.xmlconfig.ZopeXMLConfigurationError: File "/home/rafal/projects/vidensportalen_v2/parts/instance/etc/site.zcml", line 12.2-12.39
    ZopeXMLConfigurationError: File "/home/rafal/projects/vidensportalen_v2/eggs/Plone-4.0.2-py2.6.egg/Products/CMFPlone/meta.zcml", line 39.4-43.10
    ValueError: Object doesn't implement IField: <Field rafal_shortdescription(string:rw)>

Any idea why?

Upvotes: 2

Views: 194

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1123930

I'd advise you to use archetypes.schemaextender instead of using patches to alter Archetypes content types.

The package includes documentation on how to implement your additional field.

As for your error, you created a tuple with one element, a field:

>>> example = 1,
>>> print example
(1,)

Delete the trailing comma and your code should work as intended.

Upvotes: 6

Related Questions