Ejemplo n.º 1
0
def api_user_backpack(request):
    """
        Return the user's backpack. Requires authentication
        
        :return: Suggestions
    """
    backpack = Suggestion.objects.get_backpack(follower=request.user)
    return Suggestion.serialize_to_json(backpack)
Ejemplo n.º 2
0
def api_suggestion_detail(request, pk):
    """
        Returns a suggestion
        ignored
        :param lat: Latitude
        :type username: float
        :param lon: Longitude 
        :type lon: float
        
        :return: Suggestion
    """
    suggestion = Suggestion.objects.filter(pk=pk, _vis='public')
    return Suggestion.serialize_to_json(suggestion)
Ejemplo n.º 3
0
def api_suggestion_add(request, name, description, place):
    place_obj = None
    if type(place) == type(0):
        place_obj = Place.objects.filter(pk=place)
    if place_obj is None:
        place_obj = Place.objects.create_from_google(
                                 google_places_reference = place,
                                 user = request.user
                                 )
        
    data = {
            'name': name,
            'description': description,
            'visibility': 'public',
            }
    form = SuggestionForm(data)
    if form.is_valid():
        suggestion = form.save(user=request.user, place=place_obj)
        return Suggestion.serialize_to_json([suggestion])
    return form.errors
Ejemplo n.º 4
0
def api_suggestions_near(request, lat, lon, accuracy=100):
    """
        Returns the suggestions near to the location
        
        :param lat: Latitude
        :type username: float
        :param lon: Longitude 
        :type lon: float
        :param accuracy: max distance requested (in meters)
        :type accuracy: integer
        
        
        :return: 
            >>> suggestions_near(37,-3,500000)
                Requesting ->
                    {"id":"jsonrpc", "params":[37, -3, 500000], "method":"suggestions_near", "jsonrpc":"1.0"}
                Got ->
                    {"error": null, "jsonrpc": "1.0", "id": "jsonrpc", "result": "[{\"pk\": 4, \"model\": \"events.suggestion\", \"fields\": {\"user\": [1, \"admin\"], \"place\": [4, \"GeoRemindMe!\", \"Avenida de la Innovaci\u00f3n 1, CADE, M\u00f3dulo 11, 18100 Armilla, Granada, Espa\u00f1a\", \"Armilla\", [37.147712, -3.609319], \"92e1cc75513c4dcac6a6d0f72b2632150d4d3115\"], \"name\": \"visita georemindme\", \"description\": \"\"}}]"}
    """
    suggestions = Suggestion.objects.nearest_to(lat=lat, lon=lon, accuracy=accuracy)
    return Suggestion.serialize_to_json(suggestions)