可以从PloneFormGen脚本在RestrictedPython中访问文件上传吗?

时间:2012-01-12 14:08:38

标签: plone ploneformgen

目前我正在尝试设置一个表格来创建一个新闻项目。到目前为止,脚本工作正常。文件字段出现问题:当我尝试通过request.form ['pub-core-cover']访问该文件时,我得到了一个“模块AccessControl.ZopeGuards,第67行,在guarded_getitem中”。

我被建议使用HelperView来绕过RestrictedPython,这似乎是这里的问题。这对我来说非常困难,因为到目前为止我还没有开发过附加产品。不知何故,我想知道是否有另一种可能性使PFG中的文件字段功能在RestrictedPython中再次工作。否则,文件字段会以某种方式变为obsolet。

CustomScript-Adapter(不介意德语评论):

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 (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'

在Plone3中使用非常相似的代码我没有遇到任何困难。我会感激任何让我摆脱痛苦的帮助。

编辑: 顺便说说: Plone 4.05 PFG 1.72a

1 个答案:

答案 0 :(得分:1)

正如vangheem所说,它不是RestrictedPython-问题,必须要做PloneFormGen如何处理数据字段。将_file添加到变量名称非常重要。