Skip to content
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
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Jun 3, 2020

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:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

when = []
for i in range(len(ids)):
when.append((ids[i], i))
when = [(ids[i], i) for i in range(len(ids))]
Copy link
Author

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'))
Copy link
Author

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)

Comment on lines -153 to +193
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'))
Copy link
Author

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-ai
Copy link
Author

sourcery-ai bot commented Aug 4, 2020

Sourcery Code Quality Report (beta)

✅  Merging this PR will increase code quality in the affected files by 0.06 out of 10.

Quality metrics Before After Change
Complexity 2.55 2.05 -0.50 🔵
Method Length 60.60 59.47 -1.13 🔵
Quality 8.38 8.44 0.06 🔵
Other metrics Before After Change
Lines 216 213 -3
Changed files Quality Before Quality After Quality Change
app/search_mixin.py 8.96 8.99 0.03 🔵
app/main/routes.py 8.16 8.23 0.07 🔵

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Overall Recommendation
app/main/routes.py submit_recipe 6 232.74 5.29 Split out functionality

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants