#NEWLINE# def change( request , extra_context = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , next_override = None ) : #NEWLINE# #INDENT# avatars = Avatar . objects . filter ( user = request . user ) . order_by ( '-primary' ) #NEWLINE# if ( avatars . count ( ) > 0 ) : #NEWLINE# #INDENT# avatar = avatars [ 0 ] #NEWLINE# kwargs = { #NEWLINE# #INDENT# 'initial' : { #NEWLINE# #INDENT# 'choice' : avatar . id , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# avatar = None #NEWLINE# kwargs = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# primary_avatar_form = PrimaryAvatarForm ( ( next_override . POST or None ) , user = request . user , ** kwargs ) #NEWLINE# if ( request . method == 'POST' ) : #NEWLINE# #INDENT# updated = False #NEWLINE# if ( 'avatar' in request . FILES ) : #NEWLINE# #INDENT# path = avatar_file_path ( user = request . user , filename = request . FILES [ 'avatar' ] . name ) #NEWLINE# avatar = Avatar ( user = request . user , primary = True , avatar = path ) #NEWLINE# new_file = avatar . avatar . storage . save ( path , request . FILES [ 'avatar' ] ) #NEWLINE# avatar . save ( ) #NEWLINE# updated = True #NEWLINE# messages . success ( request , message = _ ( 'Successfully uploaded a new avatar.' ) ) #NEWLINE# #UNINDENT# 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# messages . success ( request , message = _ ( 'Successfully updated your avatar.' ) ) #NEWLINE# #UNINDENT# return HttpResponseRedirect ( ( next_override or _get_next ( request ) ) ) #NEWLINE# #UNINDENT# return render_to_response ( 'avatar/change.html' , extra_context , context_instance = RequestContext ( request , { #NEWLINE# #INDENT# 'avatar' : avatar , #NEWLINE# 'avatars' : avatars , #NEWLINE# 'primary_avatar_form' : primary_avatar_form , #NEWLINE# 'next' : ( next_override or _get_next ( request ) ) , #NEWLINE# #UNINDENT# } ) )