예제 #1
0
def findReservation(memberId, carId, status):
    '''Find reservation matching member id, car id and status.

    Parameters
    ----------
    memberId : int
        Member id.
    carId : int
        Car id.
    status : int
        Reservation status.

    Returns
    -------
    dict
        Reservation dict if session is valid. Otherwise, None.
    '''

    params = {"memberId": memberId, "carId": carId, "status": status}
    resp = rest.get("reservation", params=params)
    if resp is None or resp["error"] is not None:
        return None

    nowDt = datetime.utcnow()
    reservations = resp["body"]
    for reservation in reservations:
        rsvDt = webdata.strToDatetime(reservation["reservedTime"])
        rtnDt = rsvDt + timedelta(hours=reservation["reservedHours"])
        if nowDt >= rsvDt and nowDt < rtnDt:
            return reservation

    return None
예제 #2
0
def cancel():
    '''Reserve URI.

    Parameters for GET method
    -------------------------
    id : int
        Reservation id.
    '''

    member = security.verifySession(session)
    if member is None:
        return redirect(url_for(".welcome"))

    keyTypes = {"id": int}
    params = webdata.parseInput(request.args, keyTypes)
    params["status"] = -1
    resp = rest.put("reservation", data=params)
    if resp is None or resp["error"] is not None:
        error = True
    else:
        reservation = resp["body"]
        reservation["reservedTime"] = webdata.strToDatetime(
            reservation["reservedTime"])
        #if not current_app.testing:
        #    calendar.deleteEvent(session["credentials"], member, reservation)
        error = False

    return render_template("cancel.html", error=error, member=member)
예제 #3
0
def reserve():
    '''Reserve URI.

    Parameters for GET method
    -------------------------
    id : int
        Car id

    Parameters for POST method
    --------------------------
    carId : int
        Car id.
    reservedTime : str
        Time when the car can be unlocked.
    reservedHours : int
        Hours that the car is reserved for.
    '''

    member = security.verifySession(session)
    if member is None:
        return redirect(url_for(".welcome"))

    error = None
    if request.method == "GET":
        keyTypes = {"id": int}
        params = webdata.parseInput(request.args, keyTypes)
        car = getCar(params["id"])
        if car is None or not car["available"]:
            error = True
    else:  # POST
        keyTypes = {
            "carId": int,
            "reservedTime": "datetime",
            "reservedHours": int
        }
        params = webdata.parseInput(request.form, keyTypes)
        params["memberId"] = member["id"]
        params["reservedTime"] = webdata.convertLocalToUtc(
            params["reservedTime"])
        car = getCar(params["carId"])
        if car is None or not car["available"]:
            error = True
        else:
            resp = rest.post("reservation", data=params)
            if resp is None or resp["error"] is not None:
                error = True
            else:
                reservation = resp["body"]
                reservation["reservedTime"] = webdata.strToDatetime(
                    reservation["reservedTime"])
                #if not current_app.testing:
                #    calendar.insertEvent(session["credentials"], member, car, reservation)
                error = False

    return render_template("reserve.html", error=error, member=member, car=car)
예제 #4
0
def manager():

    member = security.verifySession(session)
    if member is None:
        return redirect(url_for(".welcome"))

    #All members
    resp = rest.get("allMembers")
    if resp is None or resp["error"] is not None:
        members = None
    else:
        members = resp["body"]

    #All cars
    resp = rest.get("car")
    if resp is None or resp["error"] is not None:
        cars = None
    else:
        cars = resp["body"]

    #All reservations
    resp = rest.get("reservation")
    if resp is None or resp["error"] is not None:
        reservations = None
    else:
        reservations = resp["body"]

    if reservations is not None:
        for reservation in reservations:
            params = {"id": reservation["carId"]}
            resp = rest.get("car", params=params)
            if resp is None or resp["error"] is not None:
                reservation["car"] = None
            else:
                reservation["car"] = resp["body"][0]

            reservation["reservedTime"] = webdata.strToDatetime(
                reservation["reservedTime"])
            reservation["reservedTime"] = webdata.convertUtcToLocal(
                reservation["reservedTime"])
            reservation["reservedTimeStr"] = webdata.datetimeToStr(
                reservation["reservedTime"])
            reservation["statusStr"] = webdata.statusToStr(
                reservation["status"])

    return (render_template("manager.html",
                            staff=member,
                            members=members,
                            cars=cars,
                            reservations=reservations))
예제 #5
0
def history():
    '''Reserve URI.

    Parameters for GET method
    -------------------------
    None
    '''

    member = security.verifySession(session)
    if member is None:
        return redirect(url_for(".welcome"))
    else:
        staff = member

    if request.method == "GET":
        keyTypes = {"id": int}
        params = webdata.parseInput(request.args, keyTypes)
        resp = rest.get("member", params=params)
        for m in resp['body']:
            member = m

    params = {"memberId": member["id"]}
    resp = rest.get("reservation", params=params)
    if resp is None or resp["error"] is not None:
        reservations = None
    else:
        reservations = resp["body"]

    if reservations is not None:
        for reservation in reservations:
            params = {"id": reservation["carId"]}
            resp = rest.get("car", params=params)
            if resp is None or resp["error"] is not None:
                reservation["car"] = None
            else:
                reservation["car"] = resp["body"][0]

            reservation["reservedTime"] = webdata.strToDatetime(
                reservation["reservedTime"])
            reservation["reservedTime"] = webdata.convertUtcToLocal(
                reservation["reservedTime"])
            reservation["reservedTimeStr"] = webdata.datetimeToStr(
                reservation["reservedTime"])
            reservation["statusStr"] = webdata.statusToStr(
                reservation["status"])

    return render_template("history.html",
                           staff=staff,
                           member=member,
                           reservations=reservations)