python类quote()的实例源码

models.py 文件源码 项目:django-open-lecture 作者: DmLitov4 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def get_admin_url(self):
        """
        Returns the admin URL to edit the object represented by this log entry.
        """
        if self.content_type and self.object_id:
            url_name = 'admin:%s_%s_change' % (self.content_type.app_label, self.content_type.model)
            try:
                return reverse(url_name, args=(quote(self.object_id),))
            except NoReverseMatch:
                pass
        return None
admin_urls.py 文件源码 项目:django-open-lecture 作者: DmLitov4 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def admin_urlquote(value):
    return quote(value)
admin_foreign_key_link.py 文件源码 项目:ToolsLibrary 作者: albertmenglongli 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def admin_foreign_key_link(field):
    def decorator(func):
        @wraps(func)
        def wrapper(self, obj):
            result = func(self, obj)
            if result:
                # if function return something, we do nothing and just return;
                return result

            # most of the cases will trigger this ELSE branch;
            from django.template import Context, Template
            from django.core.urlresolvers import reverse
            from django.contrib.admin.utils import quote

            assert hasattr(obj, field)

            _field_attr = getattr(obj, field, None)
            if _field_attr is None:
                _django_template = Template('')
                _context = Context()
            else:
                _description = '{{name}} {{id}}'
                _str_template = '<a href="{{url}}">%s</a>' % _description
                _django_template = Template(_str_template)
                _pk_value = _field_attr.id
                url = reverse(
                    'admin:%s_%s_change' % (_field_attr.__class__._meta.app_label,
                                            _field_attr.__class__.__name__.lower()),
                    args=(quote(_pk_value),),
                    current_app=self.admin_site.name,
                    )
                _context = Context({'url': url,
                                    'name': _field_attr.__class__._meta.verbose_name.title(),
                                    'id': _pk_value
                                    })
            return _django_template.render(_context)

        return wrapper

    return decorator
wagtail_hooks.py 文件源码 项目:moore 作者: UTNkar 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def approve_button(self, pk, classnames_add=None, classnames_exclude=None):
        if classnames_add is None:
            classnames_add = []
        if classnames_exclude is None:
            classnames_exclude = []
        classnames = self.edit_button_classnames + classnames_add
        cn = self.finalise_classname(classnames, classnames_exclude)
        return {
            'url': self.url_helper.get_action_url('approve', quote(pk)),
            'label': _('Approve'),
            'classname': cn,
            'title': _('Approve applicants for %s') % self.verbose_name,
        }
wagtail_hooks.py 文件源码 项目:moore 作者: UTNkar 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def appoint_button(self, pk, classnames_add=None, classnames_exclude=None):
        if classnames_add is None:
            classnames_add = []
        if classnames_exclude is None:
            classnames_exclude = []
        classnames = self.edit_button_classnames + classnames_add
        cn = self.finalise_classname(classnames, classnames_exclude)
        return {
            'url': self.url_helper.get_action_url('appoint', quote(pk)),
            'label': _('Appoint'),
            'classname': cn,
            'title': _('Appoint member to %s') % self.verbose_name,
        }
wagtail_hooks.py 文件源码 项目:moore 作者: UTNkar 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def get_buttons_for_obj(self, obj, exclude=None, classnames_add=None,
                            classnames_exclude=None):
        btns = []
        if exclude is None:
            exclude = []
        if classnames_add is None:
            classnames_add = []
        if classnames_exclude is None:
            classnames_exclude = []
        ph = self.permission_helper
        usr = self.request.user
        pk = quote(getattr(obj, self.opts.pk.attname))
        if 'approve' not in exclude and approve_state(usr, obj)\
                and ph.user_can_approve_obj(usr, obj):
            btns.append(
                self.approve_button(
                    pk, classnames_add, classnames_exclude
                )
            )
        if 'appoint' not in exclude and appoint_state(usr, obj)\
                and ph.user_can_appoint_obj(usr, obj):
            btns.append(
                self.appoint_button(
                    pk, classnames_add, classnames_exclude
                )
            )
        btns += super(PositionButtonHelper, self).get_buttons_for_obj(
            obj, exclude=exclude, classnames_add=classnames_add,
            classnames_exclude=classnames_exclude
        )
        return btns
