Plone 4.1 でフォルダの内容に独自の制限を追加できますか? 例えば。*.doc、*.pdf などの拡張子を持つファイルのみを含むようにフォルダーを制限します Plone で利用可能なファイル/フォルダー/ページ/画像などの一般的な制限を認識しています
1 に答える
追加の開発がないわけではありません。許可される MIME タイプを制限するには、バリデーターを使用して File タイプを拡張する必要があります。
完全な詳細には触れずに (行き詰まった場合は、自分で試して、SO でさらに質問してください)、この問題に直面した場合に実装するさまざまな可動部分を次に示します。
IValidator
許可されているコンテンツ タイプをチェックする新しいクラスを作成します。from zope.interface import implements from Products.validation.interfaces.IValidator import IValidator class LocalContentTypesValidator(object): implements(IValidator) def __init__(self, name, title='', description='') self.name = name self.title = title or name self.description = description def __call__(value, *args, **kwargs): instance = kwargs.get('instance', None) field = kwargs.get('field', None) # Get your list of content types from the aq_parent of the instance # Verify that the value (*usually* a python file object) # I suspect you have to do some content type sniffing here # Return True if the content type is allowed, or an error message
バリデーターのインスタンスをレジスターに登録します。
from Products.validation.config import validation validation.register(LocalContentTypesValidator('checkLocalContentTypes'))
ベースクラス スキーマのコピーを使用して ATContentTypes ATFile クラスの新しいサブクラスを作成し、バリデーターをその検証チェーンに追加します。
from Products.ATContentTypes.content.file import ATFile, ATFileSchema Schema = ATFileSchema.schema.copy() Schema['file'].validators = schema['file'].validators + ( 'checkLocalContentTypes',) class ContentTypeRestrictedFile(ATFile): schema = Schema # Everything else you need for a custom Archetype
または、展開内のすべてのファイル オブジェクトに適用する場合は、ATFile スキーマ自体を変更します。
from Products.ATContentTypes.content.file import ATFileSchema ATFileSchema['file'].validators = ATFileSchema['file'].validators + ( 'checkLocalContentTypes',)
フィールドをフォルダまたはカスタム サブクラスに追加して、ローカルで許可されたコンテンツ タイプのリストを保存します。私はおそらくこれに使うでしょう
archetypes.schemaextender
。WebLion has a nice tutorial
たとえば、最近ではこれに関するドキュメントがたくさんあります。もちろん、ここで人々に MIME タイプを制限させる方法についてポリシーを決定する必要があります。ワイルドカード、自由形式のテキスト、語彙など。