def _make_media_for_variables(variables=None): media_obj = WidgetsMedia( js=( ( static("admin/js/core.js"), static("admin/js/admin/RelatedObjectLookups.js"), static("libs/jquery-2.1.1.min.js"), static("libs/bootstrap/js/bootstrap.min.js"), static("admin/js/custom.js"), ) ), css={ "all": ( "//fonts.googleapis.com/css?family=Open+Sans:400,300", static("libs/bootstrap/css/bootstrap.css"), static("libs/ace/css/ace.min.css"), static("admin/css/custom.css"), ) }, ) media_obj.add_js( ( reverse("admin:jsi18n"), static("admin/js/SmartSnippetLib.js"), static("admin/js/jquery.init.js"), static("admin/js/default.jQuery.init.js"), ) ) variables_media(media_obj, variables) return media_obj
def grakon_media(request): media = Media() media.add_css({ 'all': ( 'libs/yaml/base.css', 'css/hlist.css', 'libs/jquery-ui/jquery-ui.css', 'css/layout.css', 'css/typography.css', 'css/style.css', 'libs/tipsy/tipsy.css', 'css/julia_style.css', ), }) if settings.DEBUG: js = ('libs/jquery.js', 'libs/jquery-ui/jquery-ui.js') else: js = ('https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js') js += ( 'libs/underscore.js', 'libs/tipsy/jquery.tipsy.js', 'libs/backbone.js', 'http://userapi.com/js/api/openapi.js?47', # VKontakte 'http://loginza.ru/js/widget.js', 'js/main.js', ) media.add_js(js) return {'grakon_media': media}
def progress_bar_media(): """ progress_bar_media simple tag return rendered script tag for javascript used by progress_bar """ m = Media(js=["http://code.jquery.com/jquery-1.8.3.min.js", "js/progress_bar.js"]) return m.render()
def _get_media(self): """ Provide a description of all media required to render the widgets on this form """ media = Media() for field in self.fields.values(): media = media + field.widget.media media._js = ['cms/js/libs/jquery.min.js'] + media._js return media
def progress_bar_media(): """ progress_bar_media simple tag return rendered script tag for javascript used by progress_bar """ js = ["js/progress_bar.js",] if PROGRESSBARUPLOAD_INCLUDE_JQUERY: js.append("http://code.jquery.com/jquery-1.8.3.min.js") m = Media(js=js) return m.render()
def uni_form_media(request): media = Media() media.add_css({ 'all': ( 'libs/uni-form/uni-form.css', 'libs/uni-form/default.uni-form.css' ) }) media.add_js(( 'libs/uni-form/uni-form.jquery.js', )) return {'uni_form_media': media}
def media(self): media = Media() # Add the appropriate dialog media; this will depend on which # client-side dialog library is chosen. media.add_js(["js/jquery.min.js", "js/jquery-ui.min.js"]) # Add the dialogs scripts. media.add_js(["js/dialogs/jquery.dialogs.js", "js/dialogs/dialogs.js"]) for pane in self.panes.values(): media = media + pane.media return media
def media_files(request): media = Media() media.add_css({ 'all': ( 'libs/yaml/base.css', 'libs/jquery-ui/jquery-ui.css', 'libs/crispy-forms/uni-form.css', 'libs/crispy-forms/default.uni-form.css', 'libs/chosen/chosen.css', 'libs/tipsy/tipsy.css', 'libs/jTour/jquery-jtour-2.0.2.css', 'css/hlist.css', 'css/tabs.css', 'css/gray-theme.css', 'css/typography.css', 'css/deco.css', 'css/style.css', ), }) if settings.DEBUG: js = ( 'libs/jquery.js', 'libs/jquery-ui/jquery-ui.js', 'libs/openapi.js', ) else: js = ( 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js', 'http://userapi.com/js/api/openapi.js?49', # VKontakte ) js += ( 'libs/underscore.js', 'libs/json2.js', 'libs/backbone.js', 'libs/chosen/chosen.jquery.min.js', 'libs/jquery.placeholder.min.js', 'libs/jquery.autosize.js', reverse('code_data') if settings.DEBUG else 'js/code_data.js', 'js/main.js', 'js/resources.js', 'js/resources_form.js', 'js/comments.js', 'js/locations.js', ) media.add_js(js) bottom_media = Media() bottom_media.add_js(( 'libs/tipsy/jquery.tipsy.js', 'libs/mustache.js', 'libs/crispy-forms/uni-form.jquery.js', # TODO: currently doesn't work 'libs/jTour/jquery-jtour-2.0.2.min.js', 'js/tour.js', )) return {'media_files': media, 'bottom_media_files': bottom_media}
def progress_bar_media(): """ progress_bar_media simple tag return rendered script tag for javascript used by progress_bar """ if PROGRESSBARUPLOAD_INCLUDE_JQUERY: # js = ["http://code.jquery.com/jquery-1.8.3.min.js",] js = ["ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"] else: js = [] js.append("js/progress_bar.js") m = Media(js=js) return m.render()
def media(self): js = settings.CONFIG['js'] js += [ 'admin/js/vendor/jquery/jquery.min.js', 'admin/js/jquery.init.js', reverse(self.INIT_URL) ] return Media(js=js)
def media(self): """Media defined as a dynamic property instead of an inner class.""" media = super(JqueryMediaMixin, self).media js = [] if JQUERY_URL: js.append(JQUERY_URL) elif JQUERY_URL is not False: vendor = "vendor/jquery/" extra = "" if settings.DEBUG else ".min" jquery_paths = [ "{}jquery{}.js".format(vendor, extra), "jquery.init.js", ] if USE_DJANGO_JQUERY: jquery_paths = [ "admin/js/{}".format(path) for path in jquery_paths ] js.extend(jquery_paths) media += Media(js=js) return media
def get_context_data(self, **kwargs): kwargs["VariantType"] = VariantType kwargs["hostpart"] = "{}://{}".format( self.request.scheme, self.request.get_host() ) kwargs.setdefault("media", Media()) return super().get_context_data(**kwargs)
def media(self): """Media defined as a dynamic property instead of an inner class.""" media = super(ChainedSelect, self).media js = ['smart-selects/admin/js/chainedfk.js', 'smart-selects/admin/js/bindfields.js'] media += Media(js=js) return media
def _get_media(self): # All the forms on a FormSet are the same, so you only need to # interrogate the first form for media. if self.forms: return self.forms[0].media else: return Media()
def media(self): media = super().media + Media( js=get_theme_files(settings.SUMMERNOTE_THEME, 'base_js'), css={ 'all': get_theme_files(settings.SUMMERNOTE_THEME, 'base_css'), }) return media
def media(self): """Media defined as a dynamic property instead of an inner class.""" media = super(JqueryMediaMixin, self).media js = [] if JQUERY_URL: js.append(JQUERY_URL) elif JQUERY_URL is not False: vendor = '' if django.VERSION < (1, 9, 0) else 'vendor/jquery/' extra = '' if settings.DEBUG else '.min' jquery_paths = [ '{}jquery{}.js'.format(vendor, extra), 'jquery.init.js', ] if USE_DJANGO_JQUERY: jquery_paths = [ 'admin/js/{}'.format(path) for path in jquery_paths ] js.extend(jquery_paths) media += Media(js=js) return media
def get_media(self): try: m = self.form_obj.media except: m = Media() return super(ModelFormAdminView, self).get_media() + m + \ self.vendor('xadmin.page.form.js', 'xadmin.form.css')
def progress_bar_media(): """ progress_bar_media simple tag return rendered script tag for javascript used by progress_bar """ include_jquery = getattr(settings, 'PROGRESSBARUPLOAD_INCLUDE_JQUERY', False) if include_jquery: js = ["//code.jquery.com/jquery-1.12.0.min.js"] else: js = [] js.append("js/progress_bar.js") m = Media(js=js) return m.render()
def _get_media(self): """ Media for a multiwidget is the combination of all media of the subwidgets. """ media = Media() media = media + self.data_widget.media return media
def get_plugin_media(self, request, context, plugin): if 'GOOGLE_MAPS_API_KEY' in context: key = context['GOOGLE_MAPS_API_KEY'] else: key = GOOGLE_MAPS_API_KEY return Media(js=( 'http://maps.google.com/maps?file=api&v=2&key=%s&hl=%s' % (key, request.LANGUAGE_CODE), ))
def _get_media(self): media = Media() for field in self.fields.values(): media = media + field.widget.media for formset in self.inlines: media = media + formset( queryset=formset.model.objects.none()).media return media
def _get_media(self): """ Provide a description of all media required to render the widgets on this form """ media = Media() for field in self.fields.values(): media = media + field.widget.media return media
def admin_media(self): css = { 'all': ( 'filesoup/widgets/jfu/custom/css/admin.css', ) } return self.media['js'] + Media(css=css)
def media_files(request): media = Media() media.add_css( { "all": ( "libs/yaml/base.css", "libs/jquery-ui/jquery-ui.css", "libs/crispy-forms/uni-form.css", "libs/crispy-forms/default.uni-form.css", "libs/chosen/chosen.css", "libs/tipsy/tipsy.css", "css/hlist.css", "css/layout.css", "css/typography.css", "css/style.css", "css/julia_style.css", ) } ) if settings.DEBUG: js = ("libs/jquery.js", "libs/jquery-ui/jquery-ui.js", "libs/openapi.js") else: js = ( "https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js", "https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js", "http://userapi.com/js/api/openapi.js?49", # VKontakte ) js += ( "libs/underscore.js", "libs/tipsy/jquery.tipsy.js", "libs/json2.js", "libs/backbone.js", "libs/chosen/chosen.jquery.min.js", "libs/jquery.placeholder.min.js", "libs/jquery.autosize.js", reverse("code_data") if settings.DEBUG else "js/code_data.js", "js/main.js", "js/comments.js", "js/locations.js", ) media.add_js(js) bottom_media = Media() bottom_media.add_js( ( "libs/tipsy/jquery.tipsy.js", "libs/mustache.js", "libs/crispy-forms/uni-form.jquery.js", # TODO: currently doesn't work #'libs/jTour/jquery-jtour-2.0.2.min.js', #'js/tour.js', ) ) return {"media_files": media, "bottom_media_files": bottom_media}
def _get_media(self): """ Media for a multiwidget is the combination of all media of the subwidgets """ media = Media() for w in self.widgets: media = media + w.media return media
def get_media(self, request, context): from cms.plugins.utils import get_plugin_media media_classes = [ get_plugin_media(request, context, plugin) for plugin in self.get_plugins() ] if media_classes: return reduce(operator.add, media_classes) return Media()
def test_basic(self): class C1(metaclass=MediaDefiningClass): class Media: js = ['c1.js'] css = { 'all': ['c1.css'], } class C2(C1): class Media: js = ['c2.js'] @property def media(self): base = super().media return get_class_media(base, self) class C3(C1): class Media: js = ['c3.js'] extend = ['css'] @property def media(self): base = super().media return get_class_media(base, self) class C4(C1): class Media: js = ['c4.js'] extend = False @property def media(self): base = super().media return get_class_media(base, self) inst = C2() self.assertIn('c1.js', inst.media._js) self.assertIn('c2.js', inst.media._js) self.assertIn('c1.css', inst.media._css['all']) inst = C3() self.assertIn('c3.js', inst.media._js) self.assertNotIn('c1.js', inst.media._js) self.assertIn('c1.css', inst.media._css['all']) inst = C4() self.assertIn('c4.js', inst.media._js) self.assertNotIn('c1.js', inst.media._js) self.assertNotIn('all', inst.media._css) class C5: pass base = Media() self.assertIs(get_class_media(base, C5()), base)
def media(self): extra = '' if django_settings.DEBUG else '.min' js = [ 'admin/js/vendor/jquery/jquery%s.js' % extra, 'admin/js/jquery.init.js' ] js.extend(settings.CONFIG['js']) js.append(reverse(self.INIT_URL)) return Media(js=js, css=settings.CONFIG['css'])
def progress_bar_media(): """ progress_bar_media simple tag return rendered script tag for javascript used by progress_bar """ if settings.PROGRESSBARUPLOAD_INCLUDE_JQUERY: js = [ "http://code.jquery.com/jquery-1.8.3.min.js", ] else: js = [] if settings.PROGRESSBARUPLOAD_AJAX: js.append("js/progress_bar_ajax.js") else: js.append("js/progress_bar.js") m = Media(js=js) return m.render()
def __init__(self, attrs=None): self.Media.js = self.backends[settings.BACKEND]['js'] self.Media.css['all'] = Media.merge( self.backends[settings.BACKEND]['css'], self.Media.css['all']) widgets = ( forms.TextInput(), forms.TextInput(), ) super(GeopositionWidget, self).__init__(widgets, attrs)
def prettyjson_setup(jquery=True): widget = PrettyJSONWidget() extra = '' if settings.DEBUG else '.min' if jquery: media = Media(js=( 'admin/js/vendor/jquery/jquery%s.js' % extra, 'admin/js/jquery.init.js', )) + widget.media else: media = widget.media return mark_safe(str(media))
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
def _get_media(self): if self.media_cache is None: media = Media() instances = self.__dict__['content_type_instances'] for contents in instances.values(): for content in contents: if hasattr(content, 'media'): media = media + content.media self.media_cache = media return self.media_cache
def media(self): extra = '' if settings.DEBUG else '.min' css = {'all': ('singleurlcrud/css/crud.css', )} js = self.js from django.forms.widgets import Media media = Media(js=['%s' % url for url in js], css=css) op = self.get_op() if op == "add" or op == "edit": form = self.get_form(self.get_form_class()) if hasattr(form, 'media'): media += form.media return media
def media(self): """Media defined as a dynamic property instead of an inner class.""" media = super(ChainedSelectMultiple, self).media js = ['smart-selects/admin/js/chainedm2m.js', 'smart-selects/admin/js/bindfields.js'] if self.horizontal: # For horizontal mode add django filter horizontal javascript code js.extend(["admin/js/core.js", "admin/js/SelectBox.js", "admin/js/SelectFilter2.js"]) media += Media(js=js) return media
def media(self): # get the default js and css media media = super().media # add custom js new_js = media._js # the js must be added before 'pagedown_init.js'; this is usually the last js file loaded new_js.insert(len(new_js) - 1, "js/pagedown_iguana_markdown.js") # add custom css new_css = {"all": ("css/pagedown.css", )} return Media(js=tuple(new_js), css=new_css)
def get_theme_media(theme): """ Return a media instance pointing to the css file of the requested theme. Raise an error if the theme cannot be recognised. """ path = 'theme/{}.css'.format(theme) if not os.path.exists(os.path.join(CODEMIRROR_DIR, path)): raise ValueError('Unknown theme: {!s}'.format(theme)) path = os.path.join('django-mirror/codemirror', path) return Media(css={'all': [path]})
def _get_view_media(self): """ Gather view-level media assets """ try: css = self.Media.css except AttributeError: css = {} try: js = self.Media.js except AttributeError: js = [] return Media(css=css, js=js)
class JSHeadPlugin(BaseAdminPlugin): """Move o arquivo js para o head do templates Necessário em casos que o js precisa ser carregado antes """ render_js_on_head = [] def __init__(self, admin_view): super(JSHeadPlugin, self).__init__(admin_view) self._template = self.admin_view.base_template self._media = Media() def _init(self): """Configurações do plugin depois que foi marcado como ativo""" self.admin_view.base_template = 'openvpn/js_head_base.html' def init_request(self, *args, **kwargs): if len(self.render_js_on_head) > 0: self._init() return True return False def get_context(self, context): context['js_head_base'] = self._template context['js_head_media'] = self._media return context def get_media(self, media): media_js = media._js to_remove = [] for js in media._js: if js in self.render_js_on_head: self._media.add_js((js,)) to_remove.append(js) for js in to_remove: try: media_js.remove(js) except ValueError: pass return media
def _resolve_context(self, context): context = self.__resolve_context(context) media = context.get('media', None) if media: ignore_jss = [ 'admin/js/vendor/jquery/jquery{}.js'.format( '' if settings.DEBUG else '.min'), 'admin/js/jquery.init.js' ] jss = [js for js in media._js if js not in ignore_jss] if len(jss) != len(media._js): media = Media(js=jss, css=media._css) context['media'] = media return context
class JSHeadPlugin(BaseAdminPlugin): """Move o arquivo js para o head do templates Necessário em casos que o js precisa ser carregado antes """ render_js_on_head = [] def __init__(self, admin_view): super(JSHeadPlugin, self).__init__(admin_view) self._template = self.admin_view.base_template self._media = Media() def _init(self): """Configurações do plugin depois que foi marcado como ativo""" self.admin_view.base_template = 'openvpn/js_head_base.html' def init_request(self, *args, **kwargs): if len(self.render_js_on_head) > 0: self._init() return True return False def get_context(self, context): context['js_head_base'] = self._template context['js_head_media'] = self._media return context def get_media(self, media): media_js = media._js to_remove = [] for js in media._js: if js in self.render_js_on_head: self._media.add_js((js, )) to_remove.append(js) for js in to_remove: try: media_js.remove(js) except ValueError: pass return media
def test_media_monkey_patch(self): media = Media() media.add_js(( '/admin/test1.js', 'admin/test2.js', 'http://example.com/admin/test3.js', '//example.com/admin/test3.js' )) media.add_css({ 'all': ( '/admin/test1.css', 'admin/test2.css', 'http://example.com/admin/test2.css', '//example.com/admin/test2.css' ) }) no_monkey = """ <link href="/admin/test1.css" type="text/css" media="all" rel="stylesheet" /> <link href="/static/admin/test2.css" type="text/css" media="all" rel="stylesheet" /> <link href="http://example.com/admin/test2.css" type="text/css" media="all" rel="stylesheet" /> <link href="//example.com/admin/test2.css" type="text/css" media="all" rel="stylesheet" /> <script type="text/javascript" src="/admin/test1.js"></script> <script type="text/javascript" src="/static/admin/test2.js"></script> <script type="text/javascript" src="http://example.com/admin/test3.js"></script> <script type="text/javascript" src="//example.com/admin/test3.js"></script> """.strip() monkey = """ <link href="/admin/test1.css" type="text/css" media="all" rel="stylesheet" /> <link href="http://this.com/static/admin/test2.css" type="text/css" media="all" rel="stylesheet" /> <link href="http://example.com/admin/test2.css" type="text/css" media="all" rel="stylesheet" /> <link href="//example.com/admin/test2.css" type="text/css" media="all" rel="stylesheet" /> <script type="text/javascript" src="/admin/test1.js"></script> <script type="text/javascript" src="http://this.com/static/admin/test2.js"></script> <script type="text/javascript" src="http://example.com/admin/test3.js"></script> <script type="text/javascript" src="//example.com/admin/test3.js"></script> """.strip() with self.settings(STATIC_URL='/static/'): self.assertEqual(media.render(), no_monkey) with self.settings( STATIC_URL=CloudFrontURLs('http://notthis.com/', patterns={ '^admin': 'http://this.com/static/' }) ): self.assertEqual(media.render(), monkey)
def media(self): if not USE_BOOTSTRAP_ACE: media_obj = super(SmartSnippetPlugin, self).media else: media_obj = WidgetsMedia( js=(( static('admin/js/core.js'), static('admin/js/admin/RelatedObjectLookups.js'), static('libs/jquery-2.1.1.min.js'), static('libs/bootstrap/js/bootstrap.min.js'), static('admin/js/custom.js'), ) ), css={ 'all': ( '//fonts.googleapis.com/css?family=Open+Sans:400,300', static('libs/bootstrap/css/bootstrap.css'), static('libs/ace/css/ace.min.css'), static('admin/css/custom.css'), ) } ) media_obj.add_js( (reverse('admin:jsi18n'), static('admin/js/SmartSnippetLib.js'), static('admin/js/jquery.init.js'), static('admin/js/default.jQuery.init.js'))) if not USE_BOOTSTRAP_ACE: media_obj.add_css({ 'all': ( static('admin/css/forms.css'), static('admin/css/base.css'), static('css/tipTip.css'), static('admin/css/snippet_plugin_default.css'), ) }) media_obj.add_js(( static('js/jquery.tipTip.minified.js'), static('admin/js/snippet_plugin_default.js'), ) ) return media_obj
def __init__(self, admin_view): super(JSHeadPlugin, self).__init__(admin_view) self._template = self.admin_view.base_template self._media = Media()