def listDeleteView(list_id): ''' View to delete a single list ''' try: thelist = List.fetch_one(id=list_id, user_id=session['user_id']) List.delete(id=thelist.id, user_id=session['user_id']) status = 'ok' except NoResultFound: return flask.abort(403) return jsonify({'status': status})
def get_list_with_permission(list_id, user_id): try: thelist = List.fetch_one(id=list_id, user_id=user_id) list_owner = True except NoResultFound: thelist = FriendList.fetch_one( list_id=list_id, friend_email=user_id ) list_owner = False thelist = List.fetch_one(id=list_id) except NoResultFound: return flask.abort(403) return thelist, list_owner
def post(self, id_list): user = users.get_current_user() if user: list_to_edit = List.get_by_id(int(id_list)) if list_to_edit: list_to_edit.user = user.email() list_to_edit.name_list = self.request.get("name_list", "").strip() list_to_edit.description_list = self.request.get( "description_list", "").strip() # Chk if len(list_to_edit.name_list) < 1: self.redirect("/lists/update/" + id_list + "?error=1679091C5A880FAF6FB5E6087EB1B2DC") return elif list_to_edit.name_list == 'Favorites': self.redirect("/lists/update/" + id_list + "?error=8F14E45FCEEA167A5A36DEDD4BEA2543") return elif len(list_to_edit.description_list) < 1: self.redirect("/lists/update/" + id_list + "?error=C9F0F895FB98AB9159F51FD0297E236D") return else: # Save list_mgt.update(list_to_edit) sleep(1) self.redirect( "/lists?info=6512BD43D9CAA6E02C990B0A82652DCA") else: self.redirect("/lists?error=C20AD4D76FE97759AA27A0C99BFF6710") else: self.redirect("/")
def get(self, id_list): user = users.get_current_user() if user: access_link = users.create_logout_url("/") try: message_danger = self.request.GET['error'] except: message_danger = None list_to_edit = List.get_by_id(int(id_list)) if not list_to_edit: self.redirect("/lists/?error=Error! List not found!") template_values = { "info": AppInfo, "user": user, "list": list_to_edit, "access_link": access_link, "message_danger": message_danger } jinja = jinja2.get_jinja2(app=self.app) self.response.write( jinja.render_template("/lists/update.html", **template_values)) else: self.redirect("/") return
def get(self, id_list): user = users.get_current_user() access_link = users.create_logout_url("/") try: message_success = Message.message.get(self.request.GET['info']) except: message_success = None try: message_danger = Message.message.get(self.request.GET['error']) except: message_danger = None if user: # Get the information from the list from its id list_select = List.get_by_id(int(id_list)) # Get all the movies that have the list id_movies = movielist_mgt.get_id_movies(user.email(), list_select.key.id()) # Build the request to the API to get the information of each movie that was in the list and save this information in movies_values array api_key = TMDB.tmdb_api_key movies_values = [] for id_movie in id_movies: url_movie = "https://api.themoviedb.org/3/movie/" + str( id_movie) + "?api_key=" + api_key + "&language=en-US" result = urlfetch.fetch(url_movie, method=urlfetch.GET) movie = json.loads(result.content) movies_values.append(movie) id_tvshows = movielist_mgt.get_id_tvshow(user.email(), list_select.key.id()) # Build the request to the API to get the information of each TV SHOW that was in the list and save this information in movies_values array tvshows_values = [] for id_tv in id_tvshows: url_movie = "https://api.themoviedb.org/3/tv/" + str( id_tv) + "?api_key=" + api_key + "&language=en-US" result = urlfetch.fetch(url_movie, method=urlfetch.GET) tvshow = json.loads(result.content) tvshows_values.append(tvshow) template_values = { "info": AppInfo, "user": user, "access_link": access_link, "list": list_select, "movies": movies_values, "tvshows": tvshows_values, "message_success": message_success, "message_danger": message_danger, } jinja = jinja2.get_jinja2(app=self.app) self.response.write( jinja.render_template("/lists/seeListMovies.html", **template_values)) else: self.redirect("/")
def createListView(): status = None message = None redirect_url = None form = request.form.to_dict() form.update({'user_id': session['user_id'], }) try: new_list = List.create(form) status = 'ok' message = 'added item to list' redirect_url = '/list/' + str(new_list.id) + '/details' except Exception, e: status = 'error' message = str(e)
def userListsView(): ''' Main view a user goes to to see all of their lists ''' error = None lists = List.fetch_all(user_id=session['user_id']) user_lists = dict_lists(lists) rendered_lists = [] for num, lst in user_lists.iteritems(): rendered_lists.append( render_html('wishlist/list/summary.html', lst=lst) ) return render_template( 'lists_home.html', error=error, user_lists=rendered_lists )
def create_list(): json = request.get_json() id = db.create_id('lists') title = json['title'] id_user = json['id_user'] if (db.verify_register('lists', 'id', id)): return jsonify(error(400, 'List already exists')) else: # create instance list_user = List(id, id_user, title, datetime.datetime.utcnow()) # insert into database if(db.insert('lists', list_user.to_dict())): return jsonify(list_user.to_dict()) else: return jsonify(error(203, 'Not Allowed'))
def create_list(): json = request.get_json() id = db.create_id("lists") title = json["title"] id_user = json["id_user"] if not db.verify_register("users", "id", id_user): return jsonify(error(400, "User not exists")) elif db.verify_register("lists", "id", id): return jsonify(error(400, "List already exists")) else: # create instance list_user = List(id, id_user, title, datetime.datetime.utcnow()) # insert into database if db.insert("lists", list_user.to_dict()): return jsonify(list_user.to_dict()) else: return jsonify(error(203, "Not Allowed"))
def get(self, id_list, id_movie): user = users.get_current_user() if user: list_select = List.get_by_id(int(id_list)) if list_select: movieList_to_delete = movielist_mgt.get_item( user.email(), int(id_list), int(id_movie)) if movieList_to_delete: # Delete movieList_to_delete.key.delete() sleep(1) self.redirect("/lists/" + id_list + "?info=4E732CED3463D06DE0CA9A15B6153677") else: self.redirect( "/lists?error=02E74F10E0327AD868D138F2B4FDD6F0") else: self.redirect("/lists?error=C20AD4D76FE97759AA27A0C99BFF6710") else: self.redirect("/")
def post(self, id_list): user = users.get_current_user() if user: list_to_delete = List.get_by_id(int(id_list)) if list_to_delete: # Get all the movies vinculated with the list to delete delete_movies = movielist_mgt.delete_all_movies_for_list( user.email(), list_to_delete.key.id()) if not delete_movies: self.redirect( "/lists?error=C51CE410C124A10E0DB5E4B97FC2AF39") else: # Delete the list list_to_delete.key.delete() sleep(1) self.redirect( "/lists?info=AAB3238922BCC25A6F606EB525FFDC56") else: self.redirect("/lists?error=C20AD4D76FE97759AA27A0C99BFF6710") else: self.redirect("/")
def update_list(id_list): if request.method == "POST": # query for check username query_db = db.read("lists", "id", id_list) list_user = query_db[0] if len(query_db) == 1 else None if list_user == None: return jsonify(error(404, "List not exists")) else: json = request.get_json() id = list_user["id"] title = json["title"] date = list_user["date"] id_user = list_user["id_user"] link = list_user["link"] list_user = List(id, id_user, title, date) if db.update("lists", id_list, list_user.to_dict()): return jsonify(list_user.to_dict()) else: return jsonify(error(203, "Not Allowed"))
response = requests.post(URL_CREATE_TASK, data=jsonArray) return json.loads(response.content) def create_list(list): jsonArray = json.dumps(list.to_dict()) response = requests.post(URL_CREATE_LIST, data=jsonArray) return json.loads(response.content) if __name__ == '__main__': # login user = User(1, 'lulu', 'luis', '*****@*****.**', '11/11/2011') user = create_user(user) # make list list_user = List(1, user['id'], 'title', '11/11/2011') list_user = create_list(list_user) # make task task = Task(1, list_user['id'], list_user['title'], 'description', '11/11/2011', 'status') task = create_task(task)
def post(self, id_movie): if self.request.GET['type'] == "f263d9a8b7cb4a9e573c18e5b9e15091": route = "/tv/" + id_movie else: route = "/movies/" + id_movie user = users.get_current_user() if user: # First, we remove the content from the user lists for the given movie delete_movies = movielist_mgt.delete_movie_in_lists( user.email(), int(id_movie)) if not delete_movies: self.redirect(route + "?error=9BF31C7FF062936A96D3C8BD1F8F2FF3") # Then, we get the new assignations from form lists_form = self.request.get("list[]", allow_multiple=True) if lists_form: # We built each movie and added it to the correct list for list_id in lists_form: list_select = List.get_by_id(int(list_id)) if not list_select: self.redirect( route + "?error=C74D97B01EAE257E44AA9D5BADE97BAF") movie_to_add_list = movielist_mgt.get_item( user.email(), list_select.key.id(), int(id_movie)) if movie_to_add_list: self.redirect( route + "?error=70EFDF2EC9B086079795C442636B55FB") else: movie_to_add_list = movielist_mgt.create_empty_movie_list( ) movie_to_add_list.user = user.email() movie_to_add_list.id_movie = int(id_movie) movie_to_add_list.id_list = list_select.key.id() if "movies" in route: movie_to_add_list.type_movie = "Movie" else: movie_to_add_list.type_movie = "TV Show" # Chk if len(movie_to_add_list.user) < 1: self.redirect( route + "?error=C4CA4238A0B923820DCC509A6F75849B") if movie_to_add_list.id_movie: self.redirect( route + "?error=C81E728D9D4C2F636F067F89CC14862C") if movie_to_add_list.id_list: self.redirect( route + "?error=37693CFC748049E45D87B8C7D8B9AACD") # Save movielist_mgt.update(movie_to_add_list) self.redirect(route + "?info=1FF1DE774005F8DA13F42943881C655F") else: self.redirect(route + "?info=8E296A067A37563370DED05F5A3BF3EC") else: self.redirect("/")