Skip to content

Commit

Permalink
Fix #57 and fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Hackenberg committed Jul 24, 2024
1 parent 0786c73 commit 48f301b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
12 changes: 7 additions & 5 deletions coffeebuddy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def create_app(config=None):
if config:
app.config.update(config)

if app.config["ENV"] in ("development", "prefilled") or app.testing:
if app.config.get("ENV") in ("development", "prefilled") or app.testing:
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///:memory:"

@app.teardown_appcontext
Expand All @@ -64,7 +64,7 @@ def init_db(app):

if (
(flask.current_app.config["DB_BACKEND"] == "sqlite" and not os.path.exists("coffee.db"))
or flask.current_app.config["ENV"] in ("development", "prefilled")
or flask.current_app.config.get("ENV") in ("development", "prefilled")
or flask.current_app.testing
):
try:
Expand All @@ -74,12 +74,14 @@ def init_db(app):
os._exit(1)

# Default database content
if flask.current_app.config["ENV"] == "development":
if flask.current_app.config.get("ENV") == "development":
flask.current_app.db.session.add(
coffeebuddy.model.User(tag=bytes.fromhex("01020304"), name="Mustermann", prename="Max", email="[email protected]")
coffeebuddy.model.User(
tag=bytes.fromhex("01020304"), name="Mustermann", prename="Max", email="[email protected]"
)
)
flask.current_app.db.session.commit()
elif flask.current_app.config["ENV"] == "prefilled":
elif flask.current_app.config.get("ENV") == "prefilled":
flask.current_app.debug = True
prefill()

Expand Down
10 changes: 8 additions & 2 deletions coffeebuddy/route_pay.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@ def handle_post():
flask.current_app.db.session.commit()

for payment_notification_email in payment_notification_emails:
message_md = f"{user} with bill of {user.unpayed + amount:.2f}€ just entered a payment of **{amount:.2f}€**. Their bill is now {user.unpayed:.2f}€."
message_md = (
f"{user} with bill of {user.unpayed + amount:.2f}€ "
"just entered a payment of **{amount:.2f}€**. Their bill is now {user.unpayed:.2f}€."
)
try:
# pylint: disable=possibly-used-before-assignment
api.messages.create(toPersonEmail=payment_notification_email, markdown=message_md)
except webexteamssdk.ApiError:
logging.getLogger(__name__).exception(f"Could not send webex message for email={payment_notification_email}")
logging.getLogger(__name__).exception(
f"Could not send webex message for email={payment_notification_email}"
)

return flask.redirect(f'coffee.html?tag={flask.request.args["tag"]}')
# return flask.abort(404)
Expand Down

0 comments on commit 48f301b

Please sign in to comment.