#NEWLINE# @ user_passes_test ( ( lambda u : u . is_staff ) ) #NEWLINE# def add( request ) : #NEWLINE# #INDENT# '\n    Add news items to the home page.\n    ' #NEWLINE# if ( request . method == 'POST' ) : #NEWLINE# #INDENT# form = AddItemForm ( data = request . POST ) #NEWLINE# if form . is_valid ( ) : #NEWLINE# #INDENT# item = form . save ( commit = False ) #NEWLINE# item . reporter = request . user #NEWLINE# try : #NEWLINE# #INDENT# with transaction . atomic ( ) : #NEWLINE# #INDENT# item . save ( ) #NEWLINE# #UNINDENT# #UNINDENT# except twitter . TwitterError as e : #NEWLINE# #INDENT# messages . error ( request , ( 'Twitter error: "%s" Please try again.' % e . message [ 0 ] [ 'message' ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# messages . info ( item , 'Your news item has been published!' ) #NEWLINE# return redirect ( 'home' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# form = AddItemForm ( ) #NEWLINE# #UNINDENT# return render ( request , 'form.html' , { #NEWLINE# #INDENT# 'title' : 'Add Item' , #NEWLINE# 'form' : form , #NEWLINE# 'description' : 'Enter the details for the news item below.' , #NEWLINE# 'action' : 'Add' , #NEWLINE# #UNINDENT# } )