def my_function(): with app.app_context(): user = User.query.filter_by(username='******').first() partha = Recipe(name='Best Pizza Paratha', description='AMI Favorite', num_of_serving=60, cook_time=30, directions='Ask AMI about it.', user_id=user.id) db.session.add(partha) db.session.commit() biryani = Recipe(name='Mutton Biryani', description='Papa Loves It.', num_of_serving=60, cook_time=60, directions='Ask AMI about it.', user_id=user.id) db.session.add(biryani) db.session.commit()
def get(self, recipe_id=None, method=None): if method == "new_recipe": return self.get_new_recipe() ingredients = Recipe().get_ingredients(recipe_id) ingredients.append(self.get_ingredients_totals(ingredients)) data = { "ingredients": ingredients, "recipe_name": Recipe().get_name(recipe_id), "logged_in": request.user_id } return render_template("recipe.html", data=data)
def __init__(self, cat_name=None, owner=None): """ Initializing Category class instance variables""" self.cat_name = cat_name self.owner = owner self.regex_name = "[a-zA-Z- .]+$" self.recipe_categories = [] self.new_recipe = Recipe()
def add_recipes(n=100): for i in range(n): db.session.add(Recipe( name=fake.sentence(), description=fake.text(), user_id=random.choice(User.query.all()).id ))
def get(self): template_params = {} user = User.connect() user = User.checkUser() if not user: template_params['loginUrl'] = User.loginUrl('addrecipes') else: template_params['user'] = user.email template_params['logoutUrl'] = user.logoutUrl() recipe = Recipe() recipe.nameRecipe = self.request.get('nameRecipe') recipe.ingredients = self.request.get('ingredients') recipe.typeRecipe = self.request.get('typeRecipe') recipe.step = self.request.get('list_of_step') recipe.pic_url = self.request.get('pic_url') recipe.recipe_count = 0 recipe.user = user.email if self.request.get('nameRecipe'): recipe.put() most_recipes = Recipe.try_get_most_viewed() if (most_recipes): template_params['most_views'] = most_recipes html = template.render("web/templates/addRecipes.html", template_params) self.response.write(html)
def show(self): name_of_recipe = input("Enter name of recipe") items = select_ingredients() products = [] for i in items: products.append(i['ingredient']) recipe_ingredient = [] max_ingredients = count_ingrediets() while len(products) <= max_ingredients['items']: for i in items: print(i['id'], i['ingredient']) add_ingred = input("Enter ingrediente (# stop): ") if add_ingred == '#': break if add_ingred not in products: print("Not such ingredients, try again!") continue else: recipe_ingredient.append(add_ingred) print(recipe_ingredient) recipe = Recipe(id=None, recept=name_of_recipe, ingredients=json.dumps(recipe_ingredient)) result = insert_recipe(recipe) input('Recipe created! Press Enter...')
def post_create_recipe(): recipe_form = RecipeForm() if "picture" not in request.files: flash("No picture key in request.files", 'danger') return redirect(url_for('users.update_user')) file = request.files['picture'] if file.filename == '': flash("Please select a file", 'danger') return redirect(url_for('users.update_user')) if file and allowed_file(file.filename): file.filename = secure_filename(file.filename) output = upload_file_to_s3(file, app.config['S3_BUCKET']) # Have to disable as need to use ckeditor # if recipe_form.validate_on_submit(): result = request.form new_recipe = Recipe( user_id = current_user.id, picture=output, title = result['title'], description = result['content'] ) # breakpoint() new_recipe.save() flash("New recipe created", "success") return redirect(url_for('users.index')) flash("something went wrong, please try again", "warning") return render_template('new_recipe_form.html', recipe_form=recipe_form)
def get_new_recipe(self): data = { "ingredients": Recipe().get_all_ingredients(), "form": self.RecipeForm(), "logged_in": request.user_id } return render_template("new_recipe.html", data=data)
def create_recipe(self, query=None): if query is None: query = self.json if query is not None: for r in query.get('recipes', None): self.__cache_count += 1 img_url = r.get('image', None) try: if img_url: req = requests.get(img_url, stream=True, timeout=5) if req.status_code == 200: img_name = img_url.split('/')[-1] with open('images/' + img_name, 'wb') as img: req.raw.decode_content = True shutil.copyfileobj(req.raw, img) except Exception as e: print(e) exit(-1) attrs = dict( title=r.get('title'), image_url='images/' + img_name, source_url=r.get('sourceUrl'), cook_in_min=r.get("cookingMinutes"), prep_in_min=r.get("preparationMinutes"), dish_type=r.get("dishTypes"), ingredients=r.get("extendedIngredients"), servings=r.get("servings"), description=r.get("instructions"), api_id=r.get("id"), api_url=r.get("spoonacularSourceUrl") ) recipe = Recipe(**attrs) recipe.save()
def get(self): data = { # list of dicts with keys: recipe name, recipe id "recipes": Recipe().get_popular_recipes(), "logged_in": self.is_logged_in() } return render_template("index.html", data=data)
def add_recipe(self, title: str, prep_time: int, ingredients: list, preperation: list): for item in ingredients: item.capitalize() for item in preperation: item.capitalize() new_recipe = Recipe(title, prep_time, ingredients, preperation) self.insert_one(new_recipe.json()) return return_json(success=True)
def get_recipe(self, uuid): res = self.find_one({'recipe_uuid': uuid}) if not res: return False c_recipe = Recipe() c_recipe.from_mongo(res) return c_recipe
def create(): recipe = Recipe(name=request.form.get("recipe_name"), description=request.form.get("recipe_description")) if recipe.save(): flash("Recipe Name & Description Added") return redirect(url_for('ingredients.create')) else: flash("An error occured") return render_template('recipes/new.html')
def test_like_recipe(self): new_r = dict( id="abcd", title="a new recipe" ) r = Recipe(**new_r) r.save() r.like() self.assertIsNotNone(models.storage.get("Recipe", "abcd", "fav"))
def get(self): data = { "recipes": Recipe().get_all_recipes(request.user_id), "logged_in": request.user_id } print data return render_template("recipes.html", data=data)
def get_recipes(self): recipes = self.find_all() r_recipes = [] for l_recipe in recipes: new_recipe = Recipe() new_recipe.from_mongo(l_recipe) r_recipes.append(new_recipe.json()) return r_recipes
def setUp(self): """Defining setUp() method that runs prior to each test.""" self.newRecipe = Recipe() self.newCategory = Categories() self.recipe_register = self.newRecipe.recipe_register( "category", "recipe", "*****@*****.**", "recipe_ingredients", "recipe_methods") self.newCategory.category_register("category_one", "*****@*****.**") app.config['TESTING'] = True self.test_app = app.test_client()
def test_Dislike_recipe(self): new_r = dict( id="xyz", title="I don't like you!" ) r = Recipe(**new_r) r.save() r.dislike() self.assertIsNone(models.storage.get("Recipe", "xzy")) self.assertIsNone(models.storage.get("Recipe", "xzy", "fav"))
def post(self): data = request.get_json() current_user = get_jwt_identity() data, errors = recipe_schema.load(data=request.get_json()) if errors: return {'message': 'Validation errors', 'errors': errors} recipe = Recipe(**data) recipe.user_id = current_user recipe.save() return recipe_schema.dump(recipe).data, HTTPStatus.CREATED
def test_delete_from_like_recipe(self): new_r = dict( id="acbeasyas123", title="a new recipe" ) r = Recipe(**new_r) r.save() r.like() self.assertIsNotNone(models.storage.get("Recipe", "acbeasyas123", "fav")) r.delete_from_fav() self.assertIsNone(models.storage.get("Recipe", "acbeasyas123", "fav"))
def get(self, username=None, recipe_slug=None, version=None): """ Render the recipe view. If no slug is given then create a new recipe and render it in edit mode. """ # Create a new recipe if we have no slug, otherwise query if not recipe_slug: publicuser = self.user recipe = Recipe() recipe.owner = publicuser recipe.new = True else: publicuser = UserPrefs.all().filter('name =', username).get() if not publicuser: self.abort(404) recipe = Recipe.all()\ .filter('owner =', publicuser)\ .filter('slug =', recipe_slug)\ .get() if not recipe: self.abort(404) if version: try: version = int(version) except: self.abort(404) history = RecipeHistory.get_by_id(version, recipe) if not history: self.abort(404) recipe.old = True recipe.oldname = history.name recipe.description = history.description recipe.type = history.type recipe.category = history.category recipe.style = history.style recipe.batch_size = history.batch_size recipe.boil_size = history.boil_size recipe.bottling_temp = history.bottling_temp recipe.bottling_pressure = history.bottling_pressure recipe._ingredients = history._ingredients cloned_from = None try: cloned_from = recipe.cloned_from except Exception, e: pass
def post(self): data = request.get_json() recipe = Recipe(name=data['name'], description = data['description'], num_of_servings = data['num_of_servings'], cook_time = data['cook_time'], directions = data['directions']) recipe_list.append(recipe) return recipe.data, HTTPStatus.CREATED
def post(self): # create recipe json_data = request.get_json() current_user = get_jwt_identity() try: data = recipe_schema.load(data=json_data) except ValidationError as error: errors = list(error.messages.values()) return {'message': 'Validation errors', 'errors': [x[0] for x in errors]}, HTTPStatus.BAD_REQUEST recipe = Recipe(**data) recipe.user_id = current_user recipe.save() return recipe_schema.dump(recipe), HTTPStatus.CREATED
def post(self): json_data = request.get_json() current_user = get_jwt_identity() recipe = Recipe(name = json_data['name'], description = json_data['description'], num_of_servings = json_data['num_of_servings'], cook_time = json_data['cook_time'], directions = json_data['directions'], user_id = current_user) recipe.save() return recipe.data(), HTTPStatus.CREATED
def create_recipe(): """ function that create a new recipe """ new_recipe = request.get_json() if not new_recipe: abort(400, "Not a JSON") if new_recipe: if "name" not in new_recipe: abort(400, "Missing name") recipe = Recipe(**new_recipe) storage.new(recipe) storage.save() return make_response(jsonify(recipe.to_dict()), 201)
def post(self): json_data = request.get_json() current_user = get_jwt_identity() try: data = recipe_schema.load(data=json_data) except ValidationError as errors: return { 'message': 'Validation errors', 'errors': errors.messages }, HTTPStatus.BAD_REQUEST recipe = Recipe(**data) recipe.user_id = current_user recipe.save() return recipe_schema.dump(recipe), HTTPStatus.CREATED
def post(self, method=None): print request.form # Filter out empty strings from ingredient IDs. ingredients = filter(len, request.form["ingredients"].split(",")) ingredient_pairs = [] for ingredient in ingredients: ingredient_pairs.append( [ingredient.split("-")[0], ingredient.split("-")[1]]) name = request.form["name"] author = self.get_user_id() print ingredients, name, author result = Recipe().new_recipe(name, ingredient_pairs, author) return redirect("/new/recipe", code=302)
def post(self): # get recipe data details from request call (request.get_json()) data = request.get_json() # define data required for post request recipe = Recipe(name=data['name'], description=data['description'], num_of_servings=data['num_of_servings'], cook_time=data['cook_time'], directions=data['directions']) # add data to recipe list recipe_list.append(recipe) # return created recipe data to user. return recipe.data, HTTPStatus.CREATED
def post(self): json_data = request.get_json() current_user = get_jwt_identity() try: data = recipe_schema.load(data=json_data) except Exception as errors: return ( { "message": "Validation error", "errors": errors.messages }, HTTPStatus.BAD_REQUEST, ) recipe = Recipe(**data) recipe.user_id = current_user recipe.save() return recipe_schema.dump(recipe), HTTPStatus.CREATED
def post(self, username=None, recipe_slug=None): publicuser = UserPrefs.all()\ .filter('name = ', username)\ .get() if not publicuser: self.render_json({'status': 'error', 'error': 'User not found'}) return recipe = Recipe.all()\ .filter('owner =', publicuser)\ .filter('slug =', recipe_slug)\ .get() if not recipe: self.render_json({'status': 'error', 'error': 'Recipe not found'}) return new_recipe = Recipe( **{ 'owner': UserPrefs.get(), 'cloned_from': recipe, 'color': recipe.color, 'ibu': recipe.ibu, 'alcohol': recipe.alcohol, 'name': recipe.name, 'description': recipe.description, 'type': recipe.type, 'style': recipe.style, 'batch_size': recipe.batch_size, 'boil_size': recipe.boil_size, 'bottling_temp': recipe.bottling_temp, 'bottling_pressure': recipe.bottling_pressure, '_ingredients': recipe._ingredients }) new_recipe.slug = generate_usable_slug(new_recipe) new_recipe.put() action = UserAction() action.owner = UserPrefs.get() action.type = action.TYPE_RECIPE_CLONED action.object_id = new_recipe.key().id() action.put() return self.render_json({'status': 'ok', 'redirect': new_recipe.url})