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:
parent
9441b5de09
commit
46c524a872
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user