use db contexts for better stability
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-04-24 18:37:58 +02:00
parent e9d2582606
commit 0dfb5f3134
9 changed files with 54 additions and 140 deletions

View File

@@ -51,9 +51,10 @@ class JournalHandler(BaseHandler):
await query.answer()
if query.data == "today" or query.data == "yesterday":
date = datetime.datetime.now().date() if query.data == "today" else datetime.datetime.now().date() - datetime.timedelta(days=1)
self.current_model, new = self.models.JournalEntry.get_or_create(
date = date
)
with self.models.db:
self.current_model, new = self.models.JournalEntry.get_or_create(
date = date
)
if not new:
await query.edit_message_text(text="An entry already exists for this date")
return ConversationHandler.END
@@ -69,9 +70,10 @@ class JournalHandler(BaseHandler):
date = update.message.text
try:
date = datetime.datetime.strptime(date, "%d%m%Y").date()
self.current_model, new = self.models.JournalEntry.get_or_create(
date = date
)
with self.models.db:
self.current_model, new = self.models.JournalEntry.get_or_create(
date = date
)
if not new:
await update.message.reply_text("An entry already exists for this date")
return ConversationHandler.END