#NEWLINE# @ login_required #NEWLINE# def edit_snippet( request , snippet_id = None , template_name = 'cab/edit_snippet.html' ) : #NEWLINE# #INDENT# if ( not request . user . is_active ) : #NEWLINE# #INDENT# return HttpResponseForbidden ( ) #NEWLINE# #UNINDENT# if snippet_id : #NEWLINE# #INDENT# snippet = get_object_or_404 ( Snippet , pk = snippet_id ) #NEWLINE# if ( request . user . id != snippet . author . id ) : #NEWLINE# #INDENT# return HttpResponseForbidden ( ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# template_name = 'cab/add_snippet.html' #NEWLINE# snippet = Snippet ( author = request . user , language = Language . objects . get ( name = 'Python' ) ) #NEWLINE# #UNINDENT# if ( request . method == 'POST' ) : #NEWLINE# #INDENT# form = SnippetForm ( instance = snippet , data = request . POST ) #NEWLINE# if form . is_valid ( ) : #NEWLINE# #INDENT# snippet = form . save ( ) #NEWLINE# messages . info ( request , 'Your snippet has been saved' ) #NEWLINE# return redirect ( snippet ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# form = SnippetForm ( instance = snippet ) #NEWLINE# #UNINDENT# return render ( request , template_name , { #NEWLINE# #INDENT# 'form' : form , #NEWLINE# #UNINDENT# } )