class Media

from django.forms import Media

Ancestors (MRO)

  1. Media
Expand Collapse


def absolute_path(self, path, prefix=None): Media

    def absolute_path(self, path, prefix=None):
        if path.startswith(('http://', 'https://', '/')):
            return path
        if prefix is None:
            if settings.STATIC_URL is None:
                # backwards compatibility
                prefix = settings.MEDIA_URL
                prefix = settings.STATIC_URL
        return urljoin(prefix, path)

def add_css(self, data): Media

    def add_css(self, data):
        if data:
            for medium, paths in data.items():
                for path in paths:
                    if not self._css.get(medium) or path not in self._css[medium]:
                        self._css.setdefault(medium, []).append(path)

def add_js(self, data): Media

    def add_js(self, data):
        if data:
            for path in data:
                if path not in self._js:

def render(self): Media

    def render(self):
        return mark_safe('\n'.join(chain(*[getattr(self, 'render_' + name)() for name in MEDIA_TYPES])))

def render_css(self): Media

    def render_css(self):
        # To keep rendering order consistent, we can't just iterate over items().
        # We need to sort the keys, and iterate over the sorted list.
        media = sorted(self._css.keys())
        return chain(*[[
                '<link href="{}" type="text/css" media="{}" rel="stylesheet" />',
                self.absolute_path(path), medium
            ) for path in self._css[medium]
        ] for medium in media])

def render_js(self): Media

    def render_js(self):
        return [
                '<script type="text/javascript" src="{}"></script>',
            ) for path in self._js