Python django.contrib.admin 模块,ACTION_CHECKBOX_NAME 实例源码

我们从Python开源项目中,提取了以下21个代码示例,用于说明如何使用django.contrib.admin.ACTION_CHECKBOX_NAME

项目:openvpnmon    作者:feroda    | 项目源码 | 文件源码
def publish_cert(self, request, queryset):

        verify_certs = True
        for el in queryset:
            if not el.cert:
                messages.error(request, _(
                    "No certificate has been created for client %s, cannot publish")
                               % el)
                url = urlresolvers.reverse('admin:base_client_changelist')
                verify_certs = False

        if verify_certs:

            selected = request.POST.getlist(admin.ACTION_CHECKBOX_NAME)
            ct = ContentType.objects.get_for_model(queryset.model)
            url = u"%s?ct=%s&ids=%s" % (
                urlresolvers.reverse("display-distributions"), ct.pk,
                ",".join(selected))

        return HttpResponseRedirect(url)
项目:edd    作者:JBEI    | 项目源码 | 文件源码
def merge_with_action(self, request, queryset):
        MergeForm = self.get_merge_form(request)
        form = None
        if 'merge' in request.POST:
            form = MergeForm(request.POST)
            if form.is_valid():
                mtype = form.cleaned_data['mtype']
                # update all measurements referencing mtype
                Measurement.objects.filter(
                    measurement_type__in=queryset,
                ).update(measurement_type=mtype)
                queryset.delete()
                return HttpResponseRedirect(request.get_full_path())
        if not form:
            form = MergeForm(
                initial={'_selected_action': request.POST.getlist(admin.ACTION_CHECKBOX_NAME)},
            )
        return render(request, 'admin/merge_measurement_type.html', context={
            'types': queryset,
            'form': form,
        })
项目:pyfeedback    作者:d120    | 项目源码 | 文件源码
def status_aendern_action(self, request, queryset):
        """Beschreibt eine Admin-Action für die Statusänderung."""
        form = None

        if 'apply' in request.POST:
            form = self.StatusAendernForm(request.POST)

            if form.is_valid():
                status = form.cleaned_data['status']

                queryset.update(status=status)
                for veranstaltung in queryset:
                    veranstaltung.log(request.user)

                self.message_user(request, "Status erfolgreich geändert.")
                return HttpResponseRedirect(request.get_full_path())

        if not form:
            form = self.StatusAendernForm(initial={'_selected_action': request.POST.getlist(admin.ACTION_CHECKBOX_NAME)})

        return render(request, 'admin/status_aendern.html', {'veranstaltungen': queryset, 'status': form, })
项目:pyfeedback    作者:d120    | 项目源码 | 文件源码
def keine_evaluation_action(self, request, queryset):
        """Beschreibt eine Admin-Action für die Option keine Evaluation."""
        form = None

        if 'apply' in request.POST:     #Dieser Teil reicht bereits zum ändern aus. In diesem Fall können auch Zeile 146-149 gelöscht werden (Kein Bestätigungsfenster erscheint.
            queryset.update(status=Veranstaltung.STATUS_KEINE_EVALUATION_FINAL)
            queryset.update(evaluieren=False)
            for veranstaltung in queryset:
                veranstaltung.log(request.user)

            self.message_user(request, "Veranstaltungen wurden erfolgreich auf Keine Evaluation gesetzt.")
            return HttpResponseRedirect(request.get_full_path())
            #nach dem return landet Python in status_aendern_action
        if not form:
            form = self.KeineEvaluationForm(initial={'_selected_action': request.POST.getlist(admin.ACTION_CHECKBOX_NAME)})
        return render(request, 'admin/keine_evaluation.html', {'veranstaltungen': queryset, 'status':form, })
