python - Problem using Django admin Actions with intermediate pages -



python - Problem using Django admin Actions with intermediate pages -

i added admin action send_email through admin.py.i want when admin uses send_email action selected users should show intermediate page selected users , inquire confirmation.in case inquire confirmation when click on "send email" button nil happens , got returned change_list view without send_email action got called.

admin.py

class myuseradmin(useradmin): list_display = ['username', 'email', 'first_name', 'last_name', 'is_active', staff] list_filter = ['groups', 'is_staff', 'is_superuser', 'is_active'] actions = ['send_email'] def send_email(self, request, queryset): django.core.mail import send_mail if 'apply' in request.post: in queryset: if i.email: send_mail('subject here', 'here message.', 'from@example.com',[i.email], fail_silently=false) else: self.message_user(request, "mail sent ") else: django.http import httpresponse django.template import requestcontext, loader t = loader.get_template('admin/send_mail.html') c = requestcontext(request, {'articles': queryset}) homecoming httpresponse(t.render(c),) admin.site.unregister(user) admin.site.register(user, myuseradmin)

templates/send_mail.html

{% extends "admin/base_site.html" %} {% block content %} <form action="" method="post">{% csrf_token %} <p>the mail service send next users:</p> <ul>{{ articles|unordered_list }}</ul> <input type="hidden" name="action" value="send_email" /> <input type="submit" name="apply" value="send email" /> </form> {% endblock %}

sorry bad english language .plz help

i found easy way it. worked me... hope helps:

what need "pass" selected items confirmation page , include them in form including <input type="hidden" name="action" value="admin_action" /> django admin knows should still phone call admin action. post know whether process query set or render confirmation page.

# write admin action. # important: note context passed templateresponse django.contrib.admin import helpers django.template.response import templateresponse class mymodeladmin(admin.modeladmin): def admin_action(self, request, queryset): if request.post.get('post'): # process queryset here else: context = { 'title': _("are sure?"), 'queryset': queryset, 'action_checkbox_name': helpers.action_checkbox_name, } homecoming templateresponse(request, 'path/to/template.html', context, current_app=self.admin_site.name) # template {% extends "admin/base_site.html" %} {% load i18n l10n %} {% block content %} <form action="" method="post">{% csrf_token %} <p>the next videos accepted:</p> <ul>{{ queryset|unordered_list }}</ul> <div> {% obj in queryset %} <input type="hidden" name="{{ action_checkbox_name }}" value="{{ obj.pk|unlocalize }}" /> {% endfor %} <input type="hidden" name="action" value="admin_action" /> <input type="hidden" name="post" value="yes" /> <input type="submit" value="{% trans "yes, i'm sure" %}" /> </div> </form> {% endblock %}

python django django-admin django-templates

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -