#NEWLINE# @ login_required #NEWLINE# def add( request , extra_context = None , next_override = None , upload_form = UploadAvatarForm , * args , **kwargs ) : #NEWLINE# #INDENT# if ( extra_context is None ) : #NEWLINE# #INDENT# extra_context = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# ( avatar , avatars ) = _get_avatars ( request . user ) #NEWLINE# upload_avatar_form = upload_form ( ( request . POST or None ) , ( request . FILES or None ) , user = request . user ) #NEWLINE# if ( ( request . method == 'POST' ) and ( 'avatar' in request . FILES ) ) : #NEWLINE# #INDENT# if upload_avatar_form . is_valid ( ) : #NEWLINE# #INDENT# avatar = Avatar ( user = request . user , primary = True ) #NEWLINE# image_file = request . FILES [ 'avatar' ] #NEWLINE# avatar . avatar . save ( image_file . name , image_file ) #NEWLINE# avatar . save ( ) #NEWLINE# messages . success ( request , _ ( 'Successfully uploaded a new avatar.' ) ) #NEWLINE# avatar_updated . send ( sender = Avatar , user = avatar . user , avatar = avatar ) #NEWLINE# return redirect ( ( next_override or _get_next ( request ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# context = { #NEWLINE# #INDENT# 'avatar' : avatar , #NEWLINE# 'avatars' : avatars , #NEWLINE# 'upload_avatar_form' : upload_avatar_form , #NEWLINE# 'next' : ( next_override or _get_next ( request ) ) , #NEWLINE# #UNINDENT# } #NEWLINE# context . update ( extra_context ) #NEWLINE# return render ( request , 'avatar/add.html' , context )