项目:elephaas    作者:peak6    | 项目源码 | 文件源码
def promote_instances(self, request, queryset):
        """
        Promote transmitted PostgreSQL replication instances to master state
        """

        if request.POST.get('post') == 'yes':

            for inst_id in request.POST.getlist(admin.ACTION_CHECKBOX_NAME):
                inst = Instance.objects.get(pk=inst_id)

                try:
                    util = PGUtility(inst)
                    util.promote()

                except Exception, e:
                    self.message_user(request, "%s : %s" % (e, inst), messages.ERROR)
                    continue

                self.message_user(request, "%s promoted to read/write!" % inst)
            return

        # Now go to the confirmation form. It's very basic, and only serves
        # to disrupt the process and avoid accidental promotions that would
        # necessitate a resync.

        queryset = queryset.exclude(master_id__isnull=True)

        if queryset.count() < 1:
            self.message_user(request, "No valid replicas to promte!", messages.WARNING)
            return

        return render(request, 'admin/haas/instance/promote.html', 
                {'queryset' : queryset,
                 'opts': self.model._meta,
                 'action_checkbox_name': admin.ACTION_CHECKBOX_NAME,
                }
        )
项目:elephaas    作者:peak6    | 项目源码 | 文件源码
def rebuild_instances(self, request, queryset):
        """
        Rebuild all transmitted PostgreSQL replication instances from master
        """

        # If we should be rebuilding an instance, connect to the host,
        # ensure the instance is stopped, and sync the data directories
        # through rsync + ssh.

        if request.POST.get('post') == 'yes':

            for inst_id in request.POST.getlist(admin.ACTION_CHECKBOX_NAME):
                inst = Instance.objects.get(pk=inst_id)

                try:
                    util = PGUtility(inst)
                    util.master_sync()

                except Exception, e:
                    self.message_user(request, "%s : %s" % (e, inst), messages.ERROR)
                    continue

                self.message_user(request, "%s rebuilt!" % inst)
            return

        # Now go to the confirmation form. It's very basic, and only serves
        # to disrupt the process and avoid accidental rebuilds.

        return render(request, 'admin/haas/shared/rebuild.html', 
                {'queryset' : queryset,
                 'opts': self.model._meta,
                 'crumb_title': self.rebuild_instances.short_description,
                 'action_checkbox_name': admin.ACTION_CHECKBOX_NAME,
                }
        )
项目:django-open-volunteering-platform    作者:OpenVolunteeringPlatform    | 项目源码 | 文件源码
def changelist_view(self, request, extra_context=None):
        if 'action' in request.POST and request.POST['action'] == 'export_all_as_csv':
            # Make a list with all ids to make a 'export all'
            if not request.POST.getlist(admin.ACTION_CHECKBOX_NAME):
                post = request.POST.copy()
                for u in Lead.objects.all():
                    post.update({admin.ACTION_CHECKBOX_NAME: str(u.id)})
                request._set_post(post)
        return super(LeadAdmin, self).changelist_view(request, extra_context)
项目:vishleva.com    作者:webmalc    | 项目源码 | 文件源码
def send_sms(modeladmin, request, queryset):
        selected = request.POST.getlist(admin.ACTION_CHECKBOX_NAME)
        return HttpResponseRedirect('{}?ids={}'.format(
            reverse_lazy('admin:send_sms'), ','.join(selected)))
项目:django-danceschool    作者:django-danceschool    | 项目源码 | 文件源码
def repeat_events(modeladmin, request, queryset):
    selected = request.POST.getlist(admin.ACTION_CHECKBOX_NAME)
    ct = ContentType.objects.get_for_model(queryset.model)
    return HttpResponseRedirect(reverse('repeatEvents') + "?ct=%s&ids=%s" % (ct.pk, ",".join(selected)))
项目:django-danceschool    作者:django-danceschool    | 项目源码 | 文件源码
def emailNotification(self, request, queryset):
        # Allows use of the email view to contact specific customers.
        selected = request.POST.getlist(admin.ACTION_CHECKBOX_NAME)
        return HttpResponseRedirect(reverse('sendInvoiceNotifications') + "?invoices=%s" % (",".join(selected)))
项目:django-danceschool    作者:django-danceschool    | 项目源码 | 文件源码
def emailCustomers(self, request, queryset):
        # Allows use of the email view to contact specific customers.
        selected = request.POST.getlist(admin.ACTION_CHECKBOX_NAME)
        return HttpResponseRedirect(reverse('emailStudents') + "?customers=%s" % (",".join(selected)))
