How to use the wagtailmedia.forms.BaseMediaForm function in wagtailmedia

To help you get started, we’ve selected a few wagtailmedia examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github torchbox / wagtailmedia / wagtailmedia / forms.py View on Github external
def __init__(self, *args, **kwargs):
        super(BaseMediaForm, self).__init__(*args, **kwargs)

        # We will need to exclude duration, width, height, thumbnail
        # if we would get this information from files metadata

        if self.instance.type == 'audio':
            for name in ('width', 'height'):
                # these fields might be editable=False so verify before accessing
                if name in self.fields:
                    del self.fields[name]
github torchbox / wagtailmedia / wagtailmedia / forms.py View on Github external
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(),
        })