Пример #1
0
 def read(self, request, response=None):
     """
     Geocode  an address or reverse geocode a lat/lng pair
     API Handler: GET /services/geo
     GET Params:
         @address [string] the address you'd like to geocode
         @lat [latitude] the latitude you'd like to reverse geocode, required if address is not supplied
         @lng [longitude] the longitude you'd like to reverse geocode, required if address is not supplied
     """
     if not response:
         response = ResponseObject()
     address = request.GET.get('address')
     lat = request.GET.get('lat')
     lng = request.GET.get('lng')
     if address:
         get_coords = strToBool(request.GET.get('get_coords', 'True'))
         if hasattr(settings, 'GOOGLE_API_KEY'):
             geo_code = GeoCode(address)
         else:
             #just use the api key in the utils module
             geo_code = GeoCode(address)
         
         if get_coords:
             try:
                 response.set(result=geo_code.getCoords())
             except:
                 return response.send(errors='Invalid Address')
         else:
             result = geo_code.getResponse()
             if int(result['Status']['code']) == 200:
                 response.set(result=geo_code.getResponse())
             else:
                 return response.send(errors="Invalid Address")
     elif (lat and lng):
         address = ReverseGeoCode(latlng='%s,%s' % (lat, lng)).getAddress()
         response.set(address=address)
     else:
         return response.send(errors="Please provide a lat/lng pair or address")
     return response.send()
Пример #2
0
 def update(self, request, id, response):
     """
     Resolve a pending friend request
     API Handler: PUT /friends/requests/{id}
     Params:
        @id [id] friend request id
        @accept [boolean] accept? (optional, defaults to True)
     """
     profile = request.user.get_profile()
     try:
         friend_request = FriendRequest.objects.get(id=id, request_to=request.user.get_profile())
     except FriendRequest.DoesNotExist:
         return response.send(status=404)
     
     accept = utils.strToBool(request.PUT.get('accept', 'True'))
     
     if accept:
         profile.friends.add(friend_request.request_from)
         friend_request_accepted.send(sender=friend_request, profile=profile, profile_from=friend_request.request_from)
     else:
         friend_request_ignored.send(sender=friend_request, profile=profile, profile_from=friend_request.request_from)
     friend_request.delete()
     return response.send()