Can file-uploads be accessed in RestrictedPython from PloneFormGen scripts? - plone

Currently I'm trying to set up a Form to create a News-Item from. The Script works fine so far. Problems arise with the File-Field: As soon as I try to access the file via request.form['pub-core-cover'] I get an "Module AccessControl.ZopeGuards, line 67, in guarded_getitem".
I was advised to use a HelperView to bypass RestrictedPython which seems to be the issue here. This is pretty difficult for me due to the fact I have not developed an add-on product so far. Somehow I'm wondering as well if there is another possibility to make the File-Field feature in PFG work again within RestrictedPython. Otherwise the file-field becomes somehow obsolet.
CustomScript-Adapter (don't mind the german comments):
form = request.form
# ID des Zielverzeichnisses ist publikationen
target = context.publikationen
# Einmalige ID für das neu zu erstellende Objekt erstellen anhand des Datums + Uhrzeit
from DateTime import DateTime
uid = str(DateTime().millis())
# Titel und ID festlegen und damit News-Objekt erzeugen (Titel + Beschreibung)
title = form['author-prename'] + " " + form['author-surname']
desc = form['pub-core-title'] + " " + form['pub-core-subtitle']
target.invokeFactory("News Item", id = uid, title = title.upper(), description = desc, image = form['pub-core-cover'])
# Objekt aufspüren und ContentType festlegen
obj = target[uid]
obj.setContentType('text/html')
# Inhalt des News-Items setzen
obj.setText("<p>"+ form['pub-core-description'] +"<br /><br />Veröffentlicht: "+ form['pub-tech-year'] +"<br />ISBN: "+ form['pub-tech-isbn'] +"<br />Preis: "+ form['pub-tech-price'] +"<br />" + form['pub-tech-pages'] + " Seiten, " + form['pub-tech-binding'] + "</p>")
# Objekt veröffentlichen ohne den Initial-State im Workflow zu verändern
obj.portal_workflow.doActionFor(obj, 'publish', comment='Dieser Inhalt wurde über den PythonScriptAdapter von PloneFormGen automatisch publiziert.')
# Content reindexieren, um das neue Objekt anzuzeigen
obj.reindexObject()
Traceback:
Traceback (innermost last):
Module ZPublisher.Publish, line 127, in publish
Module ZPublisher.mapply, line 77, in mapply
Module ZPublisher.Publish, line 47, in call_object
Module Products.CMFFormController.FSControllerPageTemplate, line 91, in __call__
Module Products.CMFFormController.BaseControllerPageTemplate, line 26, in _call
Module Products.CMFFormController.FormController, line 384, in validate
Module ZPublisher.mapply, line 77, in mapply
Module ZPublisher.Publish, line 47, in call_object
Module Products.CMFFormController.FSControllerValidator, line 58, in __call__
Module Products.CMFFormController.Script, line 145, in __call__
Module Products.CMFCore.FSPythonScript, line 130, in __call__
Module Shared.DC.Scripts.Bindings, line 324, in __call__
Module Shared.DC.Scripts.Bindings, line 361, in _bindAndExec
Module Products.PythonScripts.PythonScript, line 344, in _exec
Module script, line 20, in fgvalidate_base
- <FSControllerValidator at /breyer_verlag/fgvalidate_base used for /breyer_verlag/publikationen/publikation-hinzufuegen>
- Line 20
Module Products.PloneFormGen.content.form, line 566, in fgvalidate
Module Products.PloneFormGen.content.form, line 607, in fgProcessActionAdapters
Module Products.PloneFormGen.content.customScriptAdapter, line 187, in onSuccess
Module Products.PloneFormGen.content.customScriptAdapter, line 218, in executeCustomScript
Module Shared.DC.Scripts.Bindings, line 324, in __call__
Module Shared.DC.Scripts.Bindings, line 361, in _bindAndExec
Module Products.PythonScripts.PythonScript, line 344, in _exec
Module script, line 27, in create-publication
- <PythonScript at /breyer_verlag/publikationen/publikation-hinzufuegen/create-publication/create-publication>
- Line 27
Module AccessControl.ZopeGuards, line 67, in guarded_getitem
KeyError: 'pub-core-cover'
I had no difficulties using an pretty similar code in Plone3. I would appreciate any help that gets me out of my misery.
Edit:
By the way:
Plone 4.05
PFG 1.72a

As vangheem stated it is not a RestrictedPython-Problem put has to do how PloneFormGen handles the data field. It is important to add _file to the variable name.

Related

non required SelectFieldWidget

I have a dexterity content type and I'd like to have a Select-Field which is not required and which values came from a vocabulary.
This is the vocabulary:
#grok.provider(IContextSourceBinder)
def voc_test(context):
values = range(10, 21)
terms = map(lambda x: SimpleTerm(value=str(x),
title=str(x)), values)
return SimpleVocabulary(terms)
And this the definition of the field:
from plone.directives import dexterity, form
from plone.namedfile.field import NamedImage
from zope import schema
class IMyType(form.Schema):
...
form.widget('test', SelectFieldWidget)
test = schema.List(
title=_(u"Test"),
value_type=schema.Choice(source=vocabularies.voc_test),
description=_(u"desc_test"),
required=False,
)
What I get is a select field with my values from the vocabulary and the first value is 'No Value'. That is fine. But when I hit save and have 'No Value' selected a error message is shown:
Traceback (innermost last):
Module ZPublisher.Publish, line 138, in publish
Module ZPublisher.mapply, line 77, in mapply
Module ZPublisher.Publish, line 48, in call_object
Module plone.z3cform.layout, line 66, in __call__
Module plone.z3cform.layout, line 50, in update
Module plone.dexterity.browser.edit, line 52, in update
Module plone.z3cform.fieldsets.extensible, line 59, in update
Module plone.z3cform.patch, line 30, in GroupForm_update
Module z3c.form.group, line 145, in update
Module plone.app.z3cform.csrf, line 21, in execute
Module z3c.form.action, line 98, in execute
Module z3c.form.button, line 315, in __call__
Module z3c.form.button, line 170, in __call__
Module plone.dexterity.browser.edit, line 23, in handleApply
Module z3c.form.group, line 98, in extractData
Module z3c.form.form, line 147, in extractData
Module z3c.form.field, line 303, in extract
Module z3c.form.converter, line 316, in toFieldValue
Module z3c.form.term, line 41, in getValue
Module z3c.form.term, line 38, in getTermByToken
Module zope.schema.vocabulary, line 133, in getTermByToken
LookupError: --NOVALUE--
If I change:
required=False,
to
required=True
saving works.
Hopefully someone can help. Thanks.
Set a default that is within your vocabulary and make the field required so that "--NOVALUE--" is not in the options.
If, for some reason, you want to use "-- NOVALUE --" for that default, then add it to the vocabulary. If the field is set required, it will not be duplicated.

tile edit view wrong context for vocabularies

I have a persistent tile that has a choice field:
subjects = schema.List(
title=_(u"Subjects"),
value_type=schema.Choice(
vocabulary='my.subjects'
),
)
but this is failing on edit view rendering like this:
2013-05-22 18:37:56 ERROR Zope.SiteErrorLog 1369240676.330.546121806344 http://localhost:8082/plumi/##edit-tile/tagcloud.tile/home-cloud
Traceback (innermost last):
Module ZPublisher.Publish, line 126, in publish
Module ZPublisher.mapply, line 77, in mapply
Module ZPublisher.Publish, line 46, in call_object
Module plone.z3cform.layout, line 70, in __call__
Module plone.z3cform.layout, line 54, in update
Module plone.app.tiles.browser.edit, line 48, in update
Module plone.app.tiles.browser.base, line 55, in update
Module plone.z3cform.fieldsets.extensible, line 59, in update
Module plone.z3cform.patch, line 30, in GroupForm_update
Module z3c.form.group, line 125, in update
Module plone.app.tiles.browser.base, line 71, in updateWidgets
Module z3c.form.field, line 275, in update
Module z3c.form.browser.orderedselect, line 50, in update
Module z3c.form.browser.widget, line 70, in update
Module z3c.form.widget, line 199, in update
Module z3c.form.widget, line 193, in updateTerms
Module zope.component._api, line 107, in getMultiAdapter
Module zope.component._api, line 120, in queryMultiAdapter
Module zope.component.registry, line 238, in queryMultiAdapter
Module zope.interface.adapter, line 532, in queryMultiAdapter
Module z3c.form.term, line 174, in CollectionTerms
Module zope.schema._field, line 352, in bind
Module Zope2.App.schema, line 33, in get
Module my.vocabularies, line 22, in __call__
Module Products.CMFCore.utils, line 10, in check_getToolByName
Module Products.CMFCore.utils, line 120, in getToolByName
AttributeError: portal_catalog
This happen because the context passed to the vocabulary call is the data dictionary of the tile. It happens also when using SearchableTextSourceBinder in another field:
source=SearchableTextSourceBinder(
{'is_folderish': True},
default_query='path:'
)
that makes plone.app.vocabularies.catalog fail:
Module plone.app.vocabularies.catalog, line 237, in __call__
Module plone.app.vocabularies.catalog, line 144, in __init__
Module Products.CMFCore.utils, line 10, in check_getToolByName
Module Products.CMFCore.utils, line 120, in getToolByName
AttributeError: portal_catalog
I don't know, if it's by design, but when a persistent tile is edited, context sensitive vocabulary will get its context (persistent tile data dictionary) without any acquisition wrapping. Therefore all lookups which rely on acquisition will fail.
You could try fixing your vocabulary to use portal root as its context for getToolByName-looksup using either plone.api.portal.get() or zope.component.hooks.getSite().
If you really need the current context, an ugly way would be to get zope.globalrequest.getRequest().get("PUBLISHED") which should be the current publishable context found by ZPublisher. It's usually a view, but you can get your context object from its acquisition chain. Of course, you should be very defensive with that approach.

'Not Found' Site error while rendering 404 page in Plone 4.1.4

The Problem: Whenever a user navigates to an error page, instead of displaying 'Page not found' message in plone, this zope error message is displayed instead:
NotFound(' <h2>Site Error</h2>\n <p>An error was encountered while publishing this resource.\n </p>\n <p><strong>Resource not found</strong></p>\n\n Sorry, the requested resource does not exist.<p>Check the URL and try again.</p><p><b>Resource:</b> http://www.caseware.com/ddddd</p>\n <hr noshade="noshade"/>\n\n <p>Troubleshooting Suggestions</p>\n\n <ul>\n <li>The URL may be incorrect.</li>\n <li>The parameters passed to this resource may be incorrect.</li>\n <li>A resource that this resource relies on may be\n encountering an error.</li>\n </ul>\n\n <p>For more detailed information about the error, please\n refer to the error log.\n </p>\n\n <p>If the error persists please contact the site maintainer.\n Thank you for your patience.\n </p>',) (Also, the following error occurred while attempting to render the standard error message, please see the event log for full details: )
At the same time, log file for the instance in which error occurs displays the following stack trace:
2012-10-03T13:12:06 ERROR root Exception while rendering an error message
Traceback (most recent call last):
File "/home/alex/projects/production/plone4_dev/eggs/Zope2-2.13.12-py2.6.egg/OFS/SimpleItem.py", line 242, in raise_standardErrorMessage
v = s(**kwargs)
File "/home/alex/projects/production/plone4_dev/eggs/Products.CMFCore-2.2.5-py2.6.egg/Products/CMFCore/FSPythonScript.py", line 130, in __call__
return Script.__call__(self, *args, **kw)
File "/home/alex/projects/production/plone4_dev/eggs/Zope2-2.13.12-py2.6.egg/Shared/DC/Scripts/Bindings.py", line 322, in __call__
return self._bindAndExec(args, kw, None)
File "/home/alex/projects/production/plone4_dev/eggs/Zope2-2.13.12-py2.6.egg/Shared/DC/Scripts/Bindings.py", line 359, in _bindAndExec
return self._exec(bound_data, args, kw)
File "/home/alex/projects/production/plone4_dev/eggs/Products.PythonScripts-2.13.0-py2.6.egg/Products/PythonScripts/PythonScript.py", line 344, in _exec
result = f(*args, **kw)
File "Script (Python)", line 34, in standard_error_message
File "/home/alex/projects/production/plone4_dev/eggs/Zope2-2.13.12-py2.6.egg/Shared/DC/Scripts/Bindings.py", line 322, in __call__
return self._bindAndExec(args, kw, None)
File "/home/alex/projects/production/plone4_dev/eggs/Zope2-2.13.12-py2.6.egg/Shared/DC/Scripts/Bindings.py", line 359, in _bindAndExec
return self._exec(bound_data, args, kw)
File "/home/alex/projects/production/plone4_dev/eggs/Products.CMFCore-2.2.5-py2.6.egg/Products/CMFCore/FSPageTemplate.py", line 240, in _exec
result = self.pt_render(extra_context=bound_names)
File "/home/alex/projects/production/plone4_dev/eggs/Products.CMFCore-2.2.5-py2.6.egg/Products/CMFCore/FSPageTemplate.py", line 180, in pt_render
self, source, extra_context
File "/home/alex/projects/production/plone4_dev/eggs/Zope2-2.13.12-py2.6.egg/Products/PageTemplates/PageTemplate.py", line 79, in pt_render
showtal=showtal)
File "/home/alex/projects/production/plone4_dev/eggs/zope.pagetemplate-3.5.2-py2.6.egg/zope/pagetemplate/pagetemplate.py", line 113, in pt_render
strictinsert=0, sourceAnnotations=sourceAnnotations)()
File "/home/alex/projects/production/plone4_dev/eggs/zope.tal-3.5.2-py2.6.egg/zope/tal/talinterpreter.py", line 271, in __call__
self.interpret(self.program)
File "/home/alex/projects/production/plone4_dev/eggs/zope.tal-3.5.2-py2.6.egg/zope/tal/talinterpreter.py", line 343, in interpret
handlers[opcode](self, args)
File "/home/alex/projects/production/plone4_dev/eggs/zope.tal-3.5.2-py2.6.egg/zope/tal/talinterpreter.py", line 888, in do_useMacro
self.interpret(macro)
File "/home/alex/projects/production/plone4_dev/eggs/zope.tal-3.5.2-py2.6.egg/zope/tal/talinterpreter.py", line 343, in interpret
handlers[opcode](self, args)
File "/home/alex/projects/production/plone4_dev/eggs/zope.tal-3.5.2-py2.6.egg/zope/tal/talinterpreter.py", line 533, in do_optTag_tal
self.do_optTag(stuff)
File "/home/alex/projects/production/plone4_dev/eggs/zope.tal-3.5.2-py2.6.egg/zope/tal/talinterpreter.py", line 518, in do_optTag
return self.no_tag(start, program)
File "/home/alex/projects/production/plone4_dev/eggs/zope.tal-3.5.2-py2.6.egg/zope/tal/talinterpreter.py", line 513, in no_tag
self.interpret(program)
File "/home/alex/projects/production/plone4_dev/eggs/zope.tal-3.5.2-py2.6.egg/zope/tal/talinterpreter.py", line 343, in interpret
handlers[opcode](self, args)
File "/home/alex/projects/production/plone4_dev/eggs/zope.tal-3.5.2-py2.6.egg/zope/tal/talinterpreter.py", line 531, in do_optTag_tal
self.no_tag(stuff[-2], stuff[-1])
File "/home/alex/projects/production/plone4_dev/eggs/zope.tal-3.5.2-py2.6.egg/zope/tal/talinterpreter.py", line 513, in no_tag
self.interpret(program)
File "/home/alex/projects/production/plone4_dev/eggs/zope.tal-3.5.2-py2.6.egg/zope/tal/talinterpreter.py", line 343, in interpret
handlers[opcode](self, args)
File "/home/alex/projects/production/plone4_dev/eggs/zope.tal-3.5.2-py2.6.egg/zope/tal/talinterpreter.py", line 742, in do_insertStructure_tal
structure = self.engine.evaluateStructure(expr)
File "/home/alex/projects/production/plone4_dev/eggs/Zope2-2.13.12-py2.6.egg/Products/PageTemplates/Expressions.py", line 218, in evaluateStructure
text = super(ZopeContext, self).evaluateStructure(expr)
File "/home/alex/projects/production/plone4_dev/eggs/zope.tales-3.5.1-py2.6.egg/zope/tales/tales.py", line 696, in evaluate
return expression(self)
File "/home/alex/projects/production/plone4_dev/eggs/zope.contentprovider-3.7.2-py2.6.egg/zope/contentprovider/tales.py", line 80, in __call__
return provider.render()
File "/home/alex/projects/production/plone4_dev/eggs/plone.app.viewletmanager-2.0.2-py2.6.egg/plone/app/viewletmanager/manager.py", line 85, in render
return u'\n'.join([viewlet.render() for viewlet in self.viewlets])
File "/home/alex/projects/production/plone4_dev/eggs/zope.browserpage-3.12.2-py2.6.egg/zope/browserpage/simpleviewclass.py", line 44, in __call__
return self.index(*args, **kw)
File "/home/alex/projects/production/plone4_dev/eggs/Zope2-2.13.12-py2.6.egg/Products/Five/browser/pagetemplatefile.py", line 125, in __call__
return self.im_func(im_self, *args, **kw)
File "/home/alex/projects/production/plone4_dev/eggs/Zope2-2.13.12-py2.6.egg/Products/Five/browser/pagetemplatefile.py", line 59, in __call__
sourceAnnotations=getattr(debug_flags, 'sourceAnnotations', 0),
File "/home/alex/projects/production/plone4_dev/eggs/zope.pagetemplate-3.5.2-py2.6.egg/zope/pagetemplate/pagetemplate.py", line 113, in pt_render
strictinsert=0, sourceAnnotations=sourceAnnotations)()
File "/home/alex/projects/production/plone4_dev/eggs/zope.tal-3.5.2-py2.6.egg/zope/tal/talinterpreter.py", line 271, in __call__
self.interpret(self.program)
File "/home/alex/projects/production/plone4_dev/eggs/zope.tal-3.5.2-py2.6.egg/zope/tal/talinterpreter.py", line 343, in interpret
handlers[opcode](self, args)
File "/home/alex/projects/production/plone4_dev/eggs/zope.tal-3.5.2-py2.6.egg/zope/tal/talinterpreter.py", line 533, in do_optTag_tal
self.do_optTag(stuff)
File "/home/alex/projects/production/plone4_dev/eggs/zope.tal-3.5.2-py2.6.egg/zope/tal/talinterpreter.py", line 518, in do_optTag
return self.no_tag(start, program)
File "/home/alex/projects/production/plone4_dev/eggs/zope.tal-3.5.2-py2.6.egg/zope/tal/talinterpreter.py", line 513, in no_tag
self.interpret(program)
File "/home/alex/projects/production/plone4_dev/eggs/zope.tal-3.5.2-py2.6.egg/zope/tal/talinterpreter.py", line 343, in interpret
handlers[opcode](self, args)
File "/home/alex/projects/production/plone4_dev/eggs/zope.tal-3.5.2-py2.6.egg/zope/tal/talinterpreter.py", line 531, in do_optTag_tal
self.no_tag(stuff[-2], stuff[-1])
File "/home/alex/projects/production/plone4_dev/eggs/zope.tal-3.5.2-py2.6.egg/zope/tal/talinterpreter.py", line 513, in no_tag
self.interpret(program)
File "/home/alex/projects/production/plone4_dev/eggs/zope.tal-3.5.2-py2.6.egg/zope/tal/talinterpreter.py", line 343, in interpret
handlers[opcode](self, args)
File "/home/alex/projects/production/plone4_dev/eggs/zope.tal-3.5.2-py2.6.egg/zope/tal/talinterpreter.py", line 742, in do_insertStructure_tal
structure = self.engine.evaluateStructure(expr)
File "/home/alex/projects/production/plone4_dev/eggs/Zope2-2.13.12-py2.6.egg/Products/PageTemplates/Expressions.py", line 218, in evaluateStructure
text = super(ZopeContext, self).evaluateStructure(expr)
File "/home/alex/projects/production/plone4_dev/eggs/zope.tales-3.5.1-py2.6.egg/zope/tales/tales.py", line 696, in evaluate
return expression(self)
File "/home/alex/projects/production/plone4_dev/eggs/zope.contentprovider-3.7.2-py2.6.egg/zope/contentprovider/tales.py", line 80, in __call__
return provider.render()
File "/home/alex/projects/production/plone4_dev/eggs/zope.viewlet-3.7.2-py2.6.egg/zope/viewlet/manager.py", line 124, in render
return self.template(viewlets=self.viewlets)
File "/home/alex/projects/production/plone4_dev/eggs/Zope2-2.13.12-py2.6.egg/Products/Five/browser/pagetemplatefile.py", line 125, in __call__
return self.im_func(im_self, *args, **kw)
File "/home/alex/projects/production/plone4_dev/eggs/Zope2-2.13.12-py2.6.egg/Products/Five/browser/pagetemplatefile.py", line 59, in __call__
sourceAnnotations=getattr(debug_flags, 'sourceAnnotations', 0),
File "/home/alex/projects/production/plone4_dev/eggs/zope.pagetemplate-3.5.2-py2.6.egg/zope/pagetemplate/pagetemplate.py", line 113, in pt_render
strictinsert=0, sourceAnnotations=sourceAnnotations)()
File "/home/alex/projects/production/plone4_dev/eggs/zope.tal-3.5.2-py2.6.egg/zope/tal/talinterpreter.py", line 271, in __call__
self.interpret(self.program)
File "/home/alex/projects/production/plone4_dev/eggs/zope.tal-3.5.2-py2.6.egg/zope/tal/talinterpreter.py", line 343, in interpret
handlers[opcode](self, args)
File "/home/alex/projects/production/plone4_dev/eggs/zope.tal-3.5.2-py2.6.egg/zope/tal/talinterpreter.py", line 819, in do_loop_tal
iterator = self.engine.setRepeat(name, expr)
File "/home/alex/projects/production/plone4_dev/eggs/zope.tales-3.5.1-py2.6.egg/zope/tales/tales.py", line 682, in setRepeat
expr = self.evaluate(expr)
File "/home/alex/projects/production/plone4_dev/eggs/zope.tales-3.5.1-py2.6.egg/zope/tales/tales.py", line 696, in evaluate
return expression(self)
File "/home/alex/projects/production/plone4_dev/eggs/zope.tales-3.5.1-py2.6.egg/zope/tales/expressions.py", line 217, in __call__
return self._eval(econtext)
File "/home/alex/projects/production/plone4_dev/eggs/Zope2-2.13.12-py2.6.egg/Products/PageTemplates/Expressions.py", line 155, in _eval
return render(ob, econtext.vars)
File "/home/alex/projects/production/plone4_dev/eggs/Zope2-2.13.12-py2.6.egg/Products/PageTemplates/Expressions.py", line 117, in render
ob = ob()
File "/home/alex/projects/production/plone4_dev/eggs/Products.ResourceRegistries-2.0.6-py2.6.egg/Products/ResourceRegistries/browser/scripts.py", line 27, in scripts
content = registry.getInlineResource(script.getId(), context)
File "/home/alex/projects/production/plone4_dev/eggs/Products.ResourceRegistries-2.0.6-py2.6.egg/Products/ResourceRegistries/tools/BaseRegistry.py", line 856, in getInlineResource
output = self.getResourceContent(item, context)
File "/home/alex/projects/production/plone4_dev/eggs/Products.ResourceRegistries-2.0.6-py2.6.egg/Products/ResourceRegistries/tools/JSRegistry.py", line 246, in getResourceContent
output = BaseRegistryTool.getResourceContent(self, item, context, original)
File "/home/alex/projects/production/plone4_dev/eggs/Products.ResourceRegistries-2.0.6-py2.6.egg/Products/ResourceRegistries/tools/BaseRegistry.py", line 593, in getResourceContent
self._restoreCachingHeaders(original_headers, if_modified)
File "/home/alex/projects/production/plone4_dev/eggs/Products.ResourceRegistries-2.0.6-py2.6.egg/Products/ResourceRegistries/tools/BaseRegistry.py", line 661, in _restoreCachingHeaders
assert int(self.REQUEST.RESPONSE.getStatus()) / 100 == 2
AssertionError
I've been trying to figure this out for the last few days, but the main problem is -- this error occurs only in production configuration, and I can't reproduce it in development environment.
The problem has started when the site was upgraded with a new design using diazo, it also has been moved from Centos 5.6 to Centos 6, but I don't think it matters that much. Otherwise bulidout.cfg remained unchanged.
When I'm trying to reproduce the error on local development machine, I could only trigger it when instance is running with debug-mode = off, and the process has to be running in the background, whenever it runs in the foreground, error doesn't get triggered and correct 404 error message is displayed; basically everything runs fine in development environment, but as soon as code is moved in production, 404 page gets broken.
Environment info:
Plone 4.1.4
Zope 2.13.12
Python 2.6.7 (r267:88850, Dec 13 2011, 17:15:07) [GCC 4.6.2]
The assert line is a long-standing problem in Plone, one that I haven't followed all the intricacies on. There currently is one open bug involving the assert still:
Products.ResourceRegistries: "inline" resouces fail with "redirect"
I suspect that you have a JavaScript resource that is rendered inline, including in the error page. It seems the resource registry assert is not taking into account a inline response on a non-200 page (such a as a 404 Not Found response).
The above issue has a patch attached. If the patch works for you, I suggest you comment on the ticket and state it worked for you. Do confirm that you have an inline JavaScript resource in your resource registry though.

