#21987: Allow Media objects to have their own MEDIA_TYPES
-----------------------------------------+--------------------
     Reporter:  Keryn Knight <django@…>  |      Owner:  nobody
         Type:  Cleanup/optimization     |     Status:  new
    Component:  Forms                    |    Version:  master
     Severity:  Normal                   |   Keywords:
 Triage Stage:  Unreviewed               |  Has patch:  0
Easy pickings:  0                        |      UI/UX:  0
-----------------------------------------+--------------------
 Currently,
 
[https://github.com/django/django/blob/a2814846ca006b4fbf3a893ec52cd9d444b3a3eb/django/forms/widgets.py#L35
 instances of Media] look to the module scope to get the known
 
[https://github.com/django/django/blob/a2814846ca006b4fbf3a893ec52cd9d444b3a3eb/django/forms/widgets.py#L31
 MEDIA_TYPES]. This makes it difficult to subclass `Media` to add extra
 `render_x`/`add_x` methods because `MEDIA_TYPES` is hardcoded in
 
[https://github.com/django/django/blob/a2814846ca006b4fbf3a893ec52cd9d444b3a3eb/django/forms/widgets.py#L45
 __init__],
 
[https://github.com/django/django/blob/a2814846ca006b4fbf3a893ec52cd9d444b3a3eb/django/forms/widgets.py#L56
 render],
 
[https://github.com/django/django/blob/a2814846ca006b4fbf3a893ec52cd9d444b3a3eb/django/forms/widgets.py#L83
 __getitem__] and
 
[https://github.com/django/django/blob/a2814846ca006b4fbf3a893ec52cd9d444b3a3eb/django/forms/widgets.py#L102
 __add__] and isn't easily available for a subclass to add to without
 monkeypatching the module constant. As far as I can tell, the only use of
 `MEDIA_TYPES` is in the widgets module, and could be shifted to the class
 itself, leaving the module level one to raise a deprecation warning.

 Rationale is that I want to be able to add `inline_css` and `inline_js`,
 or `text` (for JS templates etc) to a `Media` object, and currently that's
 more difficult than just adjusting a subclass' attribute and adding the
 appropriate methods.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/21987>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/080.14c2ac60a12e7d4824603e3777e01f13%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to