本文整理匯總了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
示例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!")
示例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}
)
示例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
示例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
示例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)),
}
示例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.')
示例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)
示例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,
}
示例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)
示例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
示例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
示例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
示例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()
示例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,
},
}