Skip to content

Comments

Sourcery Starbot ⭐ refactored voightp/flask-mega-tutorial#1

Open
SourceryAI wants to merge 1 commit intovoightp:masterfrom
SourceryAI:master
Open

Sourcery Starbot ⭐ refactored voightp/flask-mega-tutorial#1
SourceryAI wants to merge 1 commit intovoightp:masterfrom
SourceryAI:master

Conversation

@SourceryAI
Copy link

Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨

Here's your pull request refactoring your most popular Python repo.

If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch https://github.com/sourcery-ai-bot/flask-mega-tutorial master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Comment on lines -65 to +69
auth = None
if app.config["MAIL_USERNAME"] or app.config["MAIL_PASSWORD"]:
auth = (app.config["MAIL_USERNAME"], app.config["MAIL_PASSWORD"])
secure = None
if app.config["MAIL_USE_TLS"]:
secure = ()
else:
auth = None
secure = () if app.config["MAIL_USE_TLS"] else None
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function create_app refactored with the following changes:

Comment on lines -18 to +20
if os.system("pybabel init -i messages.pot -d app/translations -l " + lang):
if os.system(
f"pybabel init -i messages.pot -d app/translations -l {lang}"
):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function register refactored with the following changes:

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:

Comment on lines -80 to +78
return "<User {}>".format(self.username)
return f"<User {self.username}>"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function User.__repr__ refactored with the following changes:

Comment on lines -90 to +88
return "https://www.gravatar.com/avatar/{}?d=identicon&s={}".format(
digest, size
)
return f"https://www.gravatar.com/avatar/{digest}?d=identicon&s={size}"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function User.avatar refactored with the following changes:

payload = {}
for field in model.__searchable__:
payload[field] = getattr(model, field)
payload = {field: getattr(model, field) for field in model.__searchable__}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function add_to_index refactored with the following changes:

"/translate?api-version=3.0&from={}&to={}".format(
source_language, dest_language
),
f"https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&from={source_language}&to={dest_language}",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function translate refactored with the following changes:

if form.validate_on_submit():
user = User.query.filter_by(email=form.email.data).first()
if user:
if user := User.query.filter_by(email=form.email.data).first():
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function reset_password_request refactored with the following changes:

Comment on lines -131 to +143
if form.validate_on_submit():
user = User.query.filter_by(username=username).first()
if user is None:
flash(_("User %(username)s not found.", username=username))
return redirect(url_for("main.index"))
if user == current_user:
flash(_("You cannot follow yourself!"))
return redirect(url_for("main.user", username=username))
current_user.follow(user)
db.session.commit()
flash(_("You are following %(username)s!", username=username))
return redirect(url_for("main.user", username=username))
else:
if not form.validate_on_submit():
return redirect(url_for("main.index"))
user = User.query.filter_by(username=username).first()
if user is None:
flash(_("User %(username)s not found.", username=username))
return redirect(url_for("main.index"))
if user == current_user:
flash(_("You cannot follow yourself!"))
return redirect(url_for("main.user", username=username))
current_user.follow(user)
db.session.commit()
flash(_("You are following %(username)s!", username=username))
return redirect(url_for("main.user", username=username))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function follow refactored with the following changes:

Comment on lines -151 to +162
if form.validate_on_submit():
user = User.query.filter_by(username=username).first()
if user is None:
flash(_("User %(username)s not found.", username=username))
return redirect(url_for("main.index"))
if user == current_user:
flash(_("You cannot unfollow yourself!"))
return redirect(url_for("main.user", username=username))
current_user.unfollow(user)
db.session.commit()
flash(_("You are not following %(username)s.", username=username))
return redirect(url_for("main.user", username=username))
else:
if not form.validate_on_submit():
return redirect(url_for("main.index"))
user = User.query.filter_by(username=username).first()
if user is None:
flash(_("User %(username)s not found.", username=username))
return redirect(url_for("main.index"))
if user == current_user:
flash(_("You cannot unfollow yourself!"))
return redirect(url_for("main.user", username=username))
current_user.unfollow(user)
db.session.commit()
flash(_("You are not following %(username)s.", username=username))
return redirect(url_for("main.user", username=username))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function unfollow refactored with the following changes:

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.

1 participant