Python django.forms.Media() Examples

The following are 30 code examples for showing how to use django.forms.Media(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module django.forms , or try the search function .

Example 1
Project: django-admin-json-editor   Author: abogushov   File: admin.py    License: MIT License 6 votes vote down vote up
def media(self):
        css = {
            'all': [
                'django_admin_json_editor/fontawesome/css/font-awesome.min.css',
                'django_admin_json_editor/style.css',
            ]
        }
        js = [
            'django_admin_json_editor/jsoneditor/jsoneditor.min.js',
        ]

        if self._editor_options['theme'] == 'bootstrap4':
            css['all'].append('django_admin_json_editor/bootstrap/css/bootstrap.min.css')
            js.append('django_admin_json_editor/jquery/jquery-3.5.1.slim.min.js')
            js.append('django_admin_json_editor/bootstrap/js/bootstrap.bundle.min.js')

        if self._sceditor:
            css['all'].append('django_admin_json_editor/sceditor/themes/default.min.css')
            js.append('django_admin_json_editor/sceditor/jquery.sceditor.bbcode.min.js')
        return forms.Media(css=css, js=js) 
Example 2
Project: bioforum   Author: reBiocoder   File: widgets.py    License: MIT License 6 votes vote down vote up
def media(self):
        extra = '' if settings.DEBUG else '.min'
        i18n_name = SELECT2_TRANSLATIONS.get(get_language())
        i18n_file = ('admin/js/vendor/select2/i18n/%s.js' % i18n_name,) if i18n_name else ()
        return forms.Media(
            js=(
                'admin/js/vendor/jquery/jquery%s.js' % extra,
                'admin/js/vendor/select2/select2.full%s.js' % extra,
            ) + i18n_file + (
                'admin/js/jquery.init.js',
                'admin/js/autocomplete.js',
            ),
            css={
                'screen': (
                    'admin/css/vendor/select2/select2%s.css' % extra,
                    'admin/css/autocomplete.css',
                ),
            },
        ) 
Example 3
Project: dissemin   Author: dissemin   File: widgets.py    License: GNU Affero General Public License v3.0 6 votes vote down vote up
def media(self):
        """
        Construct Media as a dynamic property.
        .. Note:: For more information visit
            https://docs.djangoproject.com/en/stable/topics/forms/media/#media-as-a-dynamic-property
        """
        lang = get_language()
        select2_js = (settings.SELECT2_JS,) if settings.SELECT2_JS else ()
        select2_css = (settings.SELECT2_CSS,) if settings.SELECT2_CSS else ()

        i18n_name = SELECT2_TRANSLATIONS.get(lang)
        if i18n_name not in settings.SELECT2_I18N_AVAILABLE_LANGUAGES:
            i18n_name = None

        i18n_file = (
            ('%s/%s.js' % (settings.SELECT2_I18N_PATH, i18n_name),)
            if i18n_name
            else ()
        )

        return forms.Media(
            js=select2_js + i18n_file + (static("js/django_select2.js"), ),
            css={'screen': select2_css}
        ) 
Example 4
Project: Hands-On-Application-Development-with-PyCharm   Author: PacktPublishing   File: widgets.py    License: MIT License 6 votes vote down vote up
def media(self):
        extra = '' if settings.DEBUG else '.min'
        i18n_name = SELECT2_TRANSLATIONS.get(get_language())
        i18n_file = ('admin/js/vendor/select2/i18n/%s.js' % i18n_name,) if i18n_name else ()
        return forms.Media(
            js=(
                'admin/js/vendor/jquery/jquery%s.js' % extra,
                'admin/js/vendor/select2/select2.full%s.js' % extra,
            ) + i18n_file + (
                'admin/js/jquery.init.js',
                'admin/js/autocomplete.js',
            ),
            css={
                'screen': (
                    'admin/css/vendor/select2/select2%s.css' % extra,
                    'admin/css/autocomplete.css',
                ),
            },
        ) 
Example 5
Project: StormOnline   Author: stormsha   File: dashboard.py    License: Apache License 2.0 5 votes vote down vote up
def media(self):
        return forms.Media() 
Example 6
Project: StormOnline   Author: stormsha   File: base.py    License: Apache License 2.0 5 votes vote down vote up
def get_media(self):
        return forms.Media() 
Example 7
Project: StormOnline   Author: stormsha   File: util.py    License: Apache License 2.0 5 votes vote down vote up
def vendor(*tags):
    media = Media()
    for tag in tags:
        file_type = tag.split('.')[-1]
        files = xstatic(tag)
        if file_type == 'js':
            media.add_js(files)
        elif file_type == 'css':
            media.add_css({'screen': files})
    return media 
Example 8
Project: mendelmd   Author: raonyguimaraes   File: forms.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _get_media(self):
        """
        Construct Media as a dynamic property.

        .. Note:: For more information visit
            https://docs.djangoproject.com/en/1.8/topics/forms/media/#media-as-a-dynamic-property
        """
        return forms.Media(
            js=(settings.SELECT2_JS, 'django_select2/django_select2.js'),
            css={'screen': (settings.SELECT2_CSS,)}
        ) 
Example 9
Project: mendelmd   Author: raonyguimaraes   File: forms.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _get_media(self):
        """
        Construct Media as a dynamic property.

        .. Note:: For more information visit
            https://docs.djangoproject.com/en/1.8/topics/forms/media/#media-as-a-dynamic-property
        """
        return forms.Media(
            js=(settings.SELECT2_JS, 'django_select2/django_select2.js'),
            css={'screen': (settings.SELECT2_CSS,)}
        ) 
Example 10
Project: mendelmd   Author: raonyguimaraes   File: forms.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _get_media(self):
        """
        Construct Media as a dynamic property.

        .. Note:: For more information visit
            https://docs.djangoproject.com/en/1.8/topics/forms/media/#media-as-a-dynamic-property
        """
        return forms.Media(
            js=(settings.SELECT2_JS, 'django_select2/django_select2.js'),
            css={'screen': (settings.SELECT2_CSS,)}
        ) 
Example 11
Project: GTDWeb   Author: lanbing510   File: widgets.py    License: GNU General Public License v2.0 5 votes vote down vote up
def media(self):
        js = ["core.js", "SelectBox.js", "SelectFilter2.js"]
        return forms.Media(js=[static("admin/js/%s" % path) for path in js]) 
Example 12
Project: GTDWeb   Author: lanbing510   File: widgets.py    License: GNU General Public License v2.0 5 votes vote down vote up
def media(self):
        js = ["calendar.js", "admin/DateTimeShortcuts.js"]
        return forms.Media(js=[static("admin/js/%s" % path) for path in js]) 
Example 13
Project: GTDWeb   Author: lanbing510   File: widgets.py    License: GNU General Public License v2.0 5 votes vote down vote up
def media(self):
        js = ["calendar.js", "admin/DateTimeShortcuts.js"]
        return forms.Media(js=[static("admin/js/%s" % path) for path in js]) 
Example 14
Project: GTDWeb   Author: lanbing510   File: widgets.py    License: GNU General Public License v2.0 5 votes vote down vote up
def media(self):
        media = Media(js=[static('admin/js/related-widget-wrapper.js')])
        return self.widget.media + media 
Example 15
Project: GTDWeb   Author: lanbing510   File: helpers.py    License: GNU General Public License v2.0 5 votes vote down vote up
def _media(self):
        if 'collapse' in self.classes:
            extra = '' if settings.DEBUG else '.min'
            js = ['jquery%s.js' % extra,
                  'jquery.init.js',
                  'collapse%s.js' % extra]
            return forms.Media(js=[static('admin/js/%s' % url) for url in js])
        return forms.Media() 
Example 16
Project: GTDWeb   Author: lanbing510   File: options.py    License: GNU General Public License v2.0 5 votes vote down vote up
def media(self):
        extra = '' if settings.DEBUG else '.min'
        js = ['jquery%s.js' % extra, 'jquery.init.js', 'inlines%s.js' % extra]
        if self.prepopulated_fields:
            js.extend(['urlify.js', 'prepopulate%s.js' % extra])
        if self.filter_vertical or self.filter_horizontal:
            js.extend(['SelectBox.js', 'SelectFilter2.js'])
        return forms.Media(js=[static('admin/js/%s' % url) for url in js]) 
Example 17
Project: kobo-predict   Author: awemulya   File: forms.py    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
def _media(self):
        css = {}
        js = ()
        return Media(css=css, js=js) 
Example 18
Project: django-admin-numeric-filter   Author: lukasvinclav   File: forms.py    License: MIT License 5 votes vote down vote up
def media(self):
        return super().media + Media(css=[self.NUMERIC_FILTER_CSS]) 
Example 19
Project: django-admin-numeric-filter   Author: lukasvinclav   File: forms.py    License: MIT License 5 votes vote down vote up
def media(self):
        return super().media + Media(css=[self.NUMERIC_FILTER_CSS]) 
Example 20
Project: django-mdeditor   Author: pylixm   File: widgets.py    License: GNU General Public License v3.0 5 votes vote down vote up
def _get_media(self):
        return forms.Media(
            css={
                "all": ("mdeditor/css/editormd.css",)
            },
            js=(
                "mdeditor/js/jquery.min.js",
                "mdeditor/js/editormd.min.js",
            )) 
Example 21
Project: wagtail-tag-manager   Author: jberghoef   File: views.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def media(self):
        return forms.Media(
            css={
                "all": [
                    "wagtail_tag_manager/index.bundle.css",
                    *self.model_admin.get_index_view_extra_css(),
                ]
            },
            js=[
                "wagtail_tag_manager/index.bundle.js",
                *self.model_admin.get_index_view_extra_js(),
            ],
        ) 
Example 22
Project: DCRM   Author: 82Flex   File: widgets.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def media(self):
        return forms.Media(js=('suit/js/autosize.min.js',)) 
Example 23
Project: bioforum   Author: reBiocoder   File: widgets.py    License: MIT License 5 votes vote down vote up
def media(self):
        extra = '' if settings.DEBUG else '.min'
        js = [
            'vendor/jquery/jquery%s.js' % extra,
            'jquery.init.js',
            'core.js',
            'SelectBox.js',
            'SelectFilter2.js',
        ]
        return forms.Media(js=["admin/js/%s" % path for path in js]) 
Example 24
Project: bioforum   Author: reBiocoder   File: widgets.py    License: MIT License 5 votes vote down vote up
def media(self):
        extra = '' if settings.DEBUG else '.min'
        js = [
            'vendor/jquery/jquery%s.js' % extra,
            'jquery.init.js',
            'calendar.js',
            'admin/DateTimeShortcuts.js',
        ]
        return forms.Media(js=["admin/js/%s" % path for path in js]) 
Example 25
Project: bioforum   Author: reBiocoder   File: widgets.py    License: MIT License 5 votes vote down vote up
def media(self):
        extra = '' if settings.DEBUG else '.min'
        js = [
            'vendor/jquery/jquery%s.js' % extra,
            'jquery.init.js',
            'calendar.js',
            'admin/DateTimeShortcuts.js',
        ]
        return forms.Media(js=["admin/js/%s" % path for path in js]) 
Example 26
Project: bioforum   Author: reBiocoder   File: helpers.py    License: MIT License 5 votes vote down vote up
def media(self):
        if 'collapse' in self.classes:
            extra = '' if settings.DEBUG else '.min'
            js = [
                'vendor/jquery/jquery%s.js' % extra,
                'jquery.init.js',
                'collapse%s.js' % extra,
            ]
            return forms.Media(js=['admin/js/%s' % url for url in js])
        return forms.Media() 
Example 27
Project: bioforum   Author: reBiocoder   File: options.py    License: MIT License 5 votes vote down vote up
def media(self):
        extra = '' if settings.DEBUG else '.min'
        js = ['vendor/jquery/jquery%s.js' % extra, 'jquery.init.js',
              'inlines%s.js' % extra]
        if self.filter_vertical or self.filter_horizontal:
            js.extend(['SelectBox.js', 'SelectFilter2.js'])
        if self.classes and 'collapse' in self.classes:
            js.append('collapse%s.js' % extra)
        return forms.Media(js=['admin/js/%s' % url for url in js]) 
Example 28
Project: bioforum   Author: reBiocoder   File: options.py    License: MIT License 5 votes vote down vote up
def media(self):
        "Injects OpenLayers JavaScript into the admin."
        return super().media + Media(js=[self.openlayers_url] + self.extra_js) 
Example 29
Project: wagtail-personalisation   Author: wagtail   File: views.py    License: MIT License 5 votes vote down vote up
def media(self):
        return forms.Media(
            css={'all': ['css/dashboard.css']},
            js=['js/commons.js', 'js/dashboard.js']
        ) 
Example 30
Project: pasportaservo   Author: tejoesperanto   File: widgets.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def media(self):
        return (
            forms.Media(css=self.Media.css, js=self.Media.js)
            + forms.Media(js=(
                format_lazy('{}?format=js&type=widget', reverse_lazy('gis_endpoints')),
                'maps/mapbox-gl.eo.js',
                'maps/mapbox-gl-widget.js'))
        )