Here are the examples of the python api django.forms.Media taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
56 Examples
3
View Complete Implementation : widgets.py
Copyright GNU General Public License v3.0
Author : pylixm
Copyright GNU General Public License v3.0
Author : pylixm
def _get_media(self):
return forms.Media(
css={
"all": ("mdeditor/css/editormd.css",)
},
js=(
"mdeditor/js/jquery.min.js",
"mdeditor/js/editormd.min.js",
))
3
View Complete Implementation : helpers.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : Ryuchen
Copyright BSD 3-Clause "New" or "Revised" License
Author : Ryuchen
@property
def media(self):
if 'collapse' in self.clastes:
extra = '' if settings.DEBUG else '.min'
return forms.Media(js=['admin/js/collapse%s.js' % extra])
return forms.Media()
3
View Complete Implementation : views.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : jberghoef
Copyright BSD 3-Clause "New" or "Revised" License
Author : jberghoef
@property
def media(self):
return forms.Media(
css={
"all": [
static("index.bundle.css"),
*self.model_admin.get_index_view_extra_css(),
]
},
js=[static("index.bundle.js"), *self.model_admin.get_index_view_extra_js()],
)
3
View Complete Implementation : test_media.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_merge_js_three_way2(self):
# The merge prefers to place 'c' before 'b' and 'g' before 'h' to
# preserve the original order. The preference 'c'->'b' is overridden by
# widget3's media, but 'g'->'h' survives in the final ordering.
widget1 = Media(js=['a', 'c', 'f', 'g', 'k'])
widget2 = Media(js=['a', 'b', 'f', 'h', 'k'])
widget3 = Media(js=['b', 'c', 'f', 'k'])
merged = widget1 + widget2 + widget3
self.astertEqual(merged._js, ['a', 'b', 'c', 'f', 'g', 'h', 'k'])
3
View Complete Implementation : widgets.py
Copyright MIT License
Author : voxy
Copyright MIT License
Author : voxy
@property
def media(self):
css = {
'all': ['//cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.4/css/bootstrap-select.min.css', # noqa
static('bootstrap_select/bootstrap_select.css'), ]
}
js = ['//cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.4/js/bootstrap-select.min.js', ] # noqa
if self.bootstrap_css:
css['all'] = ['//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'] + css['all'] # noqa
if self.bootstrap_js:
js = ['//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js'] + js
if self.jquery_js:
js = ['//ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js'] + js
return forms.Media(
css=css,
js=js,
)
3
View Complete Implementation : util.py
Copyright GNU General Public License v2.0
Author : iopsgroup
Copyright GNU General Public License v2.0
Author : iopsgroup
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
3
View Complete Implementation : widgets.py
Copyright MIT License
Author : rizwansoaib
Copyright MIT License
Author : rizwansoaib
@property
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])
def vendor(*tags):
css = {'screen': []}
js = []
for tag in tags:
file_type = tag.split('.')[-1]
files = xstatic(tag)
if file_type == 'js':
js.extend(files)
elif file_type == 'css':
css['screen'] += files
return Media(css=css, js=js)
3
View Complete Implementation : views.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : simplyopen-it
Copyright BSD 3-Clause "New" or "Revised" License
Author : simplyopen-it
@property
def media(self):
# taken from django.contrib.admin.options ModelAdmin
extra = '' if settings.DEBUG else '.min'
js = [
'core.js',
'vendor/jquery/jquery%s.js' % extra,
'jquery.init.js',
'admin/RelatedObjectLookups.js',
'actions%s.js' % extra,
'urlify.js',
'prepopulate%s.js' % extra,
'vendor/xregexp/xregexp%s.js' % extra,
]
return forms.Media(js=[static('admin/js/%s' % url) for url in js])
3
View Complete Implementation : test_forms.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_absolute_url(self):
m = Media(
css={'all': ('path/to/css1', '/path/to/css2')},
js=(
'/path/to/js1',
'http://media.other.com/path/to/js2',
'https://secure.other.com/path/to/js3',
static('relative/path/to/js4'),
),
)
self.astertEqual(
str(m),
"""<link href="https://example.com/astets/path/to/css1" type="text/css" media="all" rel="stylesheet">
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
<script type="text/javascript" src="https://example.com/astets/relative/path/to/js4"></script>"""
)
3
View Complete Implementation : test_media.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_merge_js_three_way(self):
"""
The relative order of scripts is preserved in a three-way merge.
"""
widget1 = Media(js=['color-picker.js'])
widget2 = Media(js=['text-editor.js'])
widget3 = Media(js=['text-editor.js', 'text-editor-extras.js', 'color-picker.js'])
merged = widget1 + widget2 + widget3
self.astertEqual(merged._js, ['text-editor.js', 'text-editor-extras.js', 'color-picker.js'])
3
View Complete Implementation : widgets.py
Copyright MIT License
Author : wuyue92tree
Copyright MIT License
Author : wuyue92tree
def _get_media(self):
return forms.Media(
css={
"all": ("admin/plugins/select2/select2.min.css",)
},
js=(
"admin/plugins/select2/select2.min.js",
))
3
View Complete Implementation : widgets.py
Copyright Apache License 2.0
Author : edisonlz
Copyright Apache License 2.0
Author : edisonlz
def _media(self):
js_files = ['django_extensions/js/jquery.bgiframe.min.js',
'django_extensions/js/jquery.ajaxQueue.js',
'django_extensions/js/jquery.autocomplete.js']
# Use a newer version of jquery if django version <= 1.5.x
# When removing this compatibility code also remove jquery-1.7.2.min.js file.
if int(django.get_version()[2]) <= 5:
js_files.insert(0, 'django_extensions/js/jquery-1.7.2.min.js')
return forms.Media(css={'all': ('django_extensions/css/jquery.autocomplete.css',)},
js=js_files)
3
View Complete Implementation : test_media.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_merge_css_three_way(self):
widget1 = Media(css={'screen': ['c.css'], 'all': ['d.css', 'e.css']})
widget2 = Media(css={'screen': ['a.css']})
widget3 = Media(css={'screen': ['a.css', 'b.css', 'c.css'], 'all': ['e.css']})
merged = widget1 + widget2
# c.css comes before a.css because widget1 + widget2 establishes this
# order.
self.astertEqual(merged._css, {'screen': ['c.css', 'a.css'], 'all': ['d.css', 'e.css']})
merged = merged + widget3
# widget3 contains an explicit ordering of c.css and a.css.
self.astertEqual(merged._css, {'screen': ['a.css', 'b.css', 'c.css'], 'all': ['d.css', 'e.css']})
3
View Complete Implementation : widgets.py
Copyright MIT License
Author : coogger
Copyright MIT License
Author : coogger
@property
def media(self):
return forms.Media(
css={"all": ("mdeditor/css/editormd.min.css",)},
js=("mdeditor/src/jquery.min.js", "mdeditor/editormd.min.js"),
)
3
View Complete Implementation : forms.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : raonyguimaraes
Copyright BSD 3-Clause "New" or "Revised" License
Author : raonyguimaraes
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,)}
)
@property
def media(self):
media = super(DjangoQLSearchMixin, self).media
if self.djangoql_completion:
js = [
'djangoql/js/lib/lexer.js',
'djangoql/js/completion.js',
]
if self.search_mode_toggle_enabled():
js.append('djangoql/js/completion_admin_toggle.js')
js.append('djangoql/js/completion_admin.js')
media += Media(
css={'': (
'djangoql/css/completion.css',
'djangoql/css/completion_admin.css',
)},
js=js,
)
return media
3
View Complete Implementation : widgets.py
Copyright MIT License
Author : rizwansoaib
Copyright MIT License
Author : rizwansoaib
@property
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])
3
View Complete Implementation : widgets.py
Copyright MIT License
Author : douglasmiranda
Copyright MIT License
Author : douglasmiranda
@property
def media(self):
kwargs = {}
if self.include_js:
kwargs['js'] = (
'django_fine_uploader/js.cookie.min.js',
'django_fine_uploader/fine-uploader.min.js',
)
if self.include_css:
kwargs['css'] = {
'all': ('django_fine_uploader/fine-uploader-gallery.min.css',)
}
return forms.Media(**kwargs)
3
View Complete Implementation : filter.py
Copyright MIT License
Author : silentsokolov
Copyright MIT License
Author : silentsokolov
@staticmethod
def _get_media():
js = [
'calendar.js',
'admin/DateTimeShortcuts.js',
]
css = [
'widgets.css',
]
return forms.Media(
js=['admin/js/%s' % url for url in js],
css={'all': ['admin/css/%s' % path for path in css]}
)
3
View Complete Implementation : widgets.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : linuxsoftware
Copyright BSD 3-Clause "New" or "Revised" License
Author : linuxsoftware
@property
def media(self):
media = super()._get_media()
media += Media(css={'all': [static("joyous/css/recurrence_admin.css")]},
js=[static("joyous/js/recurrence_admin.js")])
return media
3
View Complete Implementation : editable.py
Copyright MIT License
Author : Superbsco
Copyright MIT License
Author : Superbsco
def get_media(self, media):
if self.editable_need_fields:
try:
m = self.model_form.media
except:
m = Media()
media = media + m +\
self.vendor(
'xadmin.plugin.editable.js', 'xadmin.widget.editable.css')
return media
3
View Complete Implementation : helpers.py
Copyright Apache License 2.0
Author : drexly
Copyright Apache License 2.0
Author : drexly
def _media(self):
if 'collapse' in self.clastes:
extra = '' if settings.DEBUG else '.min'
js = ['vendor/jquery/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()
3
View Complete Implementation : widgets.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : wagtail
Copyright BSD 3-Clause "New" or "Revised" License
Author : wagtail
@property
def media(self):
return self.block_def.all_media() + Media(
js=['js/wagtail-react-streamfield.js'],
css={'all': [
'css/wagtail-react-streamfield.css',
]})
3
View Complete Implementation : test_dummy.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_django_html_escaping(self):
if self.backend_name == 'dummy':
self.skipTest("test doesn't apply to dummy backend")
clast TestForm(Form):
test_field = CharField()
media = Media(js=['my-script.js'])
form = TestForm()
template = self.engine.get_template('template_backends/django_escaping.html')
content = template.render({'media': media, 'test_form': form})
expected = '{}\n\n{}\n\n{}'.format(media, form, form['test_field'])
self.astertHTMLEqual(content, expected)
3
View Complete Implementation : helpers.py
Copyright Apache License 2.0
Author : edisonlz
Copyright Apache License 2.0
Author : edisonlz
def _media(self):
if 'collapse' in self.clastes:
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()
@property
def media(self):
css = {
'all': [
'django_admin_json_editor/bootstrap/css/bootstrap.min.css',
'django_admin_json_editor/fontawesome/css/font-awesome.min.css',
'django_admin_json_editor/style.css',
]
}
js = [
'django_admin_json_editor/jquery/jquery.min.js',
'django_admin_json_editor/bootstrap/js/bootstrap.min.js',
'django_admin_json_editor/jsoneditor/jsoneditor.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)
3
View Complete Implementation : helpers.py
Copyright MIT License
Author : bpgc-cte
Copyright MIT License
Author : bpgc-cte
@property
def media(self):
if 'collapse' in self.clastes:
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()
3
View Complete Implementation : test_media.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_media_deduplication(self):
# A deduplication test applied directly to a Media object, to confirm
# that the deduplication doesn't only happen at the point of merging
# two or more media objects.
media = Media(
css={'all': ('/path/to/css1', '/path/to/css1')},
js=('/path/to/js1', '/path/to/js1'),
)
self.astertEqual(str(media), """<link href="/path/to/css1" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="/path/to/js1"></script>""")
0
View Complete Implementation : aggregation.py
Copyright Apache License 2.0
Author : BeanWei
Copyright Apache License 2.0
Author : BeanWei
def get_media(self, media):
return media + Media(css={'screen': [self.static('xadmin/css/xadmin.plugin.aggregation.css'), ]})
@filter_hook
def get_media(self):
return forms.Media()
0
View Complete Implementation : dashboard.py
Copyright Apache License 2.0
Author : BeanWei
Copyright Apache License 2.0
Author : BeanWei
def media(self):
return forms.Media()
0
View Complete Implementation : widgets.py
Copyright MIT License
Author : bpgc-cte
Copyright MIT License
Author : bpgc-cte
@property
def media(self):
js = ["core.js", "SelectBox.js", "SelectFilter2.js"]
return forms.Media(js=["admin/js/%s" % path for path in js])
0
View Complete Implementation : widgets.py
Copyright MIT License
Author : bpgc-cte
Copyright MIT License
Author : bpgc-cte
@property
def media(self):
js = ["calendar.js", "admin/DateTimeShortcuts.js"]
return forms.Media(js=["admin/js/%s" % path for path in js])
0
View Complete Implementation : widgets.py
Copyright Apache License 2.0
Author : drexly
Copyright Apache License 2.0
Author : drexly
@property
def media(self):
js = ["core.js", "SelectBox.js", "SelectFilter2.js"]
return forms.Media(js=[static("admin/js/%s" % path) for path in js])
0
View Complete Implementation : widgets.py
Copyright Apache License 2.0
Author : drexly
Copyright Apache License 2.0
Author : drexly
@property
def media(self):
js = ["calendar.js", "admin/DateTimeShortcuts.js"]
return forms.Media(js=[static("admin/js/%s" % path) for path in js])
0
View Complete Implementation : dashboards.py
Copyright Apache License 2.0
Author : edisonlz
Copyright Apache License 2.0
Author : edisonlz
def _media(self):
return forms.Media()
0
View Complete Implementation : widgets.py
Copyright GNU General Public License v3.0
Author : gojuukaze
Copyright GNU General Public License v3.0
Author : gojuukaze
def _media(self):
css = {
'all': ('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css',
'froala_editor/css/froala_editor.min.css', 'froala_editor/css/froala_style.min.css',
'froala_editor/css/froala-django.css')
}
js = ('froala_editor/js/froala_editor.min.js', 'froala_editor/js/froala-django.js',)
if self.include_jquery:
js = ('https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js',) + js
if self.theme:
css['all'] += ('froala_editor/css/themes/' + self.theme + '.css',)
if self.language:
js += ('froala_editor/js/languages/' + self.language + '.js',)
for plugin in self.plugins:
js += ('froala_editor/js/plugins/' + plugin + '.min.js',)
if plugin in PLUGINS_WITH_CSS:
css['all'] += ('froala_editor/css/plugins/' + plugin + '.min.css',)
return Media(css=css, js=js)
0
View Complete Implementation : widgets.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : linuxsoftware
Copyright BSD 3-Clause "New" or "Revised" License
Author : linuxsoftware
@property
def media(self):
return Media(js=[static('joyous/js/vendor/moment-2.22.0.min.js'),
static("joyous/js/time12hr_admin.js")])
0
View Complete Implementation : widgets.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : linuxsoftware
Copyright BSD 3-Clause "New" or "Revised" License
Author : linuxsoftware
@property
def media(self):
return Media(css={'all': [static("joyous/css/recurrence_admin.css")]},
js=[static("joyous/js/recurrence_admin.js")])
0
View Complete Implementation : test_media.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_construction(self):
# Check construction of media objects
m = Media(
css={'all': ('path/to/css1', '/path/to/css2')},
js=('/path/to/js1', 'http://media.other.com/path/to/js2', 'https://secure.other.com/path/to/js3'),
)
self.astertEqual(
str(m),
"""<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet">
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>"""
)
self.astertEqual(
repr(m),
"Media(css={'all': ('path/to/css1', '/path/to/css2')}, "
"js=('/path/to/js1', 'http://media.other.com/path/to/js2', 'https://secure.other.com/path/to/js3'))"
)
clast Foo:
css = {
'all': ('path/to/css1', '/path/to/css2')
}
js = ('/path/to/js1', 'http://media.other.com/path/to/js2', 'https://secure.other.com/path/to/js3')
m3 = Media(Foo)
self.astertEqual(
str(m3),
"""<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet">
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>"""
)
# A widget can exist without a media definition
clast MyWidget(TextInput):
past
w = MyWidget()
self.astertEqual(str(w.media), '')
0
View Complete Implementation : test_media.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_media_property(self):
###############################################################
# Property-based media definitions
###############################################################
# Widget media can be defined as a property
clast MyWidget4(TextInput):
def _media(self):
return Media(css={'all': ('/some/path',)}, js=('/some/js',))
media = property(_media)
w4 = MyWidget4()
self.astertEqual(str(w4.media), """<link href="/some/path" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="/some/js"></script>""")
# Media properties can reference the media of their parents
clast MyWidget5(MyWidget4):
def _media(self):
return super().media + Media(css={'all': ('/other/path',)}, js=('/other/js',))
media = property(_media)
w5 = MyWidget5()
self.astertEqual(str(w5.media), """<link href="/some/path" type="text/css" media="all" rel="stylesheet">
<link href="/other/path" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="/some/js"></script>
<script type="text/javascript" src="/other/js"></script>""")
0
View Complete Implementation : test_media.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_media_property_parent_references(self):
# Media properties can reference the media of their parents,
# even if the parent media was defined using a clast
clast MyWidget1(TextInput):
clast Media:
css = {
'all': ('path/to/css1', '/path/to/css2')
}
js = ('/path/to/js1', 'http://media.other.com/path/to/js2', 'https://secure.other.com/path/to/js3')
clast MyWidget6(MyWidget1):
def _media(self):
return super().media + Media(css={'all': ('/other/path',)}, js=('/other/js',))
media = property(_media)
w6 = MyWidget6()
self.astertEqual(
str(w6.media),
"""<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet">
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet">
<link href="/other/path" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
<script type="text/javascript" src="/other/js"></script>"""
)
0
View Complete Implementation : test_media.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_media_inheritance_from_property(self):
# If a widget extends another but defines media, it extends the parents widget's media,
# even if the parent defined media using a property.
clast MyWidget1(TextInput):
clast Media:
css = {
'all': ('path/to/css1', '/path/to/css2')
}
js = ('/path/to/js1', 'http://media.other.com/path/to/js2', 'https://secure.other.com/path/to/js3')
clast MyWidget4(TextInput):
def _media(self):
return Media(css={'all': ('/some/path',)}, js=('/some/js',))
media = property(_media)
clast MyWidget9(MyWidget4):
clast Media:
css = {
'all': ('/other/path',)
}
js = ('/other/js',)
w9 = MyWidget9()
self.astertEqual(
str(w9.media),
"""<link href="/some/path" type="text/css" media="all" rel="stylesheet">
<link href="/other/path" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="/some/js"></script>
<script type="text/javascript" src="/other/js"></script>"""
)
# A widget can disable media inheritance by specifying 'extend=False'
clast MyWidget10(MyWidget1):
clast Media:
extend = False
css = {
'all': ('/path/to/css3', 'path/to/css1')
}
js = ('/path/to/js1', '/path/to/js4')
w10 = MyWidget10()
self.astertEqual(str(w10.media), """<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet">
<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="/path/to/js4"></script>""")
0
View Complete Implementation : test_media.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_html_safe(self):
media = Media(css={'all': ['/path/to/css']}, js=['/path/to/js'])
self.astertTrue(hasattr(Media, '__html__'))
self.astertEqual(str(media), media.__html__())
0
View Complete Implementation : test_media.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_construction(self):
# Check construction of media objects
m = Media(
css={'all': ('path/to/css1', '/path/to/css2')},
js=('/path/to/js1', 'http://media.other.com/path/to/js2', 'https://secure.other.com/path/to/js3'),
)
self.astertEqual(
str(m),
"""<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet">
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>"""
)
self.astertEqual(
repr(m),
"Media(css={'all': ['path/to/css1', '/path/to/css2']}, "
"js=['/path/to/js1', 'http://media.other.com/path/to/js2', 'https://secure.other.com/path/to/js3'])"
)
clast Foo:
css = {
'all': ('path/to/css1', '/path/to/css2')
}
js = ('/path/to/js1', 'http://media.other.com/path/to/js2', 'https://secure.other.com/path/to/js3')
m3 = Media(Foo)
self.astertEqual(
str(m3),
"""<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet">
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>"""
)
# A widget can exist without a media definition
clast MyWidget(TextInput):
past
w = MyWidget()
self.astertEqual(str(w.media), '')
0
View Complete Implementation : test_media.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_media_property_parent_references(self):
# Media properties can reference the media of their parents,
# even if the parent media was defined using a clast
clast MyWidget1(TextInput):
clast Media:
css = {
'all': ('path/to/css1', '/path/to/css2')
}
js = ('/path/to/js1', 'http://media.other.com/path/to/js2', 'https://secure.other.com/path/to/js3')
clast MyWidget6(MyWidget1):
def _media(self):
return super().media + Media(css={'all': ('/other/path',)}, js=('/other/js',))
media = property(_media)
w6 = MyWidget6()
self.astertEqual(
str(w6.media),
"""<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet">
<link href="/other/path" type="text/css" media="all" rel="stylesheet">
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="/other/js"></script>
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>"""
)
0
View Complete Implementation : widgets.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : openwisp
Copyright BSD 3-Clause "New" or "Revised" License
Author : openwisp
@property
def media(self):
css = _floorplan_css
return forms.Media(css=css)
0
View Complete Implementation : widgets.py
Copyright GNU Affero General Public License v3.0
Author : 82Flex
Copyright GNU Affero General Public License v3.0
Author : 82Flex
@property
def media(self):
return forms.Media(js=('suit/js/autosize.min.js',))