diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
index 081d001..79f82d4 100644
a
|
b
|
class ModelAdmin(BaseModelAdmin):
|
762 | 762 | "admin/change_form.html" |
763 | 763 | ], context, current_app=self.admin_site.name) |
764 | 764 | |
765 | | def response_add(self, request, obj, post_url_continue='../%s/'): |
| 765 | def response_add(self, request, obj, continue_url=None, add_url=None, hasperm_url=None, noperm_url=None): |
766 | 766 | """ |
767 | 767 | Determines the HttpResponse for the add_view stage. |
768 | 768 | """ |
769 | 769 | opts = obj._meta |
770 | 770 | pk_value = obj._get_pk_val() |
| 771 | app_label = opts.app_label |
| 772 | model_name = opts.module_name |
| 773 | site_name = self.admin_site.name |
| 774 | |
| 775 | msg_dict = {'name': force_text(opts.verbose_name), 'obj': force_text(obj)} |
771 | 776 | |
772 | | msg = _('The %(name)s "%(obj)s" was added successfully.') % {'name': force_text(opts.verbose_name), 'obj': force_text(obj)} |
773 | 777 | # Here, we distinguish between different save types by checking for |
774 | 778 | # the presence of keys in request.POST. |
775 | 779 | if "_continue" in request.POST: |
776 | | self.message_user(request, msg + ' ' + _("You may edit it again below.")) |
| 780 | msg = _('The %(name)s "%(obj)s" was added successfully. You may edit it again below.') % msg_dict |
| 781 | self.message_user(request, msg) |
| 782 | if continue_url is None: |
| 783 | continue_url = reverse('admin:%s_%s_change' % ( |
| 784 | app_label, model_name |
| 785 | ), |
| 786 | args=(pk_value,), |
| 787 | current_app=site_name) |
777 | 788 | if "_popup" in request.POST: |
778 | | post_url_continue += "?_popup=1" |
779 | | return HttpResponseRedirect(post_url_continue % pk_value) |
| 789 | continue_url += "?_popup=1" |
| 790 | return HttpResponseRedirect(continue_url) |
780 | 791 | |
781 | 792 | if "_popup" in request.POST: |
782 | 793 | return HttpResponse( |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
785 | 796 | # escape() calls force_text. |
786 | 797 | (escape(pk_value), escapejs(obj))) |
787 | 798 | elif "_addanother" in request.POST: |
788 | | self.message_user(request, msg + ' ' + (_("You may add another %s below.") % force_text(opts.verbose_name))) |
789 | | return HttpResponseRedirect(request.path) |
| 799 | msg = _('The %(name)s "%(obj)s" was added successfully. You may add another %(name)s below.') % msg_dict |
| 800 | self.message_user(request, msg) |
| 801 | if add_url is None: |
| 802 | add_url = reverse('admin:%s_%s_add' % |
| 803 | (app_label, model_name), |
| 804 | current_app=site_name) |
| 805 | return HttpResponseRedirect(add_url) |
790 | 806 | else: |
| 807 | msg = _('The %(name)s "%(obj)s" was added successfully.') % msg_dict |
791 | 808 | self.message_user(request, msg) |
792 | 809 | |
793 | 810 | # Figure out where to redirect. If the user has change permission, |
794 | 811 | # redirect to the change-list page for this object. Otherwise, |
795 | 812 | # redirect to the admin index. |
796 | 813 | if self.has_change_permission(request, None): |
797 | | post_url = reverse('admin:%s_%s_changelist' % |
798 | | (opts.app_label, opts.module_name), |
799 | | current_app=self.admin_site.name) |
| 814 | if hasperm_url is None: |
| 815 | url = reverse('admin:%s_%s_changelist' % |
| 816 | (app_label, model_name), |
| 817 | current_app=site_name) |
| 818 | else: |
| 819 | url = hasperm_url |
800 | 820 | else: |
801 | | post_url = reverse('admin:index', |
802 | | current_app=self.admin_site.name) |
803 | | return HttpResponseRedirect(post_url) |
| 821 | if noperm_url is None: |
| 822 | url = reverse('admin:index', current_app=site_name) |
| 823 | else: |
| 824 | url = noperm_url |
| 825 | return HttpResponseRedirect(url) |
804 | 826 | |
805 | | def response_change(self, request, obj): |
| 827 | def response_change(self, request, obj, continue_url=None, add_url=None, hasperm_url=None, noperm_url=None): |
806 | 828 | """ |
807 | 829 | Determines the HttpResponse for the change_view stage. |
808 | 830 | """ |
809 | 831 | opts = obj._meta |
810 | 832 | |
| 833 | app_label = opts.app_label |
| 834 | model_name = opts.module_name |
| 835 | site_name = self.admin_site.name |
| 836 | verbose_name = opts.verbose_name |
811 | 837 | # Handle proxy models automatically created by .only() or .defer(). |
812 | 838 | # Refs #14529 |
813 | | verbose_name = opts.verbose_name |
814 | | module_name = opts.module_name |
815 | 839 | if obj._deferred: |
816 | 840 | opts_ = opts.proxy_for_model._meta |
817 | 841 | verbose_name = opts_.verbose_name |
818 | | module_name = opts_.module_name |
| 842 | model_name = opts_.module_name |
819 | 843 | |
| 844 | msg_dict = {'name': force_text(verbose_name), 'obj': force_text(obj)} |
820 | 845 | pk_value = obj._get_pk_val() |
821 | 846 | |
822 | | msg = _('The %(name)s "%(obj)s" was changed successfully.') % {'name': force_text(verbose_name), 'obj': force_text(obj)} |
| 847 | if "_continue" in request.POST or "_saveasnew" in request.POST: |
| 848 | if continue_url is None: |
| 849 | continue_url = reverse('admin:%s_%s_change' % |
| 850 | (app_label, model_name), |
| 851 | args=(pk_value,), |
| 852 | current_app=site_name) |
823 | 853 | if "_continue" in request.POST: |
824 | | self.message_user(request, msg + ' ' + _("You may edit it again below.")) |
825 | | if "_popup" in request.REQUEST: |
826 | | return HttpResponseRedirect(request.path + "?_popup=1") |
827 | | else: |
828 | | return HttpResponseRedirect(request.path) |
| 854 | msg = _('The %(name)s "%(obj)s" was changed successfully. You may edit it again below.') % msg_dict |
| 855 | self.message_user(request, msg) |
| 856 | if "_popup" in request.POST: |
| 857 | continue_url += "?_popup=1" |
| 858 | return HttpResponseRedirect(continue_url) |
829 | 859 | elif "_saveasnew" in request.POST: |
830 | | msg = _('The %(name)s "%(obj)s" was added successfully. You may edit it again below.') % {'name': force_text(verbose_name), 'obj': obj} |
| 860 | msg = _('The %(name)s "%(obj)s" was added successfully. You may edit it again below.') % msg_dict |
831 | 861 | self.message_user(request, msg) |
832 | | return HttpResponseRedirect(reverse('admin:%s_%s_change' % |
833 | | (opts.app_label, module_name), |
834 | | args=(pk_value,), |
835 | | current_app=self.admin_site.name)) |
| 862 | return HttpResponseRedirect(continue_url) |
836 | 863 | elif "_addanother" in request.POST: |
837 | | self.message_user(request, msg + ' ' + (_("You may add another %s below.") % force_text(verbose_name))) |
838 | | return HttpResponseRedirect(reverse('admin:%s_%s_add' % |
839 | | (opts.app_label, module_name), |
840 | | current_app=self.admin_site.name)) |
| 864 | msg = _('The %(name)s "%(obj)s" was changed successfully. You may add another %(name)s below.') % msg_dict |
| 865 | self.message_user(request, msg) |
| 866 | if add_url is None: |
| 867 | add_url = reverse('admin:%s_%s_add' % |
| 868 | (app_label, model_name), |
| 869 | current_app=site_name) |
| 870 | return HttpResponseRedirect(add_url) |
841 | 871 | else: |
| 872 | msg = _('The %(name)s "%(obj)s" was changed successfully.') % msg_dict |
842 | 873 | self.message_user(request, msg) |
843 | 874 | # Figure out where to redirect. If the user has change permission, |
844 | 875 | # redirect to the change-list page for this object. Otherwise, |
845 | 876 | # redirect to the admin index. |
846 | 877 | if self.has_change_permission(request, None): |
847 | | post_url = reverse('admin:%s_%s_changelist' % |
848 | | (opts.app_label, module_name), |
849 | | current_app=self.admin_site.name) |
| 878 | if hasperm_url is None: |
| 879 | url = reverse('admin:%s_%s_changelist' % |
| 880 | (app_label, model_name), |
| 881 | current_app=site_name) |
| 882 | else: |
| 883 | url = hasperm_url |
850 | 884 | else: |
851 | | post_url = reverse('admin:index', |
852 | | current_app=self.admin_site.name) |
853 | | return HttpResponseRedirect(post_url) |
| 885 | if noperm_url is None: |
| 886 | url = reverse('admin:index', current_app=site_name) |
| 887 | else: |
| 888 | url = noperm_url |
| 889 | return HttpResponseRedirect(url) |
854 | 890 | |
855 | 891 | def response_action(self, request, queryset): |
856 | 892 | """ |
diff --git a/django/contrib/auth/admin.py b/django/contrib/auth/admin.py
index ccf940d..52f8083 100644
a
|
b
|
class UserAdmin(admin.ModelAdmin):
|
153 | 153 | 'admin/auth/user/change_password.html' |
154 | 154 | ], context, current_app=self.admin_site.name) |
155 | 155 | |
156 | | def response_add(self, request, obj, post_url_continue='../%s/'): |
| 156 | def response_add(self, request, obj, continue_url=None, add_url=None, hasperm_url=None, noperm_url=None): |
157 | 157 | """ |
158 | 158 | Determines the HttpResponse for the add_view stage. It mostly defers to |
159 | 159 | its superclass implementation but is customized because the User model |
… |
… |
class UserAdmin(admin.ModelAdmin):
|
166 | 166 | # * We are adding a user in a popup |
167 | 167 | if '_addanother' not in request.POST and '_popup' not in request.POST: |
168 | 168 | request.POST['_continue'] = 1 |
169 | | return super(UserAdmin, self).response_add(request, obj, |
170 | | post_url_continue) |
| 169 | return super(UserAdmin, self).response_add(request, obj, continue_url, add_url, hasperm_url, noperm_url) |
171 | 170 | |
172 | 171 | admin.site.register(Group, GroupAdmin) |
173 | 172 | admin.site.register(User, UserAdmin) |