0

Site Setup の Dexterity Manager を使用して、新しいコンテンツ タイプを作成しました。Plone ユーザー インターフェイスを介してコンテンツを正常に追加できますが、Python スクリプトを使用して同じオブジェクトを作成する必要があるところまで来ました。

私の最初の試みはinvokeFactoryでした:

context.invokeFactory("mycontenttype", id="test", Title="Test")

この同じコードは「Folder」オブジェクトに対して機能しますが、私の Dexterity タイプでは失敗します:

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 Shared.DC.Scripts.Bindings, line 322, in __call__
  Module Products.PloneHotfix20130618.spamProtect, line 35, in _patched_bindAndExec
  Module Shared.DC.Scripts.Bindings, line 359, in _bindAndExec
  Module Products.PythonScripts.PythonScript, line 344, in _exec
  Module script, line 7, in test
   - <PythonScript at /three-year-plan/test>
   - Line 7
TypeError: invokeFactory() takes at least 3 arguments (2 given)

さらに検索を行った後、次の関数を参照している場所がいくつか見つかりました。

from plone.dexterity.utils import createContentInContainer

Python スクリプトで plone.dexterity.utils からインポートしようとすると、パーミッション エラーが発生します。

Traceback (innermost last):

  Module ZPublisher.Publish, line 60, in publish
  Module ZPublisher.mapply, line 77, in mapply
  zModule ZPublisher.Publish, line 46, in call_object
  Module Shared.DC.Scripts.Bindings, line 322, in __call__
  Module Products.PloneHotfix20130618.spamProtect, line 35, in _patched_bindAndExec
  Module Shared.DC.Scripts.Bindings, line 359, in _bindAndExec
  Module Products.PythonScripts.PythonScript, line 344, in _exec
  Module script, line 1, in test
    - <PythonScript at /my-site/test>
    - Line 1
  Module AccessControl.ZopeGuards, line 305, in guarded_import
  Unauthorized: import of 'plone.dexterity.utils' is unauthorized

上記のエラーまたは代替方法を解決するための助けをいただければ幸いです。参考までに、バージョンの詳細を以下に掲載します。

バージョン概要

Plone 4.3.1 (4306)
CMF 2.2.7
Zope 2.13.19
Python 2.7.3 (default, Aug 1 2012, 05:14:39) [GCC 4.6.3]
PIL 1.7.8 (Pillow)
Dexterity Content Types 2.0.8
4

2 に答える 2

1

この目的には「invokeFactory」を使用できるはずです。コンテナーで呼び出し、型名を文字列として渡します。

invokeFactory メソッドを使用しようとして失敗した場所はわかりませんが、機能します。詳細については、 http://developer.plone.org/reference_manuals/external/plone.app.dexterity/reference/manipulating-content-objects.html?highlight=invokefactory#adding-an-object-to-a-containerを参照してください。

于 2013-08-06T16:41:36.060 に答える
1

あなたの推測は正しいです。createContentInContainer を使用する必要があります。ただし、いわゆる制限付き Python のみが許可されているため、Python スクリプトでは使用できません [1]。ビューに入れます[2]。

参考として、以下をご覧ください。

  1. http://developer.plone.org/reference_manuals/active/helloworld/extend/view.html
  2. http://plone.org/documentation/faq/restricted-python-scripts
于 2013-08-05T22:15:31.397 に答える