ユーザーはできるからそうするのです。
ただし、画像の自動リサイズなどは壊れます。
これは私を悲しい少年にします。
サイト全体で画像のアップロードを GIF、PNG、および JPEG に制限するにはどうすればよいですか?
アーキタイプの場合
器用さのために
ユーザーはできるからそうするのです。
ただし、画像の自動リサイズなどは壊れます。
これは私を悲しい少年にします。
サイト全体で画像のアップロードを GIF、PNG、および JPEG に制限するにはどうすればよいですか?
アーキタイプの場合
器用さのために
アーキタイプを使用して、画像コンテンツクラスをオーバーライドするか、次のスキーマを使用して独自のカスタム画像コンテンツクラスを作成します。
行を追加するだけです
allowable_content_types = ('image/gif', 'image/jpeg', 'image/png'),
スキーマに
すなわち
MyImageSchema = schemata.ATContentTypeSchema.copy() + atapi.Schema((
ImageField('image',
required = False,
allowable_content_types = ('image/gif', 'image/jpeg', 'image/png'),
storage=AttributeStorage(),
sizes= {'large' : (768, 768),
'preview' : (400, 400),
'mini' : (200, 200),
'thumb' : (128, 128),
'tile' : (64, 64),
'icon' : (32, 32),
'listing' : (16, 16),
},
widget = ImageWidget(
label=_(u"Image"),
show_content_type=False,
),
),
おそらくスキーマエクステンダーを使用してImageクラスを拡張し、その特定のフィールドをオーバーライドします
私は最近同様の問題に遭遇し、そのようにそれらを回避しました:
accept
ファイル入力に属性を追加するカスタムウィジェットを追加しますfield.swallowResizeExceptions = True
サポートされていない画像タイプをアップロードするときに、ユーザーが少なくともサイトエラーを受け取らないように設定しますフィールド定義は次のようになります。
atapi.ImageField('image1',
swallowResizeExceptions = True,
widget = atapi.ImageWidget(
label = _(u"Image 1"),
description = _(u"Image used in listings. (JPEG, PNG and GIF are supported)"),
show_content_type = False,
accept = 'image/*',
macro = 'mywidgets/myimage',
),
),
http://www.w3schools.com/tags/att_input_accept.aspaccept="image/jpeg,image/gif"
に従ってサポートされているはずですが、firefox11では無視されていることに注意してください。
mywidgets / myimageは、archetypes / skins / widgets / image.ptのカスタマイズされたバージョンであり、archetypes / skins / widgets/file.ptのカスタマイズされたバージョンを使用します。
<metal:define define-macro="edit">
...
<metal metal:use-macro="here/mywidgets/myfile/macros/file_upload"/>
...
mywidgets / myfile.ptは、単にこのマクロを定義します。
<metal:define define-macro="file_upload"
tal:define="unit accessor;
size unit/get_size | python:unit and len(unit) or 0;">
<input type="file"
size="30"
tal:attributes="name string:${fieldName}_file;
id string:${fieldName}_file;
accept widget/accept|nothing;" />
<script type="text/javascript"
tal:define="isDisabled python:test(accessor() and size!=0, 'true', 'false')"
tal:content="string:document.getElementById('${fieldName}_file').disabled=$isDisabled;">
</script>
</metal:define>
検証後イベントを使用した AT の側面全体の制限:
check Ploneで画像ファイルの拡張子を制限するには?