當前位置: 首頁>>代碼示例>>Python>>正文


Python helpers.ACTION_CHECKBOX_NAME屬性代碼示例

本文整理匯總了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) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:22,代碼來源:test_actions.py

示例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) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:18,代碼來源:test_actions.py

示例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)) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:7,代碼來源:options.py

示例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)) 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:7,代碼來源:options.py

示例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) 
開發者ID:vigo,項目名稱:django2-project-template,代碼行數:43,代碼來源:base.py

示例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) 
開發者ID:mangaki,項目名稱:mangaki,代碼行數:28,代碼來源:admin.py

示例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') 
開發者ID:nesdis,項目名稱:djongo,代碼行數:12,代碼來源:test_actions.py

示例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) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:12,代碼來源:test_actions.py

示例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) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:17,代碼來源:test_actions.py

示例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) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:35,代碼來源:test_actions.py

示例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) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:14,代碼來源:test_actions.py

示例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') 
開發者ID:nesdis,項目名稱:djongo,代碼行數:13,代碼來源:test_actions.py

示例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') 
開發者ID:nesdis,項目名稱:djongo,代碼行數:12,代碼來源:test_actions.py

示例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) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:11,代碼來源:test_actions.py

示例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) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:15,代碼來源:test_actions.py


注:本文中的django.contrib.admin.helpers.ACTION_CHECKBOX_NAME屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。