Ticket #8001: 8001.admin_urls.diff
File 8001.admin_urls.diff, 6.3 KB (added by , 16 years ago) |
---|
-
django/django/contrib/admin/options.py
325 325 for inline in self.inline_instances: 326 326 yield inline.get_formset(request, obj) 327 327 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='../../../'): 329 329 """ 330 330 Saves the object in the "add" stage and returns an HttpResponseRedirect. 331 331 … … 366 366 # redirect to the change-list page for this object. Otherwise, 367 367 # redirect to the admin index. 368 368 if self.has_change_permission(request, None): 369 post_url = '../'369 return HttpResponseRedirect(post_url_has_change_permission) 370 370 else: 371 post_url = '../../../' 372 return HttpResponseRedirect(post_url) 371 return HttpResponseRedirect(post_url_has_not_change_permission) 373 372 save_add = transaction.commit_on_success(save_add) 374 373 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="../"): 376 375 """ 377 376 Saves the object in the "change" stage and returns an HttpResponseRedirect. 378 377 … … 423 422 return HttpResponseRedirect(request.path) 424 423 elif request.POST.has_key("_saveasnew"): 425 424 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) 427 426 elif request.POST.has_key("_addanother"): 428 427 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) 430 429 else: 431 430 request.user.message_set.create(message=msg) 432 return HttpResponseRedirect( "../")431 return HttpResponseRedirect(post_url_save) 433 432 save_change = transaction.commit_on_success(save_change) 434 433 435 434 def render_change_form(self, request, context, add=False, change=False, form_url='', obj=None): … … 458 457 "admin/change_form.html" 459 458 ], context, context_instance=template.RequestContext(request)) 460 459 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/'): 462 461 "The 'add' admin view for this model." 463 462 model = self.model 464 463 opts = model._meta … … 484 483 instance=obj, save_as_new=request.POST.has_key("_saveasnew")) 485 484 inline_formsets.append(inline_formset) 486 485 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) 488 487 else: 489 488 form = ModelForm(initial=dict(request.GET.items())) 490 489 for FormSet in self.get_formsets(request): … … 515 514 context.update(extra_context or {}) 516 515 return self.render_change_form(request, context, add=True) 517 516 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/'): 519 518 "The 'change' admin view for this model." 520 519 model = self.model 521 520 opts = model._meta … … 536 535 raise Http404('%s object with primary key %r does not exist.' % (opts.verbose_name, escape(object_id))) 537 536 538 537 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) 540 539 541 540 ModelForm = self.get_form(request, obj) 542 541 inline_formsets = [] … … 612 611 'admin/change_list.html' 613 612 ], context, context_instance=template.RequestContext(request)) 614 613 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="../../"): 616 615 "The 'delete' admin view for this model." 617 616 from django.contrib.admin.models import LogEntry, DELETION 618 617 opts = self.model._meta … … 634 633 635 634 # Populate deleted_objects, a data structure of all related objects that 636 635 # 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))), []] 638 638 perms_needed = sets.Set() 639 639 get_deleted_objects(deleted_objects, perms_needed, request.user, obj, opts, 1, self.admin_site) 640 640 … … 646 646 LogEntry.objects.log_action(request.user.id, ContentType.objects.get_for_model(self.model).id, object_id, obj_display, DELETION) 647 647 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)}) 648 648 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) 651 651 652 652 context = { 653 653 "title": _("Are you sure?"),