本文整理汇总了Python中django.forms.Media类的典型用法代码示例。如果您正苦于以下问题:Python Media类的具体用法?Python Media怎么用?Python Media使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Media类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_js_packages_with_pipeline_disabled
def test_js_packages_with_pipeline_disabled(self):
"""Testing PipelineFormMedia.js_packages with PIPELINE_ENABLED=False"""
class MyMedia(PipelineFormMedia):
js_packages = ('scripts1', 'scripts2')
js = ('extra1.js', 'extra2.js')
media = Media(MyMedia)
self.assertEqual(
MyMedia.js,
[
'extra1.js',
'extra2.js',
'pipeline/js/first.js',
'pipeline/js/second.js',
'pipeline/js/application.js',
])
self.assertEqual(MyMedia.js, media._js)
self.assertEqual(
media.render_js(),
[
'<script type="text/javascript" src="%s"></script>' % path
for path in (
'/static/extra1.js',
'/static/extra2.js',
'/static/pipeline/js/first.js',
'/static/pipeline/js/second.js',
'/static/pipeline/js/application.js',
)
])
示例2: __init__
def __init__(self, **kwargs):
self._css = {}
self._js = []
if kwargs:
Media.add_css(self, kwargs.get('css', None))
Media.add_js(self, kwargs.get('js', None))
示例3: _get_media
def _get_media(self):
""" hack for executing form's js code before widget's js """
from django.forms import Media
media = Media()
media.add_js(self.Media().js)
for field in self.fields.values():
media = media + field.widget.media
return media
示例4: vendor
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
示例5: __add__
def __add__(self, other):
# Performance improvement
if other is ImmutableMedia.empty_instance:
return other
# Fast copy
combined = Media()
combined._css = other._css.copy()
combined._js = other._js[:]
return combined
示例6: _media
def _media(self):
base = getattr(super(AdminCropdusterWidget, self), 'media', None)
media = Media(base) if base else Media()
media_url = reverse("cropduster-static", kwargs={"path": ""})
media.add_js([media_url + 'js/admin.cropduster.js',])
media.add_css({
'all': (
media_url + 'css/admin.cropduster.css',
),})
return media
示例7: test_merge_warning
def test_merge_warning(self):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
self.assertEqual(Media.merge([1, 2], [2, 1]), [1, 2])
self.assertEqual(
str(w[-1].message),
'Detected duplicate Media files in an opposite order:\n1\n2'
)
示例8: test_css_packages_with_pipeline_disabled
def test_css_packages_with_pipeline_disabled(self):
"""Testing PipelineFormMedia.css_packages with PIPELINE_ENABLED=False"""
class MyMedia(PipelineFormMedia):
css_packages = {
'all': ('styles1', 'styles2'),
'print': ('print',),
}
css = {
'all': ('extra1.css', 'extra2.css')
}
media = Media(MyMedia)
self.assertEqual(
MyMedia.css,
{
'all': [
'extra1.css',
'extra2.css',
'pipeline/css/first.css',
'pipeline/css/second.css',
'pipeline/css/unicode.css',
],
'print': ['pipeline/css/urls.css'],
})
self.assertEqual(MyMedia.css, media._css)
self.assertEqual(
list(media.render_css()),
[
'<link href="%s" type="text/css" media="all" '
'rel="stylesheet" />' % path
for path in (
'/static/extra1.css',
'/static/extra2.css',
'/static/pipeline/css/first.css',
'/static/pipeline/css/second.css',
'/static/pipeline/css/unicode.css',
)
] + [
'<link href="/static/pipeline/css/urls.css" type="text/css" '
'media="print" rel="stylesheet" />'
])
示例9: test_merge
def test_merge(self):
test_values = (
(([1, 2], [3, 4]), [1, 2, 3, 4]),
(([1, 2], [2, 3]), [1, 2, 3]),
(([2, 3], [1, 2]), [1, 2, 3]),
(([1, 3], [2, 3]), [1, 2, 3]),
(([1, 2], [1, 3]), [1, 2, 3]),
(([1, 2], [3, 2]), [1, 3, 2]),
)
for (list1, list2), expected in test_values:
with self.subTest(list1=list1, list2=list2):
self.assertEqual(Media.merge(list1, list2), expected)
示例10: test_merge
def test_merge(self):
test_values = (
(([1, 2], [3, 4]), [1, 3, 2, 4]),
(([1, 2], [2, 3]), [1, 2, 3]),
(([2, 3], [1, 2]), [1, 2, 3]),
(([1, 3], [2, 3]), [1, 2, 3]),
(([1, 2], [1, 3]), [1, 2, 3]),
(([1, 2], [3, 2]), [1, 3, 2]),
(([1, 2], [1, 2]), [1, 2]),
([[1, 2], [1, 3], [2, 3], [5, 7], [5, 6], [6, 7, 9], [8, 9]], [1, 5, 8, 2, 6, 3, 7, 9]),
((), []),
(([1, 2],), [1, 2]),
)
for lists, expected in test_values:
with self.subTest(lists=lists):
self.assertEqual(Media.merge(*lists), expected)
示例11: media
def media(self):
'上传前 预览图片'
media = Media()
media.add_js(['js/previrew-image-before-upload.js'])
# media.add_css({'screen': files})
return media
示例12: get_media
def get_media(self, *args, **kwargs):
media = super(AuditeurLibreApogeeAdmin, self).get_media(*args, **kwargs)
m = Media()
m.add_js(['paiement_etudiant/js/paiement_etudiant.js'])
return media+m
示例13: test_html_safe
def test_html_safe(self):
media = Media(css={'all': ['/path/to/css']}, js=['/path/to/js'])
self.assertTrue(hasattr(Media, '__html__'))
self.assertEqual(force_text(media), media.__html__())
示例14: _upgrade_jquery
def _upgrade_jquery(self, media):
# upgrade jquery and cms jquery UI
new_media = Media()
new_media.add_css(media._css)
new_jquery_version = static('cms_blogger/js/jquery-1.9.1.min.js')
new_jquery_ui_version = static('cms_blogger/js/jquery-ui.min.js')
# make sure all jquery namespaces point to the same jquery
jquery_namspace = static('cms_blogger/js/jQuery-patch.js')
django_jquery_urls = [static('admin/js/jquery.js'),
static('admin/js/jquery.min.js')]
django_collapse_js = [static('admin/js/collapse.js'),
static('admin/js/collapse.min.js')]
for js in media._js:
if js in django_jquery_urls:
new_media.add_js((new_jquery_version, ))
elif js in django_collapse_js:
new_media.add_js(
(static('cms_blogger/js/admin-collapse.js'), ))
elif js == static('admin/js/jquery.init.js'):
new_media.add_js((js, jquery_namspace))
elif js.startswith(static('cms/js/libs/jquery.ui.')):
new_media.add_js((new_jquery_ui_version, ))
else:
new_media.add_js((js, ))
return new_media
示例15: test_merge_warning
def test_merge_warning(self):
msg = 'Detected duplicate Media files in an opposite order:\n1\n2'
with self.assertWarnsMessage(RuntimeWarning, msg):
self.assertEqual(Media.merge([1, 2], [2, 1]), [1, 2])