Beispiel #1
0
def addLibrary(user = None):
	name = request.form['name']
	library = Library.objects(user=user,unit='Movie',name=name).first()
	if library:
		return jsonify(response='error',message='Library with name %s already exists' % library.name),404
	library = Library(user=user,unit='Movie',name=name).save()
	return jsonify(response='success',type='redirect',path=url_for(endpoint='libraries',_external=True))
Beispiel #2
0
def addlibraryItem(name,user=None):
	from project.model.Movie import Movie
	
	library = Library.objects(user=user,name=name,unit='Movie').first()
	if not library:
		return jsonify(response='error',message='Unable to find the given Library'),404
	
	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(tmdb_id=movie_id).first()
	if movie:
		if library.name != 'Master':
			master = Library.objects(user=user,name="Master",unit='Movie').first()
			master.addUnit(movie)
		library.addUnit(movie)
		return jsonify(response='success',type='redirect',path=url_for(endpoint='library',name=name,_external=True))

	from tmdb3 import Movie as tmdbMovie
	movie = tmdbMovie(movie_id)
	if not movie:
		return jsonify(response='error',message='Invalid Movie given'),404
	
	from project.model.Movie import Movie
	movie = Movie.convertMovie(movie)	
	library.addUnit(movie)
	if library.name != 'Master':
			master = Library.objects(user=user,name="Master",unit='Movie').first()
			master.addUnit(movie)

	return jsonify(response='success',type='redirect',path=url_for(endpoint='library',name=name,_external=True))
Beispiel #3
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")
Beispiel #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")
Beispiel #5
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")
Beispiel #6
0
def loaned(user=None):
    from project.model.Movie import Movie
    from project.model.Library import Library

    library = Library.objects(user=user, name="Loaned", unit="Movie").first()
    if not library:
        return render_template("404.html", message="Unable to find given Library", user=user), 404
    return render_template("library/library.html", library=library, user=user)
Beispiel #7
0
def movies(user=None):
    from project.model.Movie import Movie
    from project.model.Library import Library
    library = Library.objects(user=user, name="Master", unit='Movie').first()
    if not library:
        return render_template('404.html',
                               message='Unable to find given Library',
                               user=user), 404
    return render_template('library/library.html', library=library, user=user)
Beispiel #8
0
def libraryItem(name, index,user=None):
	from project.model.Movie import Movie
	library = Library.objects(user=user,name=name,unit='Movie').first()
	if not library:
		return render_template('404.html',message='Unable to find given Library',user=user),404
	movie = library.hydrateUnit(index-1)
	if not movie:
		return render_template('404.html',message='Unable to find given Movie',user=user),404
	return render_template('library/libraryItem.html',item=movie,user=user,library=library,index=index)
Beispiel #9
0
def removeLibrary(user = None):
	name = request.form['name']
	library = Library.objects(user=user,unit='Movie',name=name).first()
	if not library:
		return jsonify(response='error',message='Library requested does not exists'),404
	if library.name == 'Master' or library.name == 'Loaned':
		return jsonify(response='error',message='Library %s cannot be deleted' % library.name),404
	library.delete()
	return jsonify(response='success',type='redirect',path=url_for(endpoint='libraries',_external=True))	
Beispiel #10
0
def removelibraryItem(name,user=None):
	from project.model.Movie import Movie
	library = Library.objects(user=user,name=name,unit='Movie').first()
	if not library:
		return jsonify(response='error',message='Unable to find the given Library'),404
	index = int(request.form['id'])
	if not index:
		return jsonify(response='error',message='Invalid parameters'),404
	movie = library.hydrateUnit(index-1)
	if not movie:
		return jsonify(response='error',message='Unable to find the given Movie in Library %s' % library.name),404
	
	if library.name == 'Master':
		libraries = Library.objects(user=user,unit='Movie')
		for library in libraries:
			library.removeUnit(movie)
	else:		
		library.removeUnit(movie)

	return jsonify(response='success',type='redirect',path=url_for(endpoint='library',name=name,_external=True))
Beispiel #11
0
def signup():
    email = request.form['email']
    password = request.form['password']
    passwordConfirm = request.form['passwordConfirm']

    if password != passwordConfirm:
        error = "The passwords you entered did not match. Please try again."
        return jsonify(response='error', message=error), 400

    if len(User.objects(email=email)) > 0:
        error = "The email provided is already in use with another account."
        return jsonify(response='error', message=error), 400

    from project.model.Library import Library
    user = User.createUser(email, password)
    user.addRole('user').save()
    session['user'] = user.toJSON()
    Library(user=user, unit='Movie', name='Master').save()
    Library(user=user, unit='Movie', name='Loaned').save()
    return jsonify(response='success',
                   type='redirect',
                   path=url_for(endpoint='libraries', _external=True))
Beispiel #12
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")
Beispiel #13
0
def library(name,user=None):
	from project.model.Movie import Movie
	library = Library.objects(user=user,name=name,unit='Movie').first()
	if not library:
		return render_template('404.html',message='Unable to find given Library',user=user),404
	return render_template('library/library.html',library=library,user=user)
Beispiel #14
0
def libraries(user = None):
	libraries = Library.objects(user=user,unit='Movie')
	return render_template('library/master.html', libraries=libraries,user=user)