当前位置: 首页>>代码示例>>Python>>正文


Python utils.quote方法代码示例

本文整理汇总了Python中django.contrib.admin.utils.quote方法的典型用法代码示例。如果您正苦于以下问题:Python utils.quote方法的具体用法?Python utils.quote怎么用?Python utils.quote使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.contrib.admin.utils的用法示例。


在下文中一共展示了utils.quote方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_buttons_for_obj

# 需要导入模块: from django.contrib.admin import utils [as 别名]
# 或者: from django.contrib.admin.utils import quote [as 别名]
def get_buttons_for_obj(self, obj, exclude=None, classnames_add=None,
                            classnames_exclude=None):
        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))
        btns = []
        if ph.user_can_inspect_obj(usr, obj):
            btns.append(self.detail_button(
                pk, classnames_add, classnames_exclude))
            btns.append(self.cancel_button(
                pk, classnames_add, classnames_exclude))

        return btns 
开发者ID:JamesRamm,项目名称:longclaw,代码行数:22,代码来源:wagtail_hooks.py

示例2: test_after_delete_snippet_hook

# 需要导入模块: from django.contrib.admin import utils [as 别名]
# 或者: from django.contrib.admin.utils import quote [as 别名]
def test_after_delete_snippet_hook(self):
        advert = Advert.objects.create(
            url='http://www.example.com/',
            text='Test hook',
        )

        def hook_func(request, instances):
            self.assertIsInstance(request, HttpRequest)
            self.assertQuerysetEqual(instances, ["<Advert: Test hook>"])
            return HttpResponse("Overridden!")

        with self.register_hook('after_delete_snippet', hook_func):
            response = self.client.post(
                reverse('wagtailsnippets:delete', args=('tests', 'advert', quote(advert.pk), ))
            )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content, b"Overridden!") 
开发者ID:wagtail,项目名称:wagtail,代码行数:20,代码来源:tests.py

示例3: chosen

# 需要导入模块: from django.contrib.admin import utils [as 别名]
# 或者: from django.contrib.admin.utils import quote [as 别名]
def chosen(request, app_label, model_name, pk):
    model = get_snippet_model_from_url_params(app_label, model_name)
    item = get_object_or_404(model, pk=unquote(pk))

    snippet_data = {
        'id': str(item.pk),
        'string': str(item),
        'edit_link': reverse('wagtailsnippets:edit', args=(
            app_label, model_name, quote(item.pk)))
    }

    return render_modal_workflow(
        request,
        None, None,
        None, json_data={'step': 'chosen', 'result': snippet_data}
    ) 
开发者ID:wagtail,项目名称:wagtail,代码行数:18,代码来源:chooser.py

示例4: get_buttons_for_obj

# 需要导入模块: from django.contrib.admin import utils [as 别名]
# 或者: from django.contrib.admin.utils import quote [as 别名]
def get_buttons_for_obj(self, obj, exclude=[], classnames_add=[],
                            classnames_exclude=[]):
        ph = self.permission_helper
        pk = quote(getattr(obj, self.opts.pk.attname))
        btns = []
        if('inspect' not in exclude and self.inspect_view_enabled):
            btns.append(
                self.inspect_button(pk, classnames_add, classnames_exclude)
            )
        if('edit' not in exclude and ph.can_edit_object(self.user, obj)):
            btns.append(
                self.edit_button(pk, classnames_add, classnames_exclude)
            )
        if('delete' not in exclude and ph.can_delete_object(self.user, obj)):
            btns.append(
                self.delete_button(pk, classnames_add, classnames_exclude)
            )
        return btns 
开发者ID:rkhleics,项目名称:wagtailmodeladmin,代码行数:20,代码来源:helpers.py

示例5: get_buttons_for_obj

# 需要导入模块: from django.contrib.admin import utils [as 别名]
# 或者: from django.contrib.admin.utils import quote [as 别名]
def get_buttons_for_obj(self, obj, exclude=None, classnames_add=None,
                            classnames_exclude=None):
        exclude = exclude or []
        classnames_add = classnames_add or []
        classnames_exclude = classnames_exclude or []

        btns = super(TaxonomyButtonHelper, self).get_buttons_for_obj(
            obj,
            exclude=exclude,
            classnames_add=classnames_add,
            classnames_exclude=classnames_exclude
        )

        ph = self.permission_helper
        usr = self.request.user
        pk = quote(getattr(obj, self.opts.pk.attname))

        if('usage' not in exclude and ph.user_can_edit_obj(usr, obj)):
            btns.append(
                self.usage_button(pk, classnames_add, classnames_exclude)
            )

        return btns 
开发者ID:torchbox,项目名称:wagtail-torchbox,代码行数:25,代码来源:admin.py

示例6: add_child_button

# 需要导入模块: from django.contrib.admin import utils [as 别名]
# 或者: from django.contrib.admin.utils import quote [as 别名]
def add_child_button(self, pk, child_verbose_name, **kwargs):
        """Build a add child button, to easily add a child under meta term."""
        instance = self.model.objects.get(pk=pk)
        if instance.is_archived or instance.get_parent() and instance.get_parent().is_archived:
            return

        classnames = self.prepare_classnames(
            start=self.edit_button_classnames + ['icon', 'icon-plus'],
            add=kwargs.get('classnames_add'),
            exclude=kwargs.get('classnames_exclude')
        )
        return {
            'classname': classnames,
            'label': 'Add %s %s' % (
                child_verbose_name, self.verbose_name),
            'title': 'Add %s %s under this one' % (
                child_verbose_name, self.verbose_name),
            'url': self.url_helper.get_action_url('add_child', quote(pk)),
        } 
开发者ID:OpenTechFund,项目名称:hypha,代码行数:21,代码来源:admin_helpers.py

示例7: test_logentry_change_message

# 需要导入模块: from django.contrib.admin import utils [as 别名]
# 或者: from django.contrib.admin.utils import quote [as 别名]
def test_logentry_change_message(self):
        """
        LogEntry.change_message is stored as a dumped JSON structure to be able
        to get the message dynamically translated at display time.
        """
        post_data = {
            'site': self.site.pk, 'title': 'Changed', 'hist': 'Some content',
            'created_0': '2008-03-12', 'created_1': '11:54',
        }
        change_url = reverse('admin:admin_utils_article_change', args=[quote(self.a1.pk)])
        response = self.client.post(change_url, post_data)
        self.assertRedirects(response, reverse('admin:admin_utils_article_changelist'))
        logentry = LogEntry.objects.filter(content_type__model__iexact='article').latest('id')
        self.assertEqual(logentry.get_change_message(), 'Changed title and hist.')
        with translation.override('fr'):
            self.assertEqual(logentry.get_change_message(), 'Modification de title et hist.')

        add_url = reverse('admin:admin_utils_article_add')
        post_data['title'] = 'New'
        response = self.client.post(add_url, post_data)
        self.assertRedirects(response, reverse('admin:admin_utils_article_changelist'))
        logentry = LogEntry.objects.filter(content_type__model__iexact='article').latest('id')
        self.assertEqual(logentry.get_change_message(), 'Added.')
        with translation.override('fr'):
            self.assertEqual(logentry.get_change_message(), 'Ajout.') 
开发者ID:nesdis,项目名称:djongo,代码行数:27,代码来源:test_logentry.py

示例8: test_recentactions_without_content_type

# 需要导入模块: from django.contrib.admin import utils [as 别名]
# 或者: from django.contrib.admin.utils import quote [as 别名]
def test_recentactions_without_content_type(self):
        """
        If a LogEntry is missing content_type it will not display it in span
        tag under the hyperlink.
        """
        response = self.client.get(reverse('admin:index'))
        link = reverse('admin:admin_utils_article_change', args=(quote(self.a1.pk),))
        should_contain = """<a href="%s">%s</a>""" % (escape(link), escape(repr(self.a1)))
        self.assertContains(response, should_contain)
        should_contain = "Article"
        self.assertContains(response, should_contain)
        logentry = LogEntry.objects.get(content_type__model__iexact='article')
        # If the log entry doesn't have a content type it should still be
        # possible to view the Recent Actions part (#10275).
        logentry.content_type = None
        logentry.save()

        should_contain = should_contain.encode()
        counted_presence_before = response.content.count(should_contain)
        response = self.client.get(reverse('admin:index'))
        counted_presence_after = response.content.count(should_contain)
        self.assertEqual(counted_presence_before - 1, counted_presence_after) 
开发者ID:nesdis,项目名称:djongo,代码行数:24,代码来源:test_logentry.py

示例9: detail_button

# 需要导入模块: from django.contrib.admin import utils [as 别名]
# 或者: from django.contrib.admin.utils import quote [as 别名]
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,
        } 
开发者ID:JamesRamm,项目名称:longclaw,代码行数:15,代码来源:wagtail_hooks.py

示例10: admin_urlquote

# 需要导入模块: from django.contrib.admin import utils [as 别名]
# 或者: from django.contrib.admin.utils import quote [as 别名]
def admin_urlquote(value):
    return quote(value) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:4,代码来源:admin_urls.py

示例11: get_admin_url

# 需要导入模块: from django.contrib.admin import utils [as 别名]
# 或者: from django.contrib.admin.utils import quote [as 别名]
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 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:13,代码来源:models.py

示例12: get_admin_url

# 需要导入模块: from django.contrib.admin import utils [as 别名]
# 或者: from django.contrib.admin.utils import quote [as 别名]
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 
开发者ID:shtalinberg,项目名称:django-actions-logger,代码行数:16,代码来源:models.py

示例13: get_admin_url

# 需要导入模块: from django.contrib.admin import utils [as 别名]
# 或者: from django.contrib.admin.utils import quote [as 别名]
def get_admin_url(self):
        """
        Return 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 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:13,代码来源:models.py

示例14: __init__

# 需要导入模块: from django.contrib.admin import utils [as 别名]
# 或者: from django.contrib.admin.utils import quote [as 别名]
def __init__(self, model_admin, instance_pk):
        super().__init__(model_admin)
        self.instance_pk = unquote(instance_pk)
        self.pk_safe = quote(self.instance_pk)
        self.site = get_object_or_404(Site, id=self.instance_pk)
        self.instance = self.model.get_for_site(self.site)
        self.instance.save() 
开发者ID:rkhleics,项目名称:wagtailmenus,代码行数:9,代码来源:views.py

示例15: copy_button

# 需要导入模块: from django.contrib.admin import utils [as 别名]
# 或者: from django.contrib.admin.utils import quote [as 别名]
def copy_button(self, pk, classnames_add=[], classnames_exclude=[]):
        cn = self.finalise_classname(classnames_add, classnames_exclude)
        return {
            'url': self.url_helper.get_action_url('copy', quote(pk)),
            'label': _('Copy'),
            'classname': cn,
            'title': _('Copy this %(model_name)s') % {
                'model_name': self.verbose_name,
            },
        } 
开发者ID:rkhleics,项目名称:wagtailmenus,代码行数:12,代码来源:modeladmin.py


注:本文中的django.contrib.admin.utils.quote方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。