0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-12-01 11:41:20 +01:00

Introduce MediaContainer class to ease combining media definitions

This commit is contained in:
Sage Abdullah 2023-09-20 12:37:13 +01:00
parent 9441b5de09
commit 46c524a872
No known key found for this signature in database
GPG Key ID: EB1A33CC51CC0217

View File

@ -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
@ -20,3 +20,17 @@ class Component(metaclass=MediaDefiningClass):
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.
"""
@property
def media(self):
media = Media()
for item in self:
media += item.media
return media