tickets: 21987
This data as json
id | created | changetime | last_pulled_from_trac | stage | status | component | type | severity | version | resolution | summary | description | owner | reporter | keywords | easy | has_patch | needs_better_patch | needs_tests | needs_docs | ui_ux |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
21987 | 2014-02-08 18:27:37 | 2014-05-04 15:13:28 | 2022-03-06 04:17:55.109844 | Accepted | assigned | Forms | Cleanup/optimization | Normal | dev | Allow Media objects to have their own MEDIA_TYPES | 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. | Osmose | Keryn Knight <django@kerynknight.com> | 0 | 1 | 1 | 0 | 0 | 0 |