def join_run_event_api(request): event_id = request.GET['event_id'] event = RunParticipants.objects.filter(run_id=event_id,participants=request.user) if not event: join = RunParticipants(run_id_id=event_id,participants=request.user) join.save() return HttpResponse(simplejson.dumps({'response':'Success'}),status=200,mimetype='application/json')
def add_run_event_api(request): run_date = request.GET['date'] run_time = request.GET['time'] #.upper() date = make_datetime(run_date,run_time) creator = request.user start_location = request.GET['start_location'] end_location = request.GET['end_location'] pace = request.GET['pace'] if request.GET['pace'].find(":") > -1 else request.GET['pace'] + ":00" pace_int = int(pace.split(":")[0]) * 60 + int(pace.split(":")[1]) distance = float(request.GET['distance']) #create a new run new_event = Run(date=date,creator=creator,start_location=start_location,end_location=end_location,pace=pace_int,distance=distance) new_event.save() #add the creator as a participant new_participant = RunParticipants(run_id=new_event,participants=request.user) new_participant.save() return HttpResponse(simplejson.dumps({'response':'Success'}),status=200,mimetype='application/json')