#NEWLINE# @ login_required #NEWLINE# def location( request ) : #NEWLINE# #INDENT# '\n    Location selection of the user profile\n    ' #NEWLINE# ( profile , created ) = Profile . objects . get_or_create ( user = request . user ) #NEWLINE# geoip = hasattr ( settings , 'GEOIP_PATH' ) #NEWLINE# if ( geoip and ( request . method == 'GET' ) and ( request . GET . get ( 'ip' ) == '1' ) ) : #NEWLINE# #INDENT# from django.contrib.gis.utils import GeoIP #NEWLINE# g = GeoIP ( ) #NEWLINE# c = g . city ( request . META . get ( 'REMOTE_ADDR' ) ) #NEWLINE# if ( c and c . get ( 'latitude' ) and c . get ( 'longitude' ) ) : #NEWLINE# #INDENT# profile . latitude = ( '%.6f' % c . get ( 'latitude' ) ) #NEWLINE# profile . longitude = ( '%.6f' % c . get ( 'longitude' ) ) #NEWLINE# profile . country = c . get ( 'country_code' ) #NEWLINE# profile . location = unicode ( c . get ( 'city' ) , 'latin1' ) #NEWLINE# #UNINDENT# #UNINDENT# if ( request . method == 'POST' ) : #NEWLINE# #INDENT# form = LocationForm ( request . POST , instance = profile ) #NEWLINE# if form . is_valid ( ) : #NEWLINE# #INDENT# form . save ( ) #NEWLINE# messages . add_message ( request , messages . INFO , _ ( 'Your profile information has been updated successfully.' ) ) #NEWLINE# signal_responses = signals . post_signal . send ( sender = location , request = request , form = form ) #NEWLINE# last_reponse = signals . last_response ( signal_responses ) #NEWLINE# if last_reponse : #NEWLINE# #INDENT# return last_response #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# form = LocationForm ( instance = profile ) #NEWLINE# #UNINDENT# template = 'userprofile/profile/location.html' #NEWLINE# data = { #NEWLINE# #INDENT# 'section' : 'location' , #NEWLINE# 'GOOGLE_MAPS_API_KEY' : GOOGLE_MAPS_API_KEY , #NEWLINE# 'form' : form , #NEWLINE# 'geoip' : geoip , #NEWLINE# #UNINDENT# } #NEWLINE# signals . context_signal . send ( sender = location , request = request , context = data ) #NEWLINE# return render_to_response ( g , data , context_instance = RequestContext ( request ) )