-
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
base: master
Are you sure you want to change the base?
Conversation
0a7f050
to
c71ae11
Compare
c71ae11
to
6973385
Compare
6973385
to
8279b2f
Compare
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Function SearchableMixin.search
refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension
)
@@ -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')) |
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 (
remove-unreachable-code
)
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')) |
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 submit_recipe
refactored with the following changes:
- Remove redundant conditional (
remove-redundant-if
) - Add guard clause (
last-if-guard
) - Replace assignment with augmented assignment (
aug-assign
)
Sourcery Code Quality Report (beta)✅ Merging this PR will increase code quality in the affected files by 0.06 out of 10.
Here are some functions in these files that still need a tune-up:
Please see our documentation here for details on how these metrics are calculated. We are actively working on this report - lots more documentation and extra metrics to come! Let us know what you think of it by mentioning @sourcery-ai in a comment. |
Branch
master
refactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
master
branch, then run: