def register_newsitem_permissions_panel(): content_type = ContentType.objects.get_for_model(cls) return collection_member_permission_formset_factory( # Delete is automatically covered in change. cls, [ ('add_newsitem', _("Create"), _("Create any newsitem")), ('change_newsitem', _("Edit"), _("Edit/delete any newsitem")), ], 'wagtailnews/permissions/includes/newsitem_permissions_formset.html' )
fields = model.admin_form_fields if 'collection' not in fields: # force addition of the 'collection' field, because leaving it out can # cause dubious results when multiple collections exist (e.g adding the # document to the root collection where the user may not have permission) - # and when only one collection exists, it will get hidden anyway. fields = list(fields) + ['collection'] return modelform_factory( model, form=EmbedVideoInsertionForm, fields=fields, widgets={ # 'tags': widgets.AdminTagWidget, 'thumbnail': AdminImageChooser, }) class EmbedVideoInsertionForm(BaseCollectionMemberForm): permission_policy = embed_video_permission_policy alt_text = forms.CharField() GroupEmbedVideoPermissionFormSet = collection_member_permission_formset_factory( EmbedVideo, [ ('add_image', _("Add"), _("Add/edit embed videos you own")), ('change_image', _("Edit"), _("Edit any embed video")), ], 'wagtail_embed_videos/permissions/includes/image_permissions_formset.html')
if 'collection' not in fields: # force addition of the 'collection' field, because leaving it out can # cause dubious results when multiple collections exist (e.g adding the # document to the root collection where the user may not have permission) - # and when only one collection exists, it will get hidden anyway. fields = list(fields) + ['collection'] return modelform_factory( model, form=EmbedVideoInsertionForm, fields=fields, widgets={ # 'tags': widgets.AdminTagWidget, 'thumbnail': AdminImageChooser, }) class EmbedVideoInsertionForm(BaseCollectionMemberForm): permission_policy = embed_video_permission_policy alt_text = forms.CharField() GroupEmbedVideoPermissionFormSet = collection_member_permission_formset_factory( EmbedVideo, [ ('add_image', _("Add"), _("Add/edit embed videos you own")), ('change_image', _("Edit"), _("Edit any embed video")), ], 'wagtail_embed_videos/permissions/includes/image_permissions_formset.html' )
# force addition of the 'collection' field, because leaving it out can # cause dubious results when multiple collections exist (e.g adding the # document to the root collection where the user may not have permission) - # and when only one collection exists, it will get hidden anyway. fields = list(fields) + ['collection'] return modelform_factory(model, form=BaseDocumentForm, fields=fields, widgets={ 'tags': widgets.AdminTagWidget, 'file': forms.FileInput() }) def get_document_multi_form(model): return modelform_factory(model, form=BaseDocumentForm, fields=['title', 'collection', 'tags'], widgets={ 'tags': widgets.AdminTagWidget, 'file': forms.FileInput() }) GroupDocumentPermissionFormSet = collection_member_permission_formset_factory( Document, [ ('add_document', _("Add"), _("Add/edit documents you own")), ('change_document', _("Edit"), _("Edit any document")), ], 'wagtaildocs/permissions/includes/document_permissions_formset.html')
return modelform_factory( model, form=BaseDocumentForm, fields=fields, widgets={ 'tags': widgets.AdminTagWidget, 'file': forms.FileInput() }) def get_document_multi_form(model): return modelform_factory( model, form=BaseDocumentForm, fields=['title', 'collection', 'tags'], widgets={ 'tags': widgets.AdminTagWidget, 'file': forms.FileInput() }) GroupDocumentPermissionFormSet = collection_member_permission_formset_factory( Document, [ ('add_document', _("Add"), _("Add/edit documents you own")), ('change_document', _("Edit"), _("Edit any document")), ], 'wagtaildocs/permissions/includes/document_permissions_formset.html' )
widget=forms.RadioSelect ) alt_text = forms.CharField() class URLGeneratorForm(forms.Form): filter_method = forms.ChoiceField( label=_("Filter"), choices=( ('original', _("Original size")), ('width', _("Resize to width")), ('height', _("Resize to height")), ('min', _("Resize to min")), ('max', _("Resize to max")), ('fill', _("Resize to fill")), ), ) width = forms.IntegerField(_("Width"), min_value=0) height = forms.IntegerField(_("Height"), min_value=0) closeness = forms.IntegerField(_("Closeness"), min_value=0, initial=0) GroupImagePermissionFormSet = collection_member_permission_formset_factory( Image, [ ('add_image', _("Add"), _("Add/edit images you own")), ('change_image', _("Edit"), _("Edit any image")), ], 'wagtailimages/permissions/includes/image_permissions_formset.html' )
def get_media_form(model): fields = model.admin_form_fields if 'collection' not in fields: # force addition of the 'collection' field, because leaving it out can # cause dubious results when multiple collections exist (e.g adding the # media to the root collection where the user may not have permission) - # and when only one collection exists, it will get hidden anyway. fields = list(fields) + ['collection'] return modelform_factory( model, form=BaseMediaForm, fields=fields, widgets={ 'tags': widgets.AdminTagWidget, 'file': forms.FileInput(), 'thumbnail': forms.ClearableFileInput(), }) GroupMediaPermissionFormSet = collection_member_permission_formset_factory( Media, [ ('add_media', _("Add"), _("Add/edit media you own")), ('change_media', _("Edit"), _("Edit any media")), ], 'wagtailmedia/permissions/includes/media_permissions_formset.html' )
formfield_callback=formfield_for_dbfield, # set the 'file' widget to a FileInput rather than the default ClearableFileInput # so that when editing, we don't get the 'currently: ...' banner which is # a bit pointless here widgets={ 'tags': widgets.AdminTagWidget, 'file': forms.FileInput(), 'thumbnail': forms.FileInput(), }) class VideoTranscodeAdminForm(forms.Form): media_format = EnumField(MediaFormats) quality = EnumField(VideoQuality) def __init__(self, video, data=None, **kwargs): super(VideoTranscodeAdminForm, self).__init__(data=data, **kwargs) self.video = video def save(self): media_format = self.cleaned_data['media_format'] quality = self.cleaned_data['quality'] self.video.do_transcode(media_format, quality) GroupVideoPermissionFormSet = collection_member_permission_formset_factory( Video, [ ('add_video', _("Add"), _("Add/edit images you own")), ('change_video', _("Edit"), _("Edit any video")), ], 'wagtailvideos/permissions/includes/video_permissions_formset.html')
into a rich text area """ format = forms.ChoiceField(choices=[(format.name, format.label) for format in get_image_formats()], widget=forms.RadioSelect) alt_text = forms.CharField() class URLGeneratorForm(forms.Form): filter_method = forms.ChoiceField( label=_("Filter"), choices=( ('original', _("Original size")), ('width', _("Resize to width")), ('height', _("Resize to height")), ('min', _("Resize to min")), ('max', _("Resize to max")), ('fill', _("Resize to fill")), ), ) width = forms.IntegerField(_("Width"), min_value=0) height = forms.IntegerField(_("Height"), min_value=0) closeness = forms.IntegerField(_("Closeness"), min_value=0, initial=0) GroupImagePermissionFormSet = collection_member_permission_formset_factory( Image, [ ('add_image', _("Add"), _("Add/edit images you own")), ('change_image', _("Edit"), _("Edit any image")), ], 'wagtailimages/permissions/includes/image_permissions_formset.html')