models.py 文件源码 项目:travlr 作者: gauravkulkarni96 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def get_admin_url(self):
        """
        Returns the admin URL to edit the object represented by this log entry.
        """
        if self.content_type and self.object_id:
            url_name = 'admin:%s_%s_change' % (self.content_type.app_label, self.content_type.model)
            try:
                return reverse(url_name, args=(quote(self.object_id),))
            except NoReverseMatch:
                pass
        return None
admin_urls.py 文件源码 项目:travlr 作者: gauravkulkarni96 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def admin_urlquote(value):
    return quote(value)
pageadmin.py 文件源码 项目:DjangoCMS 作者: farhan711 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def change_view(self, request, object_id, form_url='', extra_context=None):
        """
        The 'change' admin view for the Page model.
        """
        if extra_context is None:
            extra_context = {'basic_info': True}
        try:
            obj = self.model.objects.get(pk=object_id)
        except self.model.DoesNotExist:
            # Don't raise Http404 just yet, because we haven't checked
            # permissions yet. We don't want an unauthenticated user to be able
            # to determine whether a given object exists.
            obj = None
        else:
            context = {
                'page': obj,
                'CMS_PERMISSION': get_cms_setting('PERMISSION'),
                'ADMIN_MEDIA_URL': settings.STATIC_URL,
                'can_change': obj.has_change_permission(request),
                'can_change_permissions': obj.has_change_permissions_permission(request),
                'current_site_id': settings.SITE_ID,
            }
            context.update(extra_context or {})
            extra_context = self.update_language_tab_context(request, obj, context)

        tab_language = get_language_from_request(request)
        extra_context.update(self.get_unihandecode_context(tab_language))

        response = super(PageAdmin, self).change_view(
            request, object_id, form_url=form_url, extra_context=extra_context)
        if tab_language and response.status_code == 302 and response._headers['location'][1] == request.path_info:
            location = response._headers['location']
            response._headers['location'] = (location[0], "%s?language=%s" % (location[1], tab_language))
        if request.method == "POST" and response.status_code in (200, 302):
            if 'history' in request.path_info:
                return HttpResponseRedirect(admin_reverse('cms_page_change', args=(quote(object_id),)))
            elif 'recover' in request.path_info:
                return HttpResponseRedirect(admin_reverse('cms_page_change', args=(quote(object_id),)))
        return response
tests.py 文件源码 项目:django-disqus-backstore 作者: chenesan 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_thread_delete_view__get__success(self, _, __):
        thread_data = THREADS_LIST_RESPONSE['response'][0]
        post_data = POSTS_LIST_RESPONSE['response'][0]
        thread_object = thread_factory(thread_data)
        related_post_object = post_factory(post_data)
        related_post_object.thread = thread_object
        delete_url = reverse('{admin_site_name}:{app_label}_{model_name}_delete'.format(
            admin_site_name=admin.site.name,
            app_label=Thread._meta.app_label,
            model_name=Thread._meta.model_name
        ), args=[thread_object.id])
        request = RequestFactory().get(delete_url, follow=True)
        request.user = MockSuperUser()

        response = ThreadAdmin(Thread, admin.site).delete_view(request, str(thread_object.id))
        template_names = set([
            'admin/delete_confirmation.html',
            'admin/disqus_backstore/delete_confirmation.html',
            'admin/disqus_backstore/thread/delete_confirmation.html',
        ])

        self.assertEqual(response.status_code, 200)
        self.assertEqual(set(response.template_name), template_names)
        # dirty hack for formatting deleted_object context... Use the same formatting
        # in django.contrib.admin.utils.get_deleted_objects
        # the related post objects will be a list of post object,
        # so we have to put it into a list...
        deleted_objects = [format_html('{}: <a href="{}">{}</a>',
                                       capfirst(obj.__class__._meta.verbose_name),
                                       reverse('%s:%s_%s_change' % (
                                           admin.site.name,
                                           obj._meta.app_label,
                                           obj._meta.model_name
                                       ), None, (quote(obj._get_pk_val()),)),
                                       obj) for obj in [thread_object, related_post_object]]
        deleted_objects[1] = [deleted_objects[1]]
        self.assertEqual(sorted(response.context_data['deleted_objects']),
                         sorted(deleted_objects))
