#NEWLINE# def delete_object( request , model , post_delete_redirect , object_id = None , slug = None , slug_field = 'slug' , template_name = None , template_loader = loader , extra_context = None , login_required = False , context_processors = None , template_object_name = 'object' ) : #NEWLINE# #INDENT# '\n    Generic object-delete function.\n\n    The given template will be used to confirm deletetion if this view is\n    fetched using GET; for safty, deletion will only be performed if this\n    view is POSTed.\n\n    Templates: ``<app_label>/<model_name>_confirm_delete.html``\n    Context:\n        object\n            the original object being deleted\n    ' #NEWLINE# if ( extra_context is None ) : #NEWLINE# #INDENT# extra_context = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# if ( login_required and ( not request . user . is_authenticated ( ) ) ) : #NEWLINE# #INDENT# return redirect_to_login ( request . path ) #NEWLINE# #UNINDENT# obj = lookup_object ( model , object_id , slug , slug_field ) #NEWLINE# if ( request . method == 'POST' ) : #NEWLINE# #INDENT# obj . delete ( ) #NEWLINE# msg = ( ugettext ( 'The %(verbose_name)s was deleted.' ) % { #NEWLINE# #INDENT# 'verbose_name' : model . _meta . verbose_name , #NEWLINE# #UNINDENT# } ) #NEWLINE# messages . success ( request , msg , fail_silently = True ) #NEWLINE# return HttpResponseRedirect ( post_delete_redirect ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not template_name ) : #NEWLINE# #INDENT# template_name = ( '%s/%s_confirm_delete.html' % ( model . _meta . app_label , model . _meta . object_name . lower ( ) ) ) #NEWLINE# #UNINDENT# t = template_loader . get_template ( template_name ) #NEWLINE# c = RequestContext ( request , { #NEWLINE# #INDENT# template_object_name : obj , #NEWLINE# #UNINDENT# } , context_processors ) #NEWLINE# apply_extra_context ( extra_context , c ) #NEWLINE# response = HttpResponse ( t . render ( c ) ) #NEWLINE# populate_xheaders ( request , response , model , getattr ( obj , obj . _meta . pk . attname ) ) #NEWLINE# return response