#NEWLINE# @ login_required ( ) #NEWLINE# def user_settings_avatar( request ) : #NEWLINE# #INDENT# if ( request . method == 'POST' ) : #NEWLINE# #INDENT# upload_avatar_form = UserAvatarForm ( request . POST , request . FILES ) #NEWLINE# if ( 'bavatar' in request . POST ) : #NEWLINE# #INDENT# if upload_avatar_form . is_valid ( ) : #NEWLINE# #INDENT# avatar = UserAvatar ( user = request . user ) #NEWLINE# avatar . save ( ) #NEWLINE# image_file = request . FILES [ 'avatar' ] #NEWLINE# avatar . avatar . save ( image_file . name , avatar ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( 'bdelavatar' in request . POST ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# UserAvatar . objects . get ( user = request . user ) . delete ( ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# upload_avatar_form = UserAvatarForm ( ) #NEWLINE# #UNINDENT# extra_context = user_settings_intialize ( request ) #NEWLINE# extra_context [ 'upload_avatar_form' ] = upload_avatar_form #NEWLINE# context = RequestContext ( request ) #NEWLINE# return render_to_response ( 'account/user_profile_avatar.html' , extra_context , context_instance = context )