Exemple #1
0
def handle_checkin(student, body):
    # Make sure they actually have a bike out
    if not student.ride_set.filter(checkin_time=None):
        try:
            ride = student.ride_set.latest("checkin_time")
        except:
            return "You have never checked out a bike. Check out a bike using the 'checkout (number)'. Once you have done that, use this command to return it."

        checkin_display_time = timezone.localtime(ride.checkin_time)
        time_of_day = "{}:{}".format(checkin_display_time.hour, checkin_display_time.minute)
        return "You don't have any rides to check in. Your last ride was checked in at {} at {}.".format(time_of_day, ride.checkin_station)

    # Get their location and check the bike in
    location = None
    stations = Station.objects.all()
    for station in stations:
        if station.name.lower() in body or (station.full_name and station.full_name.lower() in body):
            location = station
    if not location:
        email_razzi("Station didn't match for checkin. Message was {}".format(body))
        message = "Station not found. Options: Rodin, Ware, Huntsman, Fisher, College Hall, Hill, PSA. To return text 'Checkin Hill' or another station."
        return message
    ride = student.ride_set.latest("checkout_time")
    checkin_ride(ride, location)
    message = "You have successfully returned your bike at {}. Make sure it is locked, and we will confirm the bike's checkin location shortly. Thanks!".format(location)
    return message
def checkin(request):
    location = request.POST.get("station")
    penncard = request.POST.get("penncard")
    try:
        station = Station.objects.filter(active=True).get(name=location)
    except:
        logger.warn('Station missing: {}'.format(location))
        return json_failure("Station not found.")
    try:
        student = Student.objects.get(penncard=penncard)
    except Student.DoesNotExist:
        logger.warn('Student missing: {}'.format(penncard))
        return json_failure("No student with that PennCard was found.")
    ride = student.ride_set.latest()
    checkin_ride(ride, station)
    return HttpResponse()