项目:django-danceschool    作者:django-danceschool    | 项目源码 | 文件源码
def updateStaffCompensationInfo(self, request, queryset):
    '''
    This action is added to the list for instructors to permit bulk
    updating of compensation information for staff members.
    '''
    selected = request.POST.getlist(admin.ACTION_CHECKBOX_NAME)
    ct = ContentType.objects.get_for_model(queryset.model)
    return HttpResponseRedirect(reverse('updateCompensationRules') + "?ct=%s&ids=%s" % (ct.pk, ",".join(selected)))
项目:AntiMagic    作者:luo1fly    | 项目源码 | 文件源码
def approve_selected_objects(modeladmin, request, queryset):
        selected = request.POST.getlist(admin.ACTION_CHECKBOX_NAME)
        ct = ContentType.objects.get_for_model(queryset.model)
        return HttpResponseRedirect("/asset/new_assets/approval/?ct=%s&ids=%s" % (ct.pk, ",".join(selected)))
项目:ddnet-django    作者:ddnet    | 项目源码 | 文件源码
def release_action(modeladmin, request, queryset):
    selected = request.POST.getlist(dj_admin.ACTION_CHECKBOX_NAME)
    return HttpResponseRedirect(reverse('admin:map_release') + '?ids={}'.format(','.join(selected)))
项目:ddnet-django    作者:ddnet    | 项目源码 | 文件源码
def fix_action(modeladmin, request, queryset):
    selected = request.POST.getlist(dj_admin.ACTION_CHECKBOX_NAME)
    return HttpResponseRedirect(reverse('admin:map_fix') + '?ids={}'.format(','.join(selected)))
项目:openvpnmon    作者:feroda    | 项目源码 | 文件源码
def show_cert(self, request, queryset):
        selected = request.POST.getlist(admin.ACTION_CHECKBOX_NAME)
        ct = ContentType.objects.get_for_model(queryset.model)
        url = u"%s?ct=%s&ids=%s" % (urlresolvers.reverse("display-certs"),
                                    ct.pk, ",".join(selected))
        return HttpResponseRedirect(url)
项目:openvpnmon    作者:feroda    | 项目源码 | 文件源码
def download_cert(self, request, queryset):
        selected = request.POST.getlist(admin.ACTION_CHECKBOX_NAME)
        if len(selected) > 1:
            messages.error(
                request,
                _("You can download only certificates for one client a time"))
            url = urlresolvers.reverse('admin:base_client_changelist')
        elif not queryset[0].cert:
            messages.error(
                request, _("No certificate has been created for this client"))
            url = urlresolvers.reverse('admin:base_client_changelist')
        else:
            url = urlresolvers.reverse('private-cert-download',
                                       kwargs={"client_id": int(selected[0])})
        return HttpResponseRedirect(url)
项目:edd    作者:JBEI    | 项目源码 | 文件源码
def merge_with_action(self, request, queryset):
        form = None
        # only allow merges when registry_id or registry_url are None
        queryset = queryset.filter(Q(registry_id=None) | Q(registry_url=None))
        if 'merge' in request.POST:
            form = self.MergeWithStrainForm(request.POST)
            if form.is_valid():
                strain = form.cleaned_data['strain']
                # Update all lines referencing strains in queryset to reference `strain` instead
                lines = Line.objects.filter(strains__in=queryset)
                for line in lines:
                    line.strains.remove(*queryset.all())
                    line.strains.add(strain)
                strain_count = queryset.count()
                queryset.delete()
                messages.info(
                    request,
                    _("Merged %(strain_count)d strains, updating %(line_count)d lines.") % {
                        'strain_count': strain_count,
                        'line_count': lines.count(),
                    }
                )
                return HttpResponseRedirect(request.get_full_path())
        if not form:
            form = self.MergeWithStrainForm(
                initial={'_selected_action': request.POST.getlist(admin.ACTION_CHECKBOX_NAME)},
            )
        return render(request, 'admin/merge_strain.html', context={
            'strains': queryset,
            'form': form
        })
