#NEWLINE# @ login_required #NEWLINE# def change( request , extra_context = None , next_override = None , upload_form = UploadAvatarForm , primary_form = PrimaryAvatarForm , * 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# if avatar : #NEWLINE# #INDENT# kwargs = { #NEWLINE# #INDENT# 'initial' : { #NEWLINE# #INDENT# 'choice' : avatar . id , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# kwargs = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# upload_avatar_form = upload_form ( user = request . user , ** kwargs ) #NEWLINE# primary_avatar_form = primary_form ( ( request . POST or None ) , user = request . user , avatars = avatars , ** kwargs ) #NEWLINE# if ( request . method == 'POST' ) : #NEWLINE# #INDENT# updated = False #NEWLINE# if ( ( 'choice' in request . POST ) and primary_avatar_form . is_valid ( ) ) : #NEWLINE# #INDENT# avatar = Avatar . objects . get ( id = primary_avatar_form . cleaned_data [ 'choice' ] ) #NEWLINE# avatar . primary = True #NEWLINE# avatar . save ( ) #NEWLINE# updated = True #NEWLINE# invalidate_cache ( request . user ) #NEWLINE# messages . success ( request , _ ( 'Successfully updated your avatar.' ) ) #NEWLINE# #UNINDENT# if updated : #NEWLINE# #INDENT# avatar_updated . send ( sender = Avatar , user = request . user , avatar = avatar ) #NEWLINE# #UNINDENT# return redirect ( ( next_override or _get_next ( request ) ) ) #NEWLINE# #UNINDENT# context = { #NEWLINE# #INDENT# 'avatar' : avatar , #NEWLINE# 'avatars' : avatars , #NEWLINE# 'upload_avatar_form' : upload_avatar_form , #NEWLINE# 'primary_avatar_form' : primary_avatar_form , #NEWLINE# 'next' : ( next_override or _get_next ( request ) ) , #NEWLINE# #UNINDENT# } #NEWLINE# context . update ( extra_context ) #NEWLINE# return render ( request , 'avatar/change.html' , context )