Example #1
0
def locate(request):
    """ Ajax view. Locates user and creates a Checkin. """
    if request.method == "POST":
        form = LocationForm(request.POST)
        if form.is_valid():
            try:
                the_checkin = form.save(request)
                request.session["location"] = the_checkin["location"]
                data = json.dumps(the_checkin, cls=MongoJSONEncoder)
            except Exception, e:
                data = json.dumps({"error": str(e)})
        else:
            data = json.dumps({"error": form.errors})
Example #2
0
def checkins(request, checkin_id=None):
    now = timezone.now().replace(hour=0, minute=1)
    db = get_checkins_db()

    if request.method == "GET" and checkin_id:
        data = db.find_one({"_id": checkin_id})
        if not data:
            raise Http404

    elif request.method == "GET" and not checkin_id:
        data = get_checkins(get_location(request))

    elif request.method == "POST" and not checkin_id:
        post_data = json.loads(request.POST.keys()[0])
        form = LocationForm(data=post_data["location"])
        if form.is_valid():
            data = form.save(request, geocode=post_data["geocode"][0])

    return HttpResponse(json.dumps(data, cls=MongoJSONEncoder))