def put(self, list_id, movie_id, session=None): """ Sets movie identifiers """ try: movie = ml.get_movie_by_id(list_id=list_id, movie_id=movie_id, session=session) except NoResultFound: return { 'status': 'error', 'message': 'could not find movie with id %d in list %d' % (movie_id, list_id) }, 404 data = request.json # Validates ID type based on allowed ID # TODO pass this to json shcema validation for id_name in data: if set(id_name.keys()) & set(allowed_ids) == set([]): return { 'status': 'error', 'message': 'movie identifier %s is not allowed' % id_name }, 501 movie.ids[:] = ml.get_db_movie_identifiers(identifier_list=data, movie_id=movie_id, session=session) session.commit() return jsonify(movie.to_dict())
def get(self, list_id, movie_id, session=None): """ Get a movie by list ID and movie ID """ try: movie = ml.get_movie_by_id(list_id=list_id, movie_id=movie_id, session=session) except NoResultFound: raise NotFoundError("could not find movie with id %d in list %d" % (movie_id, list_id)) return jsonify(movie.to_dict())
def movie_list_del(options): with Session() as session: try: movie_list = plugin_movie_list.get_list_by_exact_name( options.list_name) except NoResultFound: console('Could not find movie list with name {}'.format( options.list_name)) return try: movie_exist = plugin_movie_list.get_movie_by_id( list_id=movie_list.id, movie_id=int(options.movie), session=session) except NoResultFound: console('Could not find movie with ID {} in list `{}`'.format( int(options.movie), options.list_name)) return except ValueError: title, year = split_title_year(options.movie) movie_exist = plugin_movie_list.get_movie_by_title_and_year( list_id=movie_list.id, title=title, year=year, session=session) if not movie_exist: console('Could not find movie with title {} in list {}'.format( options.movie, options.list_name)) return else: console('Removing movie {} from list {}'.format( movie_exist.title, options.list_name)) session.delete(movie_exist)
def get(self, list_id, movie_id, session=None): """ Get a movie by list ID and movie ID """ try: movie = ml.get_movie_by_id(list_id=list_id, movie_id=movie_id, session=session) except NoResultFound: return {'status': 'error', 'message': 'could not find movie with id %d in list %d' % (movie_id, list_id)}, 404 return jsonify(movie.to_dict())
def delete(self, list_id, movie_id, session=None): """ Delete a movie by list ID and movie ID """ try: movie = ml.get_movie_by_id(list_id=list_id, movie_id=movie_id, session=session) except NoResultFound: raise NotFoundError("could not find movie with id %d in list %d" % (movie_id, list_id)) log.debug("deleting movie %d", movie.id) session.delete(movie) return success_response("successfully deleted movie %d" % movie_id)
def get(self, list_id, movie_id, session=None): """ Get a movie by list ID and movie ID """ try: movie = ml.get_movie_by_id(list_id=list_id, movie_id=movie_id, session=session) except NoResultFound: raise NotFoundError('could not find movie with id %d in list %d' % (movie_id, list_id)) return jsonify(movie.to_dict())
def delete(self, list_id, movie_id, session=None): """ Delete a movie by list ID and movie ID """ try: movie = ml.get_movie_by_id(list_id=list_id, movie_id=movie_id, session=session) except NoResultFound: return {'status': 'error', 'message': 'could not find movie with id %d in list %d' % (movie_id, list_id)}, 404 log.debug('deleting movie %d', movie.id) session.delete(movie) return {}
def delete(self, list_id, movie_id, session=None): """ Delete a movie by list ID and movie ID """ try: movie = ml.get_movie_by_id(list_id=list_id, movie_id=movie_id, session=session) except NoResultFound: raise NotFoundError('could not find movie with id %d in list %d' % (movie_id, list_id)) log.debug('deleting movie %d', movie.id) session.delete(movie) return success_response('successfully deleted movie %d' % movie_id)
def put(self, list_id, movie_id, session=None): """ Sets movie identifiers """ try: movie = ml.get_movie_by_id(list_id=list_id, movie_id=movie_id, session=session) except NoResultFound: raise NotFoundError("could not find movie with id %d in list %d" % (movie_id, list_id)) data = request.json # Validates ID type based on allowed ID for id_name in data: if list(id_name)[0] not in MovieListBase().supported_ids: raise BadRequest("movie identifier %s is not allowed" % id_name) movie.ids[:] = ml.get_db_movie_identifiers(identifier_list=data, movie_id=movie_id, session=session) session.commit() return jsonify(movie.to_dict())
def put(self, list_id, movie_id, session=None): """ Sets movie identifiers """ try: movie = ml.get_movie_by_id(list_id=list_id, movie_id=movie_id, session=session) except NoResultFound: return {'status': 'error', 'message': 'could not find movie with id %d in list %d' % (movie_id, list_id)}, 404 data = request.json # Validates ID type based on allowed ID # TODO pass this to json shcema validation for id_name in data: if set(id_name.keys()) & set(allowed_ids) == set([]): return {'status': 'error', 'message': 'movie identifier %s is not allowed' % id_name}, 501 movie.ids[:] = ml.get_db_movie_identifiers(identifier_list=data, movie_id=movie_id, session=session) session.commit() return jsonify(movie.to_dict())
def put(self, list_id, movie_id, session=None): """ Sets movie identifiers """ try: movie = ml.get_movie_by_id(list_id=list_id, movie_id=movie_id, session=session) except NoResultFound: raise NotFoundError('could not find movie with id %d in list %d' % (movie_id, list_id)) data = request.json # Validates ID type based on allowed ID for id_name in data: if list(id_name)[0] not in MovieListBase().supported_ids: raise BadRequest('movie identifier %s is not allowed' % id_name) movie.ids[:] = ml.get_db_movie_identifiers(identifier_list=data, movie_id=movie_id, session=session) session.commit() return jsonify(movie.to_dict())
def movie_list_del(options): with Session() as session: try: movie_list = get_list_by_exact_name(options.list_name) except NoResultFound: console('Could not find movie list with name {}'.format(options.list_name)) return try: movie_exist = get_movie_by_id(list_id=movie_list.id, movie_id=int(options.movie), session=session) except NoResultFound: console('Could not find movie with ID {} in list `{}`'.format(int(options.movie), options.list_name)) return except ValueError: title, year = split_title_year(options.movie) movie_exist = get_movie_by_title_and_year(list_id=movie_list.id, title=title, year=year, session=session) if not movie_exist: console('Could not find movie with title {} in list {}'.format(options.movie, options.list_name)) return else: console('Removing movie {} from list {}'.format(movie_exist.title, options.list_name)) session.delete(movie_exist)