Ticket #8001: 8001.admin_urls.diff

File 8001.admin_urls.diff, 6.3 KB (added by Julien Phalip, 16 years ago)
  • django/django/contrib/admin/options.py

     
    325325        for inline in self.inline_instances:
    326326            yield inline.get_formset(request, obj)
    327327
    328     def save_add(self, request, form, formsets, post_url_continue):
     328    def save_add(self, request, form, formsets, post_url_continue, post_url_has_change_permission='../', post_url_has_not_change_permission='../../../'):
    329329        """
    330330        Saves the object in the "add" stage and returns an HttpResponseRedirect.
    331331
     
    366366            # redirect to the change-list page for this object. Otherwise,
    367367            # redirect to the admin index.
    368368            if self.has_change_permission(request, None):
    369                 post_url = '../'
     369                return HttpResponseRedirect(post_url_has_change_permission)
    370370            else:
    371                 post_url = '../../../'
    372             return HttpResponseRedirect(post_url)
     371                return HttpResponseRedirect(post_url_has_not_change_permission)
    373372    save_add = transaction.commit_on_success(save_add)
    374373
    375     def save_change(self, request, form, formsets=None):
     374    def save_change(self, request, form, formsets=None, post_url_save_as_new="../%s/", post_url_add_another="../add/", post_url_save="../"):
    376375        """
    377376        Saves the object in the "change" stage and returns an HttpResponseRedirect.
    378377
     
    423422                return HttpResponseRedirect(request.path)
    424423        elif request.POST.has_key("_saveasnew"):
    425424            request.user.message_set.create(message=_('The %(name)s "%(obj)s" was added successfully. You may edit it again below.') % {'name': opts.verbose_name, 'obj': new_object})
    426             return HttpResponseRedirect("../%s/" % pk_value)
     425            return HttpResponseRedirect(post_url_save_as_new % pk_value)
    427426        elif request.POST.has_key("_addanother"):
    428427            request.user.message_set.create(message=msg + ' ' + (_("You may add another %s below.") % opts.verbose_name))
    429             return HttpResponseRedirect("../add/")
     428            return HttpResponseRedirect(post_url_add_another)
    430429        else:
    431430            request.user.message_set.create(message=msg)
    432             return HttpResponseRedirect("../")
     431            return HttpResponseRedirect(post_url_save)
    433432    save_change = transaction.commit_on_success(save_change)
    434433
    435434    def render_change_form(self, request, context, add=False, change=False, form_url='', obj=None):
     
    458457            "admin/change_form.html"
    459458        ], context, context_instance=template.RequestContext(request))
    460459
    461     def add_view(self, request, form_url='', extra_context=None):
     460    def add_view(self, request, form_url='', extra_context=None, post_url_continue='../%s/'):
    462461        "The 'add' admin view for this model."
    463462        model = self.model
    464463        opts = model._meta
     
    484483                    instance=obj, save_as_new=request.POST.has_key("_saveasnew"))
    485484                inline_formsets.append(inline_formset)
    486485            if all_valid(inline_formsets) and form.is_valid():
    487                 return self.save_add(request, form, inline_formsets, '../%s/')
     486                return self.save_add(request, form, inline_formsets, post_url_continue)
    488487        else:
    489488            form = ModelForm(initial=dict(request.GET.items()))
    490489            for FormSet in self.get_formsets(request):
     
    515514        context.update(extra_context or {})
    516515        return self.render_change_form(request, context, add=True)
    517516
    518     def change_view(self, request, object_id, extra_context=None):
     517    def change_view(self, request, object_id, extra_context=None, form_url='../../add/'):
    519518        "The 'change' admin view for this model."
    520519        model = self.model
    521520        opts = model._meta
     
    536535            raise Http404('%s object with primary key %r does not exist.' % (opts.verbose_name, escape(object_id)))
    537536
    538537        if request.POST and request.POST.has_key("_saveasnew"):
    539             return self.add_view(request, form_url='../../add/')
     538            return self.add_view(request, form_url)
    540539
    541540        ModelForm = self.get_form(request, obj)
    542541        inline_formsets = []
     
    612611            'admin/change_list.html'
    613612        ], context, context_instance=template.RequestContext(request))
    614613
    615     def delete_view(self, request, object_id, extra_context=None):
     614    def delete_view(self, request, object_id, extra_context=None, object_url="../../%s/", post_url_has_not_change_permission="../../../../", post_url_has_change_permission="../../"):
    616615        "The 'delete' admin view for this model."
    617616        from django.contrib.admin.models import LogEntry, DELETION
    618617        opts = self.model._meta
     
    634633
    635634        # Populate deleted_objects, a data structure of all related objects that
    636635        # will also be deleted.
    637         deleted_objects = [mark_safe(u'%s: <a href="../../%s/">%s</a>' % (escape(force_unicode(capfirst(opts.verbose_name))), quote(object_id), escape(obj))), []]
     636        object_rendered_url = object_url % quote(object_id)
     637        deleted_objects = [mark_safe(u'%s: <a href="%s">%s</a>' % (escape(force_unicode(capfirst(opts.verbose_name))), object_rendered_url, escape(obj))), []]
    638638        perms_needed = sets.Set()
    639639        get_deleted_objects(deleted_objects, perms_needed, request.user, obj, opts, 1, self.admin_site)
    640640
     
    646646            LogEntry.objects.log_action(request.user.id, ContentType.objects.get_for_model(self.model).id, object_id, obj_display, DELETION)
    647647            request.user.message_set.create(message=_('The %(name)s "%(obj)s" was deleted successfully.') % {'name': force_unicode(opts.verbose_name), 'obj': force_unicode(obj_display)})
    648648            if not self.has_change_permission(request, None):
    649                 return HttpResponseRedirect("../../../../")
    650             return HttpResponseRedirect("../../")
     649                return HttpResponseRedirect(post_url_has_not_change_permission)
     650            return HttpResponseRedirect(post_url_has_change_permission)
    651651       
    652652        context = {
    653653            "title": _("Are you sure?"),
Back to Top