Using import with a level specification isn't supported by AccessControl: _warnings

I'm having problem with FS controller page template. I had this Plone2 base product which i have eggified while doing Plone 4.2 migration. I have pasted traceback below.
Traceback (innermost last):
Module ZPublisher.Publish, line 126, in publish
Module ZPublisher.mapply, line 77, in mapply
Module ZPublisher.Publish, line 46, in call_object
Module Products.CMFFormController.FSControllerPageTemplate, line 91, in __call__
Module Products.CMFFormController.BaseControllerPageTemplate, line 26, in _call
Module Products.CMFFormController.FormController, line 384, in validate
Module ZPublisher.mapply, line 77, in mapply
Module ZPublisher.Publish, line 46, in call_object
Module Products.CMFFormController.FSControllerValidator, line 58, in __call__
Module Products.CMFFormController.Script, line 145, in __call__
Module Products.CMFCore.FSPythonScript, line 130, in __call__
Module Shared.DC.Scripts.Bindings, line 322, in __call__
Module Shared.DC.Scripts.Bindings, line 359, in _bindAndExec
Module Products.PythonScripts.PythonScript, line 344, in _exec
Module script, line 32, in exams_list
- <FSControllerValidator at /dev/exam/online/booking/validators/exams_list>
- Line 32
Module AccessControl.ZopeGuards, line 299, in guarded_import
Unauthorized: Using import with a level specification isn't supported by AccessControl: _warnings
line 32 on exams_list validators is wrap with astric
if event and not state.getErrors():
try:
context.script.validateEvent()
except ValueError,exc:
state.setError('SIMSError',str(exc))
**except 'dryrun':**
state.setStatus('dryrun')
Any help or pointer always helpful.
Support for string exceptions was removed from Python 2.6; you'll need to use a proper exception class for 'dryrun' instead.
You'll need to mark that exception as importable by restricted code before you can then import it into your Controller Script.
Here is an example definition for such an exception:
from AccessControl.SecurityInfo import ModuleSecurityInfo
security = ModuleSecurityInfo('My.Product.exceptions')
security.declarePublic('DryRunException')
class DryRunException(Exception):
'''The process was not committed, this was only a dry run'''
With the ModuleSecurityInfo information in place you can now import this exception into your script:
from My.Product.exceptions import DryRunException
and catch that instead in your except block; the code that throws this exception will need to be updated too, of course.

ReferenceField causes AttributeError: 'function' object has no attribute '__of__' in a custom content type

I have created a custom content type that has a ReferenceField. When I set allowed_types to a default content type, such as Document or Folder, I do not get any problems upon saving or reindexing. However, when I set allowed_types to another custom content type, I get a very strange error. It appears I can set the UID in the ReferenceField fine and base_view does not break, but I cannot save or reindex the object.
Using:
Plone 4.0.1
Zope 2.12.11
Python 2.6.5 (r265:79063, Nov 21 2010, 11:58:21) [GCC 4.2.1 (Apple Inc. build 5664)]
Any ideas?
atapi.ReferenceField(
'issue_source',
storage=atapi.AnnotationStorage(),
widget=atapi.ReferenceWidget(
label=_(u"Issue Source"),
description=_(u"Please select the source document to which this issue corresponds."),
),
required=True,
relationship='issue_issue_source',
allowed_types=('Source Document'), # specify portal type names here ('Example Type',)
multiValued=False, #One to One relationship
),
In ipzope:
>>> issue
<Issue at /Plone/Members/test_user2/test-issue>
>>> issue.isReferenceable
1
>>> source_document
<SourceDocument at /Plone/test-folder/test-doc>
>>> issue.setIssue_source(source_document.UID())
>>> issue.getIssue_source()
<SourceDocument at /Plone/test-folder/test-doc>
>>> source_document
<SourceDocument at /Plone/test-folder/test-doc>
>>> issue.reindexObject()
> /Applications/Plone/plone-site/eggs/Products.CMFDynamicViewFTI-4.0-py2.6.egg/Products/CMFDynamicViewFTI/browserdefault.py(77)__call__()
76 context = aq_inner(self)
---> 77 template = template.__of__(context)
78 return template(context, context.REQUEST)
ipdb> quit
------------------------------------------------------------
Traceback (most recent call last):
File "<ipython console>", line 1, in <module>
File "/Applications/Plone/plone-site/eggs/Products.Archetypes-1.6.3-py2.6.egg/Products/Archetypes/CatalogMultiplex.py", line 123, in reindexObject
c.catalog_object(self, url, idxs=lst)
File "/Applications/Plone/plone-site/eggs/Plone-4.0.1-py2.6.egg/Products/CMFPlone/CatalogTool.py", line 287, in catalog_object
update_metadata, pghandler=pghandler)
File "/Applications/Plone/plone-site/eggs/Products.PDBDebugMode-1.3.1-py2.6.egg/Products/PDBDebugMode/zcatalog.py", line 20, in catalog_object
update_metadata=update_metadata, pghandler=pghandler)
File "/Applications/Plone/plone-site/eggs/Zope2-2.12.11-py2.6-macosx-10.4-x86_64.egg/Products/ZCatalog/ZCatalog.py", line 529, in catalog_object
update_metadata=update_metadata)
File "/Applications/Plone/plone-site/eggs/Zope2-2.12.11-py2.6-macosx-10.4-x86_64.egg/Products/ZCatalog/Catalog.py", line 348, in catalogObject
self.updateMetadata(object, uid)
File "/Applications/Plone/plone-site/eggs/Zope2-2.12.11-py2.6-macosx-10.4-x86_64.egg/Products/ZCatalog/Catalog.py", line 278, in updateMetadata
newDataRecord = self.recordify(object)
File "/Applications/Plone/plone-site/eggs/Zope2-2.12.11-py2.6-macosx-10.4-x86_64.egg/Products/ZCatalog/Catalog.py", line 417, in recordify
if(attr is not MV and safe_callable(attr)): attr=attr()
File "/Applications/Plone/plone-site/eggs/Products.CMFDynamicViewFTI-4.0-py2.6.egg/Products/CMFDynamicViewFTI/browserdefault.py", line 77, in __call__
template = template.__of__(context)
AttributeError: 'function' object has no attribute '__of__'
When I click save through the web I get a slightly different error message:
2011-08-09 15:19:16 ERROR Zope.SiteErrorLog 1312895956.510.252592718824 http://127.0.0.1:8080/Plone/Members/test_user2/test-doc/atct_edit
Traceback (innermost last):
Module ZPublisher.Publish, line 127, in publish
Module ZPublisher.mapply, line 77, in mapply
Module Products.PDBDebugMode.runcall, line 70, in pdb_runcall
Module ZPublisher.Publish, line 47, in call_object
Module Products.CMFFormController.FSControllerPageTemplate, line 91, in __call__
Module Products.CMFFormController.BaseControllerPageTemplate, line 28, in _call
Module Products.CMFFormController.ControllerBase, line 231, in getNext
Module Products.CMFFormController.Actions.TraverseTo, line 38, in __call__
Module ZPublisher.mapply, line 77, in mapply
Module ZPublisher.Publish, line 47, in call_object
Module Products.CMFFormController.FSControllerPythonScript, line 107, in __call__
Module Products.CMFFormController.ControllerBase, line 231, in getNext
Module Products.CMFFormController.Actions.TraverseTo, line 38, in __call__
Module ZPublisher.mapply, line 77, in mapply
Module ZPublisher.Publish, line 47, in call_object
Module Products.CMFFormController.FSControllerPythonScript, line 105, in __call__
Module Products.CMFFormController.Script, line 145, in __call__
Module Products.CMFCore.FSPythonScript, line 130, in __call__
Module Shared.DC.Scripts.Bindings, line 324, in __call__
Module Shared.DC.Scripts.Bindings, line 361, in _bindAndExec
Module Products.PythonScripts.PythonScript, line 344, in _exec
Module script, line 1, in content_edit
- <FSControllerPythonScript at /Plone/content_edit used for /Plone/Members/test_user2/test-doc>
- Line 1
Module Products.CMFCore.FSPythonScript, line 130, in __call__
Module Shared.DC.Scripts.Bindings, line 324, in __call__
Module Shared.DC.Scripts.Bindings, line 361, in _bindAndExec
Module Products.PythonScripts.PythonScript, line 344, in _exec
Module script, line 13, in content_edit_impl
- <FSPythonScript at /Plone/content_edit_impl used for /Plone/Members/test_user2/test-doc>
- Line 13
Module Products.Archetypes.BaseObject, line 658, in processForm
Module Products.Archetypes.BaseObject, line 650, in _processForm
- __traceback_info__: (<Issue at /Plone/Members/test_user2/test-doc>, <Field nextPreviousEnabled(boolean:rw)>, <bound method Issue.setNextPreviousEnabled of <Issue at /Plone/Members/test_user2/test-doc>>)
Module Products.Archetypes.CatalogMultiplex, line 123, in reindexObject
Module Products.CMFPlone.CatalogTool, line 287, in catalog_object
Module Products.PDBDebugMode.zcatalog, line 20, in catalog_object
Module Products.ZCatalog.ZCatalog, line 529, in catalog_object
Module Products.ZCatalog.Catalog, line 348, in catalogObject
Module Products.ZCatalog.Catalog, line 278, in updateMetadata
Module Products.ZCatalog.Catalog, line 417, in recordify
Module Products.CMFDynamicViewFTI.browserdefault, line 77, in __call__
AttributeError: 'function' object has no attribute '__of__'
> /Applications/Plone/plone-site/eggs/Products.CMFDynamicViewFTI-4.0-py2.6.egg/Products/CMFDynamicViewFTI/browserdefault.py(77)__call__()
76 context = aq_inner(self)
---> 77 template = template.__of__(context)
78 return template(context, context.REQUEST)
This looks strange indeed, some tips:
Pass a tuple into allowed_types instead of string:
allowed_types=('Source Document', ),
Make sure you don't have a content item with an id that matches a catalog index id. Also make sure you don't index getIssue_source but if you need to, use getRawIssue_source. Reference fields return real content objects, so using the normal accessor would store the real content objects in the catalog. That will lead to a lot of surprises and problems later on. The raw accessor returns a uuid or a list of uuids, which you can use in a catalog query like:
query = {'UID': uids}
brains = catalog(query)

Resources