Ejemplo n.º 1
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))