1

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

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

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 中使用非常相似的代码我没有遇到任何困难。我将不胜感激任何帮助我摆脱痛苦的帮助。

编辑:顺便说一句:Pl​​one 4.05 PFG 1.72a

4

1 回答 1

1

正如 vangheem 所说,PloneFormGen 如何处理数据字段并不是一个 RestrictedPython 问题。_file添加到变量名中很重要。

于 2012-01-21T12:05:12.350 回答