2012-01-12 87 views
1

目前我正在嘗試設置一個表單來創建一個新聞項目。該腳本到目前爲止工作正常。文件字段出現問題:只要我嘗試通過request.form ['pub-core-cover']訪問文件,我就會看到一個名爲「Module AccessControl.ZopeGuards,line 67,in guarded_getitem」的文件。可以通過PloneFormGen腳本在RestrictedPython中訪問文件上傳嗎?

我被建議使用HelperView繞過RestrictedPython,這似乎是這裏的問題。由於我迄今尚未開發附加產品,這對我來說很難。不知何故,我想知道如果有另一種可能性使PFG中的文件字段功能再次在RestrictedPython中工作。否則,文件字段會變成obsolet。

CustomScript適配器(不介意德國評論):

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

文件數據實際上不是形式['pub-core-cover-file']? KeyError僅僅是說對該密鑰的請求沒有任何價值。您可能需要檢查請求,以便查看其中的內容。另外,http://pypi.python.org/pypi/uwosh.pfg.d2c的插件可能會對您有所幫助。 – vangheem 2012-01-12 18:59:56

+0

感謝您的回覆。沒有爲什麼要將變量命名爲['pub-core-cover-file']?我宣佈它的形式['pub-core-cover']。對我來說,關鍵的問題不是'pub-core-cover',而是上面的那條線讓我想到RestrictedPython,我想繞過它。一般來說,我不想使用額外的插件,但使用已經存在的長期產品的功能。 – 2012-01-13 12:07:31

+1

不,請看看如何上傳文件。它實際上是附加在密鑰上的'_file'。我寫了d2c,並且不得不使用它來進行文件上傳。退房http://svn.plone.org/svn/collective/uwosh.pfg.d2c/trunk/uwosh/pfg/d2c/content/savedataadapter.py 您收到的錯誤是一個KeyError:'pub-core '表示'pub-core-cover'的'cover'不是表單字典中的關鍵。 – vangheem 2012-01-13 18:12:06

回答

1

由於vangheem說,它是不是一個RestrictedPython-問題提出必須做PloneFormGen如何處理數據字段。將_file添加到變量名稱很重要。

相關問題