-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BaseMediaForm cannot be subclassed #147
Comments
Hey @jsma, I've customised the media form without issues in the past. Can you update the issue with
The key issue here seems to be the circular import in the error. |
This caused import issues for projects that subclassed ``BaseMediaForm``. Updated tests to rely on overriding settings instead of mocking the return value. Fixed tox config for dj32, which was accidentally only testing Django 3.1.x (the bug was introduced in 5e2f95e). Fixes torchbox#147
Hi @zerolab, Thanks for the reply! The simplest way to reproduce in my project is to have this in forms.py: from wagtailmedia.forms import BaseMediaForm
def no_op():
pass
class CustomMediaForm(BaseMediaForm):
pass Then in admin.py: from .forms import no_op This results in:
I noticed that wagtail does not call def get_document_base_form():
base_form_override = getattr(settings, "WAGTAILDOCS_DOCUMENT_FORM_BASE", "")
if base_form_override:
from django.utils.module_loading import import_string
base_form = import_string(base_form_override)
else:
base_form = BaseDocumentForm
return base_form
def get_document_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
# 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=get_document_base_form(),
fields=fields,
formfield_callback=formfield_for_dbfield,
) I'll submit a PR shortly. |
Thank you for taking the time to provide the additional info and the PR. Will try to review your PR asap |
Issue Summary
I attempted a customization along the lines of #64. My first approach was to subclass the existing BaseMediaForm so I could inherit the existing
__init__
logic andpermission_policy
and focus solely on modifying the widgets. However, this lead to errors sinceget_base_form()
is called at the module level:wagtailmedia/src/wagtailmedia/forms.py
Line 48 in 4d0efb9
The resulting error:
Any reason the
get_base_form()
call cannot happen insideget_media_form()
?Happy to submit a PR if this change is acceptable. Thanks!
The text was updated successfully, but these errors were encountered: