本文整理汇总了Python中django.contrib.admin.helpers.ACTION_CHECKBOX_NAME属性的典型用法代码示例。如果您正苦于以下问题:Python helpers.ACTION_CHECKBOX_NAME属性的具体用法?Python helpers.ACTION_CHECKBOX_NAME怎么用?Python helpers.ACTION_CHECKBOX_NAME使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类django.contrib.admin.helpers
的用法示例。
在下文中一共展示了helpers.ACTION_CHECKBOX_NAME属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_model_admin_default_delete_action
# 需要导入模块: from django.contrib.admin import helpers [as 别名]
# 或者: from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME [as 别名]
def test_model_admin_default_delete_action(self):
action_data = {
ACTION_CHECKBOX_NAME: [self.s1.pk, self.s2.pk],
'action': 'delete_selected',
'index': 0,
}
delete_confirmation_data = {
ACTION_CHECKBOX_NAME: [self.s1.pk, self.s2.pk],
'action': 'delete_selected',
'post': 'yes',
}
confirmation = self.client.post(reverse('admin:admin_views_subscriber_changelist'), action_data)
self.assertIsInstance(confirmation, TemplateResponse)
self.assertContains(confirmation, 'Are you sure you want to delete the selected subscribers?')
self.assertContains(confirmation, '<h2>Summary</h2>')
self.assertContains(confirmation, '<li>Subscribers: 2</li>')
self.assertContains(confirmation, '<li>External subscribers: 1</li>')
self.assertContains(confirmation, ACTION_CHECKBOX_NAME, count=2)
self.client.post(reverse('admin:admin_views_subscriber_changelist'), delete_confirmation_data)
self.assertEqual(Subscriber.objects.count(), 0)
示例2: test_user_message_on_none_selected
# 需要导入模块: from django.contrib.admin import helpers [as 别名]
# 或者: from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME [as 别名]
def test_user_message_on_none_selected(self):
"""
User sees a warning when 'Go' is pressed and no items are selected.
"""
action_data = {
ACTION_CHECKBOX_NAME: [],
'action': 'delete_selected',
'index': 0,
}
url = reverse('admin:admin_views_subscriber_changelist')
response = self.client.post(url, action_data)
self.assertRedirects(response, url, fetch_redirect_response=False)
response = self.client.get(response.url)
msg = 'Items must be selected in order to perform actions on them. No items have been changed.'
self.assertContains(response, msg)
self.assertEqual(Subscriber.objects.count(), 2)
示例3: action_checkbox
# 需要导入模块: from django.contrib.admin import helpers [as 别名]
# 或者: from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME [as 别名]
def action_checkbox(self, obj):
"""
A list_display column containing a checkbox widget.
"""
return helpers.checkbox.render(helpers.ACTION_CHECKBOX_NAME, force_text(obj.pk))
示例4: action_checkbox
# 需要导入模块: from django.contrib.admin import helpers [as 别名]
# 或者: from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME [as 别名]
def action_checkbox(self, obj):
"""
A list_display column containing a checkbox widget.
"""
return helpers.checkbox.render(helpers.ACTION_CHECKBOX_NAME, str(obj.pk))
示例5: hard_delete_selected
# 需要导入模块: from django.contrib.admin import helpers [as 别名]
# 或者: from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME [as 别名]
def hard_delete_selected(modeladmin, request, queryset):
opts = modeladmin.model._meta # # pylint: disable=W0212
deletable_objects, model_count, perms_needed, protected = modeladmin.get_deleted_objects(queryset, request)
if request.POST.get('post') and not protected:
if perms_needed:
raise PermissionDenied
if queryset.count():
number_of_rows_deleted, __ = queryset.hard_delete() # __ = deleted_items
if number_of_rows_deleted == 1:
message_bit = _('1 record was')
else:
message_bit = _('%(number_of_rows)s records were') % dict(number_of_rows=number_of_rows_deleted)
message = _('%(message_bit)s deleted') % dict(message_bit=message_bit)
modeladmin.message_user(request, message)
return None
objects_name = model_ngettext(queryset)
if perms_needed or protected:
title = _('Cannot delete %(name)s') % {'name': objects_name}
else:
title = _('Are you sure?')
context = {
**modeladmin.admin_site.each_context(request),
'title': title,
'objects_name': str(objects_name),
'deletable_objects': [deletable_objects],
'model_count': dict(model_count).items(),
'queryset': queryset,
'perms_lacking': perms_needed,
'protected': protected,
'opts': opts,
'action_checkbox_name': helpers.ACTION_CHECKBOX_NAME,
'media': modeladmin.media,
}
request.current_app = modeladmin.admin_site.name
return TemplateResponse(request, 'admin/hard_delete_selected_confirmation.html', context)
示例6: refresh_work
# 需要导入模块: from django.contrib.admin import helpers [as 别名]
# 或者: from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME [as 别名]
def refresh_work(self, request, queryset):
if request.POST.get('confirm'): # Confirmed
downloaded_titles = []
for obj in queryset:
chosen_poster = request.POST.get('chosen_poster_{:d}'.format(obj.id))
if not chosen_poster:
continue
if obj.retrieve_poster(chosen_poster):
downloaded_titles.append(obj.title)
if downloaded_titles:
self.message_user(
request,
"Des posters ont été trouvés pour les anime suivants : %s." % ', '.join(downloaded_titles))
else:
self.message_user(request, "Aucun poster n'a été trouvé, essayez de changer le titre.")
return None
bundle = []
for work in queryset:
bundle.append((work.id, work.title, get_potential_posters(work)))
context = {
'queryset': queryset,
'bundle': bundle,
'opts': self.model._meta,
'action_checkbox_name': helpers.ACTION_CHECKBOX_NAME
}
return TemplateResponse(request, 'admin/refresh_poster_confirmation.html', context)
示例7: test_model_admin_custom_action
# 需要导入模块: from django.contrib.admin import helpers [as 别名]
# 或者: from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME [as 别名]
def test_model_admin_custom_action(self):
"""A custom action defined in a ModelAdmin method."""
action_data = {
ACTION_CHECKBOX_NAME: [self.s1.pk],
'action': 'mail_admin',
'index': 0,
}
self.client.post(reverse('admin:admin_views_subscriber_changelist'), action_data)
self.assertEqual(len(mail.outbox), 1)
self.assertEqual(mail.outbox[0].subject, 'Greetings from a ModelAdmin action')
示例8: test_default_delete_action_nonexistent_pk
# 需要导入模块: from django.contrib.admin import helpers [as 别名]
# 或者: from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME [as 别名]
def test_default_delete_action_nonexistent_pk(self):
self.assertFalse(Subscriber.objects.filter(id=9998).exists())
action_data = {
ACTION_CHECKBOX_NAME: ['9998'],
'action': 'delete_selected',
'index': 0,
}
response = self.client.post(reverse('admin:admin_views_subscriber_changelist'), action_data)
self.assertContains(response, 'Are you sure you want to delete the selected subscribers?')
self.assertContains(response, '<ul></ul>', html=True)
示例9: test_non_localized_pk
# 需要导入模块: from django.contrib.admin import helpers [as 别名]
# 或者: from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME [as 别名]
def test_non_localized_pk(self):
"""
If USE_THOUSAND_SEPARATOR is set, the ids for the objects selected for
deletion are rendered without separators.
"""
s = ExternalSubscriber.objects.create(id=9999)
action_data = {
ACTION_CHECKBOX_NAME: [s.pk, self.s2.pk],
'action': 'delete_selected',
'index': 0,
}
response = self.client.post(reverse('admin:admin_views_subscriber_changelist'), action_data)
self.assertTemplateUsed(response, 'admin/delete_selected_confirmation.html')
self.assertContains(response, 'value="9999"') # Instead of 9,999
self.assertContains(response, 'value="%s"' % self.s2.pk)
示例10: test_model_admin_default_delete_action_protected
# 需要导入模块: from django.contrib.admin import helpers [as 别名]
# 或者: from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME [as 别名]
def test_model_admin_default_delete_action_protected(self):
"""
The default delete action where some related objects are protected
from deletion.
"""
q1 = Question.objects.create(question='Why?')
a1 = Answer.objects.create(question=q1, answer='Because.')
a2 = Answer.objects.create(question=q1, answer='Yes.')
q2 = Question.objects.create(question='Wherefore?')
action_data = {
ACTION_CHECKBOX_NAME: [q1.pk, q2.pk],
'action': 'delete_selected',
'index': 0,
}
delete_confirmation_data = action_data.copy()
delete_confirmation_data['post'] = 'yes'
response = self.client.post(reverse('admin:admin_views_question_changelist'), action_data)
self.assertContains(response, 'would require deleting the following protected related objects')
self.assertContains(
response,
'<li>Answer: <a href="%s">Because.</a></li>' % reverse('admin:admin_views_answer_change', args=(a1.pk,)),
html=True
)
self.assertContains(
response,
'<li>Answer: <a href="%s">Yes.</a></li>' % reverse('admin:admin_views_answer_change', args=(a2.pk,)),
html=True
)
# A POST request to delete protected objects displays the page which
# says the deletion is prohibited.
response = self.client.post(reverse('admin:admin_views_question_changelist'), delete_confirmation_data)
self.assertContains(response, 'would require deleting the following protected related objects')
self.assertEqual(Question.objects.count(), 2)
示例11: test_delete_queryset_hook
# 需要导入模块: from django.contrib.admin import helpers [as 别名]
# 或者: from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME [as 别名]
def test_delete_queryset_hook(self):
delete_confirmation_data = {
ACTION_CHECKBOX_NAME: [self.s1.pk, self.s2.pk],
'action': 'delete_selected',
'post': 'yes',
'index': 0,
}
SubscriberAdmin.overridden = False
self.client.post(reverse('admin:admin_views_subscriber_changelist'), delete_confirmation_data)
# SubscriberAdmin.delete_queryset() sets overridden to True.
self.assertIs(SubscriberAdmin.overridden, True)
self.assertEqual(Subscriber.objects.all().count(), 0)
示例12: test_delete_selected_uses_get_deleted_objects
# 需要导入模块: from django.contrib.admin import helpers [as 别名]
# 或者: from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME [as 别名]
def test_delete_selected_uses_get_deleted_objects(self):
"""The delete_selected action uses ModelAdmin.get_deleted_objects()."""
book = Book.objects.create(name='Test Book')
data = {
ACTION_CHECKBOX_NAME: [book.pk],
'action': 'delete_selected',
'index': 0,
}
response = self.client.post(reverse('admin2:admin_views_book_changelist'), data)
# BookAdmin.get_deleted_objects() returns custom text.
self.assertContains(response, 'a deletable object')
示例13: test_custom_function_mail_action
# 需要导入模块: from django.contrib.admin import helpers [as 别名]
# 或者: from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME [as 别名]
def test_custom_function_mail_action(self):
"""A custom action may be defined in a function."""
action_data = {
ACTION_CHECKBOX_NAME: [self.s1.pk],
'action': 'external_mail',
'index': 0,
}
self.client.post(reverse('admin:admin_views_externalsubscriber_changelist'), action_data)
self.assertEqual(len(mail.outbox), 1)
self.assertEqual(mail.outbox[0].subject, 'Greetings from a function action')
示例14: test_custom_function_action_with_redirect
# 需要导入模块: from django.contrib.admin import helpers [as 别名]
# 或者: from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME [as 别名]
def test_custom_function_action_with_redirect(self):
"""Another custom action defined in a function."""
action_data = {
ACTION_CHECKBOX_NAME: [self.s1.pk],
'action': 'redirect_to',
'index': 0,
}
response = self.client.post(reverse('admin:admin_views_externalsubscriber_changelist'), action_data)
self.assertEqual(response.status_code, 302)
示例15: test_default_redirect
# 需要导入模块: from django.contrib.admin import helpers [as 别名]
# 或者: from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME [as 别名]
def test_default_redirect(self):
"""
Actions which don't return an HttpResponse are redirected to the same
page, retaining the querystring (which may contain changelist info).
"""
action_data = {
ACTION_CHECKBOX_NAME: [self.s1.pk],
'action': 'external_mail',
'index': 0,
}
url = reverse('admin:admin_views_externalsubscriber_changelist') + '?o=1'
response = self.client.post(url, action_data)
self.assertRedirects(response, url)