项目:pyfeedback    作者:d120    | 项目源码 | 文件源码
def assign_fachgebiet_action(self, request, queryset):
        """Definiert eine Admin-Action für die Fachgebietzuweisung."""
        form = None
        suggestion_list = []

        for p in queryset:
            proposed_fachgebiet = FachgebietEmail.get_fachgebiet_from_email(p.email)
            suggestion_list.append((p, proposed_fachgebiet))

        if any(s in request.POST for s in ('apply', 'save')):
            form = self.FachgebietZuweisenForm(request.POST)

            if form.is_valid():
                selected_persons = request.POST.getlist("selectedPerson")
                for person in queryset:
                    person_id_str = str(person.id)
                    if person_id_str in selected_persons:
                        proposed_fachgebiet_id = request.POST.get("fachgebiet_" + person_id_str, 0)
                        if int(proposed_fachgebiet_id) > 0:
                            proposed_fachgebiet = Fachgebiet.objects.get(id=proposed_fachgebiet_id)
                            person.fachgebiet = proposed_fachgebiet
                            person.save()
                            suggestion_list = [(x, y) for x, y in suggestion_list if x is not person]

                self.message_user(request, "Fachgebiete erfolgreich zugewiesen.")

                if ('save' in request.POST) or not suggestion_list:
                    return HttpResponseRedirect(request.get_full_path())

        if not form:
            form = self.FachgebietZuweisenForm(initial={
                '_selected_action': request.POST.getlist(admin.ACTION_CHECKBOX_NAME)
            })

        return render(request, 'admin/fachgebiet.html', {'data': suggestion_list, 'fachgebiet': form, })
项目:netbox    作者:digitalocean    | 项目源码 | 文件源码
def activate_selected(modeladmin, request, queryset):
        """
        Enable bulk activation of UserKeys
        """
        try:
            my_userkey = UserKey.objects.get(user=request.user)
        except UserKey.DoesNotExist:
            messages.error(request, "You do not have an active User Key.")
            return redirect('admin:secrets_userkey_changelist')

        if 'activate' in request.POST:
            form = ActivateUserKeyForm(request.POST)
            if form.is_valid():
                master_key = my_userkey.get_master_key(form.cleaned_data['secret_key'])
                if master_key is not None:
                    for uk in form.cleaned_data['_selected_action']:
                        uk.activate(master_key)
                    return redirect('admin:secrets_userkey_changelist')
                else:
                    messages.error(
                        request, "Invalid private key provided. Unable to retrieve master key.", extra_tags='error'
                    )
        else:
            form = ActivateUserKeyForm(initial={'_selected_action': request.POST.getlist(admin.ACTION_CHECKBOX_NAME)})

        return render(request, 'activate_keys.html', {
            'form': form,
        })
项目:django-remote-submission    作者:ornl-ndav    | 项目源码 | 文件源码
def submit_to_server(self, request, queryset):
        """Submit job to server via an admin interface action."""
        form = None

        if 'apply' in request.POST:
            form = JobAdmin.RequestPasswordForm(request.POST)

            if form.is_valid():
                password = form.cleaned_data['password']
                username = form.cleaned_data['username']

                count = 0
                for job in queryset:
                    submit_job_to_server.delay(
                        job_pk=job.pk,
                        password=password,
                        username=username,
                    )
                    count += 1

                message = _(
                    'Successfully submitted %(count)s job',
                    'Successfully submitted %(count)s jobs',
                    count,
                ) % {
                    'count': count,
                }

                self.message_user(request, message)
                return HttpResponseRedirect(request.get_full_path())

        if not form:
            # This part is required to make the intermediate page work with the
            # Django actions.
            selected_action = request.POST.getlist(admin.ACTION_CHECKBOX_NAME)
            index = int(request.POST.get('index', 0))
            form = JobAdmin.RequestPasswordForm(initial={
                admin.ACTION_CHECKBOX_NAME: selected_action,
                'select_across': request.POST['select_across'],
                'action': request.POST['action'],
            })

        return render(
            request,
            'admin/django_remote_submission/submit_to_server.html',
            {
                'jobs': queryset,
                'form': form,
            },
        )