我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用django.forms.widgets.Media()。
def patch(): from django.forms import forms, formsets, util, widgets # Add __html__ methods to these classes: classes = [ forms.BaseForm, forms.BoundField, formsets.BaseFormSet, util.ErrorDict, util.ErrorList, widgets.Media, widgets.RadioFieldRenderer, ] try: classes.append(widgets.RadioChoiceInput) except AttributeError: classes.append(widgets.RadioInput) for cls in classes: if not hasattr(cls, '__html__'): cls.__html__ = __html__
def __init__(self, admin_view): super(JSHeadPlugin, self).__init__(admin_view) self._template = self.admin_view.base_template self._media = Media()
def 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 _add_media(self, model_admin): if not hasattr(model_admin, 'Media'): raise ImproperlyConfigured('Add empty Media class to %s. Sorry about this bug.' % model_admin) def _get_media(obj): return Media(media=getattr(obj, 'Media', None)) media = _get_media(model_admin) + _get_media(AutocompleteFilter) + _get_media(self) for name in MEDIA_TYPES: setattr(model_admin.Media, name, getattr(media, "_" + name))
def media(self): js = ["core.js", "SelectBox.js", "SelectFilter2.js"] return forms.Media(js=[static("admin/js/%s" % path) for path in js])
def media(self): js = ["calendar.js", "admin/DateTimeShortcuts.js"] return forms.Media(js=[static("admin/js/%s" % path) for path in js])
def media(self): media = Media(js=[static('admin/js/related-widget-wrapper.js')]) return self.widget.media + media
def media(self): media = Media(js=['admin/js/related-widget-wrapper.js']) return self.widget.media + media
def _media(self): return widgets.Media( css={ 'all': ('eonasdan-bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.css',) }, js=[ "moment/moment.js", "eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js", ] )
def get_media_assets(self): media = Media() media.add_js(['extra.js']) return media
def _get_common_media(self): config = getattr(settings, 'ARCTIC_COMMON_MEDIA_ASSETS', []) media = Media() if 'css' in config: media.add_css(config['css']) if 'js' in config: media.add_js(config['js']) return media
def get_media_assets(self): """ Allows to define additional media for view """ return Media()
def _get_view_media(self): """ Gather view-level media assets """ media = Media() try: media.add_css(self.Media.css) except AttributeError: pass try: media.add_js(self.Media.js) except AttributeError: pass return media
def get_request(self, *args, **kwargs): request = super(PluginsTestBaseCase, self).get_request(*args, **kwargs) request.placeholder_media = Media() request.toolbar = CMSToolbar(request) return request
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))