tests.py 文件源码 项目:django-disqus-backstore 作者: chenesan 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_post_delete_view__get__success(self, _, __):
        thread_data = THREADS_LIST_RESPONSE['response'][0]
        post_data = POSTS_LIST_RESPONSE['response'][0]
        thread_object = thread_factory(thread_data)
        post_object = post_factory(post_data)
        post_object.thread = thread_object
        delete_url = reverse('{admin_site_name}:{app_label}_{model_name}_delete'.format(
            admin_site_name=admin.site.name,
            app_label=Post._meta.app_label,
            model_name=Post._meta.model_name
        ), args=[post_data['id']])

        request = RequestFactory().get(delete_url, follow=True)
        request.user = MockSuperUser()

        response = PostAdmin(Post, admin.site).delete_view(request, post_data['id'])
        template_names = set([
            'admin/delete_confirmation.html',
            'admin/disqus_backstore/delete_confirmation.html',
            'admin/disqus_backstore/post/delete_confirmation.html',
        ])

        self.assertEqual(response.status_code, 200)
        self.assertEqual(set(response.template_name), template_names)
        # dirty hack for formatting deleted_object context... Use the same formatting
        # in django.contrib.admin.utils.get_deleted_objects
        deleted_objects = [format_html('{}: <a href="{}">{}</a>',
                                       capfirst(obj.__class__._meta.verbose_name),
                                       reverse('%s:%s_%s_change' % (
                                           admin.site.name,
                                           obj._meta.app_label,
                                           obj._meta.model_name
                                       ), None, (quote(obj._get_pk_val()),)),
                                       obj) for obj in [post_object]]
        self.assertEqual(response.context_data['deleted_objects'],
                         deleted_objects)
models.py 文件源码 项目:logo-gen 作者: jellene4eva 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def get_admin_url(self):
        """
        Returns the admin URL to edit the object represented by this log entry.
        """
        if self.content_type and self.object_id:
            url_name = 'admin:%s_%s_change' % (self.content_type.app_label, self.content_type.model)
            try:
                return reverse(url_name, args=(quote(self.object_id),))
            except NoReverseMatch:
                pass
        return None
admin_urls.py 文件源码 项目:logo-gen 作者: jellene4eva 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def admin_urlquote(value):
    return quote(value)
models.py 文件源码 项目:liberator 作者: libscie 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def get_admin_url(self):
        """
        Returns the admin URL to edit the object represented by this log entry.
        """
        if self.content_type and self.object_id:
            url_name = 'admin:%s_%s_change' % (self.content_type.app_label, self.content_type.model)
            try:
                return reverse(url_name, args=(quote(self.object_id),))
            except NoReverseMatch:
                pass
        return None
admin_urls.py 文件源码 项目:liberator 作者: libscie 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def admin_urlquote(value):
    return quote(value)
models.py 文件源码 项目:gmail_scanner 作者: brandonhub 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def get_admin_url(self):
        """
        Returns the admin URL to edit the object represented by this log entry.
        """
        if self.content_type and self.object_id:
            url_name = 'admin:%s_%s_change' % (self.content_type.app_label, self.content_type.model)
            try:
                return reverse(url_name, args=(quote(self.object_id),))
            except NoReverseMatch:
                pass
        return None
admin_urls.py 文件源码 项目:gmail_scanner 作者: brandonhub 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def admin_urlquote(value):
    return quote(value)
models.py 文件源码 项目:djanoDoc 作者: JustinChavez 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def get_admin_url(self):
        """
        Returns the admin URL to edit the object represented by this log entry.
        """
        if self.content_type and self.object_id:
            url_name = 'admin:%s_%s_change' % (self.content_type.app_label, self.content_type.model)
            try:
                return reverse(url_name, args=(quote(self.object_id),))
            except NoReverseMatch:
                pass
        return None
admin_urls.py 文件源码 项目:djanoDoc 作者: JustinChavez 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def admin_urlquote(value):
    return quote(value)
wagtail_hooks.py 文件源码 项目:longclaw 作者: JamesRamm 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def detail_button(self, pk, classnames_add=None, classnames_exclude=None):
        if classnames_add is None:
            classnames_add = ['detail-button']
        if classnames_exclude is None:
            classnames_exclude = []
        classnames = self.detail_button_classnames + classnames_add
        cn = self.finalise_classname(classnames, classnames_exclude)
        return {
            'url': self.url_helper.get_action_url('detail', quote(pk)),
            'label': _('View'),
            'classname': cn,
            'title': _('View this %s') % self.verbose_name,
        }


问题


面经


文章

微信
公众号

扫码关注公众号