Esempio n. 1
0
def createLoan(user=None):
    from datetime import datetime

    borrower = request.form["email"]
    return_date = request.form["date"] or None
    movie_id = request.form["movie"]
    if return_date:
        return_date = datetime.strptime(return_date, "%m/%d/%Y")
        if return_date <= datetime.now():
            return jsonify(response="error", message="Return date must be in the future"), 404

    if not movie_id:
        return jsonify(response="error", message="Invalid Movie given"), 404
    from project.model.Movie import Movie

    movie = Movie.objects(id=movie_id).first()
    if not movie:
        return jsonify(response="error", message="Invalid Movie given"), 404

    from project.model.Loan import Loan

    loan = Loan.objects(user=user, movie=movie).first()
    if loan:
        return jsonify(response="error", message="A loan already exists for this movie"), 404

    loan = Loan.create(user, movie, borrower, return_date)
    from project.model.Library import Library

    borrowed_lib = Library.objects(user=user, unit="Movie", name="Loaned").first()
    borrowed_lib.addUnit(movie)

    return jsonify(response="success", type="reload")
Esempio n. 2
0
def createLoan(user=None):
    from datetime import datetime
    borrower = request.form['email']
    return_date = request.form['date'] or None
    movie_id = request.form['movie']
    if return_date:
        return_date = datetime.strptime(return_date, '%m/%d/%Y')
        if return_date <= datetime.now():
            return jsonify(response='error',
                           message='Return date must be in the future'), 404

    if not movie_id:
        return jsonify(response='error', message='Invalid Movie given'), 404
    from project.model.Movie import Movie
    movie = Movie.objects(id=movie_id).first()
    if not movie:
        return jsonify(response='error', message='Invalid Movie given'), 404

    from project.model.Loan import Loan
    loan = Loan.objects(user=user, movie=movie).first()
    if loan:
        return jsonify(response='error',
                       message='A loan already exists for this movie'), 404

    loan = Loan.create(user, movie, borrower, return_date)
    from project.model.Library import Library
    borrowed_lib = Library.objects(user=user, unit="Movie",
                                   name="Loaned").first()
    borrowed_lib.addUnit(movie)

    return jsonify(response='success', type="reload")
Esempio n. 3
0
def returnMovie(user=None):
    movie_id = request.form['id']

    if not movie_id:
        return jsonify(response='error', message='Invalid Movie given'), 404
    from project.model.Movie import Movie
    movie = Movie.objects(id=movie_id).first()
    if not movie:
        return jsonify(response='error', message='Invalid Movie given'), 404

    from project.model.Loan import Loan
    loan = Loan.objects(user=user, movie=movie).first()
    if not loan:
        return jsonify(
            response='error',
            message='This movie has not been loaned out and cannot be returned'
        ), 404

    from project.model.Library import Library
    borrowed_lib = Library.objects(user=user, unit="Movie",
                                   name="Loaned").first()
    borrowed_lib.removeUnit(movie)
    loan.delete()

    return jsonify(response='success', type="reload")
Esempio n. 4
0
def returnMovie(user=None):
    movie_id = request.form["id"]

    if not movie_id:
        return jsonify(response="error", message="Invalid Movie given"), 404
    from project.model.Movie import Movie

    movie = Movie.objects(id=movie_id).first()
    if not movie:
        return jsonify(response="error", message="Invalid Movie given"), 404

    from project.model.Loan import Loan

    loan = Loan.objects(user=user, movie=movie).first()
    if not loan:
        return jsonify(response="error", message="This movie has not been loaned out and cannot be returned"), 404

    from project.model.Library import Library

    borrowed_lib = Library.objects(user=user, unit="Movie", name="Loaned").first()
    borrowed_lib.removeUnit(movie)
    loan.delete()

    return jsonify(response="success", type="reload")