我们从Python开源项目中,提取了以下17个代码示例,用于说明如何使用django.utils.html.escapejs()。
def get_login_url(self, request, **kwargs): method = kwargs.pop('method', self.get_method()) if method == 'js_sdk': next = "'%s'" % escapejs(kwargs.get('next') or '') process = "'%s'" % escapejs( kwargs.get('process') or AuthProcess.LOGIN) action = "'%s'" % escapejs( kwargs.get('action') or AuthAction.AUTHENTICATE) js = "allauth.facebook.login(%s, %s, %s)" % (next, action, process) ret = "javascript:%s" % (urlquote(js),) else: assert method == 'oauth2' ret = super(FacebookProvider, self).get_login_url(request, **kwargs) return ret
def get_login_url(self, request, **kwargs): next_url = "'%s'" % escapejs(kwargs.get('next') or '') process = "'%s'" % escapejs(kwargs.get('process') or 'login') return 'javascript:allauth.persona.login(%s, %s)' % (next_url, process)
def environment(**options): env = Environment(**options) env.install_gettext_translations(translation, newstyle=True) from .templatetags.borgcube import get_url, field_name, compression_name, summarize_archive, job_outcome, format_timedelta, json, describe_recurrence from django.utils.html import escapejs from django.template.defaultfilters import linebreaks, linebreaksbr, yesno env.filters.update({ 'get_url': get_url, # TODO: remove 'field_name': field_name, 'compression_name': compression_name, 'summarize_archive': summarize_archive, 'job_outcome': job_outcome, 'format_timedelta': format_timedelta, 'json': json, 'describe_recurrence': describe_recurrence, 'escapejs': escapejs, 'linebreaks': linebreaks, 'linebreaksbr': linebreaksbr, 'yesno': yesno, }) hook.borgcube_web_jinja_env(env=env) return env
def render_tag(self, context, **kwargs): try: from django.utils.html import escapejs except ImportError: from django.utils.text import javascript_quote as escapejs rendered = self.nodelist.render(context) return u"'%s'" % escapejs(rendered.strip())
def response_add(self, request, obj, post_url_continue=None): """ Determines the HttpResponse for the add_view stage. """ opts = obj._meta pk_value = obj._get_pk_val() preserved_filters = self.get_preserved_filters(request) msg_dict = {'name': force_text(opts.verbose_name), 'obj': force_text(obj)} # Here, we distinguish between different save types by checking for # the presence of keys in request.POST. if IS_POPUP_VAR in request.POST: return SimpleTemplateResponse('admin/popup_response.html', { 'pk_value': escape(pk_value), 'obj': escapejs(obj) }) elif "_continue" in request.POST: msg = _('The %(name)s "%(obj)s" was added successfully. You may edit it again below.') % msg_dict self.message_user(request, msg, messages.SUCCESS) if post_url_continue is None: post_url_continue = reverse('admin:%s_%s_change' % (opts.app_label, opts.model_name), args=(pk_value,), current_app=self.admin_site.name) post_url_continue = add_preserved_filters({'preserved_filters': preserved_filters, 'opts': opts}, post_url_continue) return HttpResponseRedirect(post_url_continue) elif "_addanother" in request.POST: msg = _('The %(name)s "%(obj)s" was added successfully. You may add another %(name)s below.') % msg_dict self.message_user(request, msg, messages.SUCCESS) redirect_url = request.path redirect_url = add_preserved_filters({'preserved_filters': preserved_filters, 'opts': opts}, redirect_url) return HttpResponseRedirect(redirect_url) else: msg = _('The %(name)s "%(obj)s" was added successfully.') % msg_dict self.message_user(request, msg, messages.SUCCESS) return self.response_post_save_add(request, obj)
def get_login_url(self, request, **kwargs): method = kwargs.pop('method', self.get_method()) if method == 'js_sdk': next = "'%s'" % escapejs(kwargs.get('next') or '') process = "'%s'" % escapejs( kwargs.get('process') or AuthProcess.LOGIN) action = "'%s'" % escapejs( kwargs.get('action') or AuthAction.AUTHENTICATE) ret = "javascript:allauth.facebook.login(%s, %s, %s)" \ % (next, action, process) else: assert method == 'oauth2' ret = super(FacebookProvider, self).get_login_url(request, **kwargs) return ret
def response_add(self, request, obj, post_url_continue=None): """ Determines the HttpResponse for the add_view stage. """ opts = obj._meta pk_value = obj._get_pk_val() preserved_filters = self.get_preserved_filters(request) msg_dict = {'name': force_text(opts.verbose_name), 'obj': force_text(obj)} # Here, we distinguish between different save types by checking for # the presence of keys in request.POST. if IS_POPUP_VAR in request.POST: to_field = request.POST.get(TO_FIELD_VAR) if to_field: attr = str(to_field) else: attr = obj._meta.pk.attname value = obj.serializable_value(attr) return SimpleTemplateResponse('admin/popup_response.html', { 'pk_value': escape(pk_value), # for possible backwards-compatibility 'value': escape(value), 'obj': escapejs(obj) }) elif "_continue" in request.POST: msg = _('The %(name)s "%(obj)s" was added successfully. You may edit it again below.') % msg_dict self.message_user(request, msg, messages.SUCCESS) if post_url_continue is None: post_url_continue = reverse('admin:%s_%s_change' % (opts.app_label, opts.model_name), args=(quote(pk_value),), current_app=self.admin_site.name) post_url_continue = add_preserved_filters( {'preserved_filters': preserved_filters, 'opts': opts}, post_url_continue ) return HttpResponseRedirect(post_url_continue) elif "_addanother" in request.POST: msg = _('The %(name)s "%(obj)s" was added successfully. You may add another %(name)s below.') % msg_dict self.message_user(request, msg, messages.SUCCESS) redirect_url = request.path redirect_url = add_preserved_filters({'preserved_filters': preserved_filters, 'opts': opts}, redirect_url) return HttpResponseRedirect(redirect_url) else: msg = _('The %(name)s "%(obj)s" was added successfully.') % msg_dict self.message_user(request, msg, messages.SUCCESS) return self.response_post_save_add(request, obj)
def response_change(self, request, obj): """ Determines the HttpResponse for the change_view stage. """ if IS_POPUP_VAR in request.POST: to_field = request.POST.get(TO_FIELD_VAR) attr = str(to_field) if to_field else obj._meta.pk.attname # Retrieve the `object_id` from the resolved pattern arguments. value = request.resolver_match.args[0] new_value = obj.serializable_value(attr) return SimpleTemplateResponse('admin/popup_response.html', { 'action': 'change', 'value': escape(value), 'obj': escapejs(obj), 'new_value': escape(new_value), }) opts = self.model._meta pk_value = obj._get_pk_val() preserved_filters = self.get_preserved_filters(request) msg_dict = {'name': force_text(opts.verbose_name), 'obj': force_text(obj)} if "_continue" in request.POST: msg = _('The %(name)s "%(obj)s" was changed successfully. You may edit it again below.') % msg_dict self.message_user(request, msg, messages.SUCCESS) redirect_url = request.path redirect_url = add_preserved_filters({'preserved_filters': preserved_filters, 'opts': opts}, redirect_url) return HttpResponseRedirect(redirect_url) elif "_saveasnew" in request.POST: msg = _('The %(name)s "%(obj)s" was added successfully. You may edit it again below.') % msg_dict self.message_user(request, msg, messages.SUCCESS) redirect_url = reverse('admin:%s_%s_change' % (opts.app_label, opts.model_name), args=(pk_value,), current_app=self.admin_site.name) redirect_url = add_preserved_filters({'preserved_filters': preserved_filters, 'opts': opts}, redirect_url) return HttpResponseRedirect(redirect_url) elif "_addanother" in request.POST: msg = _('The %(name)s "%(obj)s" was changed successfully. You may add another %(name)s below.') % msg_dict self.message_user(request, msg, messages.SUCCESS) redirect_url = reverse('admin:%s_%s_add' % (opts.app_label, opts.model_name), current_app=self.admin_site.name) redirect_url = add_preserved_filters({'preserved_filters': preserved_filters, 'opts': opts}, redirect_url) return HttpResponseRedirect(redirect_url) else: msg = _('The %(name)s "%(obj)s" was changed successfully.') % msg_dict self.message_user(request, msg, messages.SUCCESS) return self.response_post_save_change(request, obj)