0

基于:http ://www.sixfeetup.com/blog/how-to-allow-users-to-create-site-content-using-ploneformgen

我尝试了这个自定义脚本适配器:

pasta = context.portal_url.getPortalObject()['conteudo']
(comment) The form being submitted so we can access its contents
form = request.form

(comment) Create a unique ID
from DateTime import DateTime
identidade = str(DateTime().millis())

(comment) Create a new Page (Document)
pasta.invokeFactory("Document", id=identidade, title=form['nome-completo'])

(comment) Set the reference for our new Page
obj=pasta[identidade]

(comment) Set the values for the content of the Page; use the short names of each item in the form
(comment) (which you can see in the URL if you are viewing one of the fields directly)
obj.setContentType('text/html')
obj.setText(form['formacao'])


(comment) Reindexed the Page in the site
obj.reindexObject()

但我收到了这个奇怪的错误:

Traceback (innermost last):
-Module ZPublisher.Publish, line 60, 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 Products.PloneHotfix20130618.spamProtect, line 33, in _patched_bindAndExec
-Module Products.PloneHotfix20121106.python_scripts, line 63, in _patched_bindAndExec
-Module Shared.DC.Scripts.Bindings, line 359, in _bindAndExec
-Module Products.PythonScripts.PythonScript, line 344, in _exec
-Module script, line 20, in fgvalidate_base
  - <FSControllerValidator at /course/statistics/fgvalidate_base used for /course/statistics/create/form>
-Line 20
-Module Products.PloneFormGen.content.form, line 574, in fgvalidate
-Module Products.PloneFormGen.content.form, line 622, 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 322, in __call__
-Module Products.PloneHotfix20130618.spamProtect, line 33, in _patched_bindAndExec
-Module Products.PloneHotfix20121106.python_scripts, line 63, in _patched_bindAndExec
-Module Shared.DC.Scripts.Bindings, line 359, in _bindAndExec
-Module Products.PythonScripts.PythonScript, line 344, in _exec
-Module script, line 15, in Processing Data
  - <PythonScript at /course/statistics/create/form/formcustomscriptadapter.2016-03-21.4473916570/Processing Data>
-Line 15
-Module AccessControl.ZopeGuards, line 83, in guarded_getitem
-Module Products.PloneHotfix20130618.get, line 38, in __getitem__
-**KeyError: '1458833943942'**

谁能建议该怎么做?

4

1 回答 1

1

答:我只是换了行

obj=pasta[identidade]

至:

obj = pasta.get('identidade',pasta)

它起作用了:-)

于 2016-04-26T22:36:31.837 回答