Python django.contrib.admin.ACTION_CHECKBOX_NAME Examples

The following are 18 code examples of django.contrib.admin.ACTION_CHECKBOX_NAME(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.contrib.admin , or try the search function .
Example #1
Source File: admin.py    From repoll with Apache License 2.0 7 votes vote down vote up
def deny_selected_new_assets(self, request, queryset):
        """
        用于在申请redis的界面添加一个审批拒绝按钮
        :param request: Http Request实例
        :param queryset: 勾选实例名称
        :return:
        """
        # 获得被打钩的checkbox对应的Redis的id编号,用于更新数据库的主键
        selected = request.POST.getlist(admin.ACTION_CHECKBOX_NAME)
        deny_upline_number = 0
        try:
            for asset_id in selected:
                obj = ApproveRedis(request, asset_id)
                deny_redis_ins = obj.deny_create()
                if deny_redis_ins:
                    deny_upline_number += 1
                    obj.redis_apply_status_update(statu=4)
                    self.message_user(request, "已拒绝  %s  个新Redis实例上线!" % deny_upline_number)
                else:
                    self.message_user(request, "操作实例为 {0} 的实例失败,已存在上线实例,请检查".format(obj.redis_ins_name))
        except ValueError as e:
            self.message_user(request, "操作实例为 {0} 的实例失败,原因为{1}".format(queryset, e)) 
Example #2
Source File: admin.py    From repoll with Apache License 2.0 7 votes vote down vote up
def approve_selected_new_assets(self, request, queryset):
        """
        用于在申请redis的界面添加一个审批通过按钮
        :param request: Http Request实例
        :param queryset: 勾选实例名称
        :return:
        """
        # 获得被打钩的checkbox对应的Redis的id编号,用于更新数据库的主键
        selected = request.POST.getlist(admin.ACTION_CHECKBOX_NAME)
        success_upline_number = 0
        try:
            for asset_id in selected:
                obj = ApproveRedis(request, asset_id)
                create_redis_ins = obj.create_asset()
                if create_redis_ins:
                    success_upline_number += 1
                    self.message_user(request, "成功批准  %s  个新Redis实例上线!" % success_upline_number)
                    obj.redis_apply_status_update(statu=3)
                else:
                    self.message_user(request, "实例为 {0} 的实例上线失败,已存在上线实例,请检查".format(obj.redis_ins_name))
        except ValueError as e:
            self.message_user(request, "实例为 {0} 的实例上线失败,原因为{1}".format(queryset, e)) 
Example #3
Source File: test_refresh_from_anidb.py    From mangaki with GNU Affero General Public License v3.0 6 votes vote down vote up
def test_refresh_tags_from_anidb_confirmed(self):
        self.add_to_responses('hibike_euphonium.xml')
        self.client.login(username='test', password='test')
        hibike = Work.objects.get(title='Hibike! Euphonium')

        refresh_tags_from_anidb_url = reverse('admin:mangaki_work_changelist')
        context = {
            'action': 'update_tags_via_anidb',
            admin.ACTION_CHECKBOX_NAME: self.work_ids,
            'confirm': 1,
            'to_update_work_ids': [str(hibike.pk)],
            'work_ids': [str(hibike.pk), str(hibike.pk), str(hibike.pk)],
            'tag_titles': ['female protagonist', 'facial distortion', 'training'],
            'weights': ['0', '0', '400'],
            'anidb_tag_ids': ['5851', '4055', '3831'],
            'tag_operations': ['added', 'added', 'added'],
            'tag_checkboxes': [str(hibike.pk)+':5851', str(hibike.pk)+':4055', str(hibike.pk)+':3831']
        }

        response = self.client.post(refresh_tags_from_anidb_url, context)
        self.assertEqual(response.status_code, 302)

        tags = set(Work.objects.get(anidb_aid=10889).taggedwork_set.all().values_list('tag__title', flat=True)) 
Example #4
Source File: test_merge.py    From mangaki with GNU Affero General Public License v3.0 6 votes vote down vote up
def test_merge_confirmed(self):
        self.client.login(username='test', password='test')
        merge_url = reverse('admin:mangaki_work_changelist')
        context = {
            'action': 'merge',
            admin.ACTION_CHECKBOX_NAME: self.work_ids,
            'confirm': 1,
            'id': self.work_ids[0],  # Chosen ID for the canonical work
            'fields_to_choose': '',
            'fields_required': ''
        }
        with self.assertNumQueries(39):
            self.client.post(merge_url, context)
        self.assertEqual(list(Rating.objects.filter(user__in=self.users).values_list('choice', flat=True)), ['favorite'] * 4)
        self.assertEqual(Work.all_objects.filter(redirect__isnull=True).count(), 1)
        self.assertEqual(WorkCluster.objects.count(), 1)
        self.assertEqual(Staff.objects.count(), 2)
        self.assertEqual(Reference.objects.count(), 2)
        self.assertEqual(Work.objects.get(id=self.work_ids[0]).genre.count(), 2)

    # noinspection PyPep8Naming
    # FIXME: classical scenario, we should have a simpler decorator to perform those tests 
Example #5
Source File: application.py    From Ouroboros with GNU General Public License v3.0 5 votes vote down vote up
def test_approval_action_approves_application(self):
        self.client.force_login(self.admin)
        change_url = reverse_lazy("admin:application_application_changelist")

        self.client.post(
            change_url,
            {"action": "approve", admin.ACTION_CHECKBOX_NAME: [self.app.pk]},
            follow=True,
        )

        self.app.refresh_from_db()
        self.assertEqual(self.app.status, STATUS_ADMITTED) 
Example #6
Source File: admin.py    From django-heythere with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def send_selected(self, request, queryset):
        if request.POST.get('post'):
            for notification in queryset:
                notification.send_email()
            self.message_user(
                request,
                _(u'Successfully tried to send {0} notifications'.format(
                    len(queryset))))
            return redirect('admin:heythere_notification_changelist')
        return TemplateResponse(request, 'admin/send_selected.html', {
            'current_app': self.admin_site.name,
            'opts': self.opts,
            'action_checkbox_name': admin.ACTION_CHECKBOX_NAME,
            'queryset': queryset
        }) 
Example #7
Source File: user.py    From Ouroboros with GNU General Public License v3.0 5 votes vote down vote up
def test_export_user_emails(self):
        self.client.force_login(self.admin)
        change_url = reverse_lazy("admin:user_user_changelist")
        response = self.client.post(
            change_url,
            {
                "action": "export_user_emails",
                admin.ACTION_CHECKBOX_NAME: [self.user.pk],
            },
            follow=True,
        )
        self.assertEqual(response.status_code, 200) 
Example #8
Source File: application.py    From Ouroboros with GNU General Public License v3.0 5 votes vote down vote up
def test_export_application_emails(self):
        self.client.force_login(self.admin)
        change_url = reverse_lazy("admin:application_application_changelist")
        response = self.client.post(
            change_url,
            {
                "action": "export_application_emails",
                admin.ACTION_CHECKBOX_NAME: [self.app.pk],
            },
            follow=True,
        )
        self.assertEqual(response.status_code, 200) 
Example #9
Source File: application.py    From Ouroboros with GNU General Public License v3.0 5 votes vote down vote up
def test_reject_action_rejects_application(self):
        self.client.force_login(self.admin)
        change_url = reverse_lazy("admin:application_application_changelist")
        self.client.post(
            change_url,
            {"action": "reject", admin.ACTION_CHECKBOX_NAME: [self.app.pk]},
            follow=True,
        )
        self.app.refresh_from_db()
        self.assertEqual(self.app.status, STATUS_REJECTED) 
Example #10
Source File: application.py    From Ouroboros with GNU General Public License v3.0 5 votes vote down vote up
def test_reject_action_sends_rejection_email(self):
        self.client.force_login(self.admin)
        change_url = reverse_lazy("admin:application_application_changelist")

        self.client.post(
            change_url,
            {"action": "reject", admin.ACTION_CHECKBOX_NAME: [self.app.pk]},
            follow=True,
        )

        self.assertEqual(len(mail.outbox), 1) 
Example #11
Source File: application.py    From Ouroboros with GNU General Public License v3.0 5 votes vote down vote up
def test_approval_action_sends_approval_email(self):
        self.client.force_login(self.admin)
        change_url = reverse_lazy("admin:application_application_changelist")

        self.client.post(
            change_url, {"action": "approve", admin.ACTION_CHECKBOX_NAME: [self.app.pk]}
        )

        self.assertEqual(len(mail.outbox), 1) 
Example #12
Source File: admin.py    From crowdata with MIT License 5 votes vote down vote up
def cluster_canons_action(self, request, queryset):
        selected = request.POST.getlist(admin.ACTION_CHECKBOX_NAME)
        #ct = ContentType.objects.get_for_model(queryset.model)
        #return HttpResponseRedirect("/cluster/?ct=%s&ids=%s" % (ct.pk, ",".join(selected)))
        return HttpResponseRedirect("/admin/crowdataapp/canonicalfieldentrylabel/cluster/?ids=%s" % ",".join(selected)) 
Example #13
Source File: test_merge.py    From mangaki with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_merge(self):
        self.client.login(username='test', password='test')
        merge_url = reverse('admin:mangaki_work_changelist')
        response = self.client.post(merge_url, {'action': 'merge', admin.ACTION_CHECKBOX_NAME: self.work_ids})
        self.assertEqual(response.status_code, 200) 
Example #14
Source File: test_change_default_title.py    From mangaki with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_change_title_no_alternative_titles(self):
        self.client.login(username='test', password='test')
        change_title_url = reverse('admin:mangaki_work_changelist')
        response = self.client.post(
            change_title_url,
            {'action': 'change_title', admin.ACTION_CHECKBOX_NAME: self.work_ids[2]},
            follow=True
        )
        self.assertEqual(response.status_code, 200) 
Example #15
Source File: test_change_default_title.py    From mangaki with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_change_title(self):
        self.client.login(username='test', password='test')
        change_title_url = reverse('admin:mangaki_work_changelist')
        response = self.client.post(
            change_title_url,
            {'action': 'change_title', admin.ACTION_CHECKBOX_NAME: self.work_ids},
            follow=True
        )
        self.assertEqual(response.status_code, 200) 
Example #16
Source File: test_refresh_from_anidb.py    From mangaki with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_refresh_tags_from_anidb(self):
        self.add_to_responses('hibike_euphonium.xml')
        self.client.login(username='test', password='test')

        refresh_tags_from_anidb_url = reverse('admin:mangaki_work_changelist')
        response = self.client.post(
            refresh_tags_from_anidb_url,
            {'action': 'update_tags_via_anidb', admin.ACTION_CHECKBOX_NAME: self.work_ids},
            follow=True
        )
        self.assertEqual(response.status_code, 200) 
Example #17
Source File: test_refresh_from_anidb.py    From mangaki with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_refresh_work_from_anidb(self):
        self.add_to_responses('hibike_euphonium.xml')
        self.add_to_responses('punchline.xml')

        self.client.login(username='test', password='test')
        refresh_work_from_anidb_url = reverse('admin:mangaki_work_changelist')
        response = self.client.post(
            refresh_work_from_anidb_url,
            {'action': 'refresh_work_from_anidb', admin.ACTION_CHECKBOX_NAME: self.work_ids},
            follow=True
        )
        self.assertEqual(response.status_code, 200)

        self.assertEqual(Work.objects.get(anidb_aid=10889).title, 'Hibike! Euphonium') 
Example #18
Source File: test_prize.py    From donation-tracker with Apache License 2.0 5 votes vote down vote up
def test_prize_key_import_action(self):
        self.client.login(username='admin', password='password')

        response = self.client.post(
            reverse('admin:tracker_prize_changelist'),
            {
                'action': 'import_keys_action',
                ACTION_CHECKBOX_NAME: [self.prize.id, self.prize_with_keys.id],
            },
        )
        self.assertRedirects(response, reverse('admin:tracker_prize_changelist'))
        self.assertMessages(response, ['Select exactly one prize that uses keys.'])
        response = self.client.post(
            reverse('admin:tracker_prize_changelist'),
            {'action': 'import_keys_action', ACTION_CHECKBOX_NAME: [self.prize.id]},
        )
        self.assertRedirects(response, reverse('admin:tracker_prize_changelist'))
        self.assertMessages(response, ['Select exactly one prize that uses keys.'])
        response = self.client.post(
            reverse('admin:tracker_prize_changelist'),
            {
                'action': 'import_keys_action',
                ACTION_CHECKBOX_NAME: [self.prize_with_keys.id],
            },
        )
        self.assertRedirects(
            response,
            reverse('admin:tracker_prize_key_import', args=(self.prize_with_keys.id,)),
        )