Skip to content

Commit

Permalink
Add MediaContainer class
Browse files Browse the repository at this point in the history
  • Loading branch information
tbrlpld committed Nov 22, 2023
1 parent 24c0718 commit be341df
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion laces/components.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any, MutableMapping

from django.forms import MediaDefiningClass
from django.forms import Media, MediaDefiningClass
from django.template import Context
from django.template.loader import get_template

Expand Down Expand Up @@ -38,3 +38,20 @@ def render_html(self, parent_context: MutableMapping[str, Any] = None) -> str:

template = get_template(self.template_name)
return template.render(context_data)


class MediaContainer(list):
"""
A list that provides a ``media`` property that combines the media definitions
of its members.
Extracted from Wagtail. See:
https://github.com/wagtail/wagtail/blob/ca8a87077b82e20397e5a5b80154d923995e6ca9/wagtail/admin/ui/components.py#L25-L36 # noqa: E501
"""

@property
def media(self):
media = Media()
for item in self:
media += item.media
return media

0 comments on commit be341df

Please sign in to comment.