use db contexts for better stability
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user