-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sourcery refactored master branch #1
Open
sourcery-ai
wants to merge
1
commit into
master
Choose a base branch
from
sourcery/master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,53 +145,52 @@ def manage_recipes(): | |
def admin_create_recipe(): | ||
if current_user.isAdmin is not True: | ||
return('Unable to access') | ||
return redirect(url_for('main.index')) | ||
return render_template('admin_create_recipe.html') | ||
|
||
@bp.route('/admin/submit_recipe', methods=['GET','POST']) | ||
def submit_recipe(): | ||
if request.method == 'POST': | ||
#pull in all individual form responses. First create the Recipe record w/ no ingredients or steps | ||
recipeName = request.form['recipeName'] | ||
mealType = request.form['mealType'] | ||
Image = request.form['Image'] | ||
prepTime = request.form['prepTime'] | ||
if prepTime is None or "" or " ": | ||
prepTime = 0. | ||
cookTime = request.form['cookTime'] | ||
if cookTime is None or "" or " ": | ||
cookTime = 0. | ||
recipeCheck = Recipe2.query.filter_by(recipeName=recipeName).first() | ||
if recipeCheck is not None: | ||
flash('A recipe with this name already exists. Please choose a new name for your recipe') | ||
return redirect(url_for('main.admin_create_recipe')) | ||
recipe = Recipe(recipeName=recipeName, mealType=mealType, Image=Image, prepTime=prepTime, cookTime=cookTime) | ||
db.session.add(recipe) | ||
if request.method != 'POST': | ||
return | ||
|
||
#pull in all individual form responses. First create the Recipe record w/ no ingredients or steps | ||
recipeName = request.form['recipeName'] | ||
mealType = request.form['mealType'] | ||
Image = request.form['Image'] | ||
prepTime = request.form['prepTime'] | ||
prepTime = 0. | ||
cookTime = request.form['cookTime'] | ||
cookTime = 0. | ||
recipeCheck = Recipe2.query.filter_by(recipeName=recipeName).first() | ||
if recipeCheck is not None: | ||
flash('A recipe with this name already exists. Please choose a new name for your recipe') | ||
return redirect(url_for('main.admin_create_recipe')) | ||
recipe = Recipe(recipeName=recipeName, mealType=mealType, Image=Image, prepTime=prepTime, cookTime=cookTime) | ||
db.session.add(recipe) | ||
# Pull in ingredient information, then query for the recipe we just created to get ID and create the recipeIngredients record for these ingredients | ||
ingredientNames = request.form.getlist('ingredientName') | ||
ingredientMeasurements = request.form.getlist('ingredientMeasurement') | ||
ingredientAmounts = request.form.getlist('ingredientAmount') | ||
recipeRecord = Recipe2.query.filter_by(recipeName=recipeName).first() | ||
recipeRecordID = recipeRecord.id | ||
ingredientNames = request.form.getlist('ingredientName') | ||
ingredientMeasurements = request.form.getlist('ingredientMeasurement') | ||
ingredientAmounts = request.form.getlist('ingredientAmount') | ||
recipeRecord = Recipe2.query.filter_by(recipeName=recipeName).first() | ||
recipeRecordID = recipeRecord.id | ||
# Iterate over all the ingredients in the recipe Form | ||
i = 0 | ||
for ingredientName in ingredientNames: | ||
i = 0 | ||
for ingredientName in ingredientNames: | ||
# Check if this ingredient already exists in the ingredient table and if not create an ingredient record for that ingredient | ||
ingredient = Ingredients.query.filter_by(ingredientName=ingredientName).first() | ||
if ingredient is None: | ||
newIngredient = Ingredients(ingredientName=ingredientName) | ||
db.session.add(newIngredient) | ||
ingredient = Ingredients.query.filter_by(ingredientName=ingredientName).first() | ||
db.session.add(recipeIngredient) | ||
i + 1 | ||
recipeSteps = request.form.getlist('recipeStep') | ||
j=0 | ||
for recipeStep in recipeSteps: | ||
j=j+1 | ||
step = Recipe_Steps(recipe_id=recipeRecordID, stepNumber=j, directions=recipeStep) | ||
db.session.add(step) | ||
db.session.commit() | ||
return redirect(url_for('main.admin')) | ||
ingredient = Ingredients.query.filter_by(ingredientName=ingredientName).first() | ||
if ingredient is None: | ||
newIngredient = Ingredients(ingredientName=ingredientName) | ||
db.session.add(newIngredient) | ||
ingredient = Ingredients.query.filter_by(ingredientName=ingredientName).first() | ||
db.session.add(recipeIngredient) | ||
i + 1 | ||
recipeSteps = request.form.getlist('recipeStep') | ||
j=0 | ||
for recipeStep in recipeSteps: | ||
j += 1 | ||
step = Recipe_Steps(recipe_id=recipeRecordID, stepNumber=j, directions=recipeStep) | ||
db.session.add(step) | ||
db.session.commit() | ||
return redirect(url_for('main.admin')) | ||
Comment on lines
-153
to
+193
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
@bp.route('/admin/users') | ||
@login_required | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,7 @@ def search(cls, expression, page, per_page): | |
ids, total = query_index(cls.__tablename__, expression, page, per_page) | ||
if total == 0: | ||
return cls.query.filter_by(id=0), 0 | ||
when = [] | ||
for i in range(len(ids)): | ||
when.append((ids[i], i)) | ||
when = [(ids[i], i) for i in range(len(ids))] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
return cls.query.filter(cls.id.in_(ids)).order_by(db.case(when, value=cls.id)), total | ||
|
||
@classmethod | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
admin_create_recipe
refactored with the following changes:remove-unreachable-code
)