cleanup the model layout
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:
@@ -3,7 +3,7 @@ import os
|
||||
from telegram.ext import ConversationHandler, CommandHandler, MessageHandler, filters, CallbackQueryHandler
|
||||
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
|
||||
from telegram.constants import ParseMode
|
||||
|
||||
import models
|
||||
|
||||
ENTRY_OPTIONS, CONTENT_ENTRY = range(2)
|
||||
BUTTON_COUNT = 5
|
||||
@@ -12,8 +12,7 @@ BUTTON_COUNT = 5
|
||||
from .basehandler import BaseHandler
|
||||
|
||||
class JournalHandler(BaseHandler):
|
||||
def __init__(self, entry_string, models):
|
||||
self.models = models
|
||||
def __init__(self, entry_string):
|
||||
self.entry_string = entry_string
|
||||
self.handler = ConversationHandler(
|
||||
entry_points=[CommandHandler(entry_string, self.entry_point)],
|
||||
@@ -74,12 +73,12 @@ class JournalHandler(BaseHandler):
|
||||
await query.answer()
|
||||
date = datetime.datetime.strptime(query.data, "%d%m%Y").date()
|
||||
|
||||
with self.models.db:
|
||||
self.current_model, new = self.models.JournalEntry.get_or_create(
|
||||
with models.db:
|
||||
self.current_model, new = models.JournalEntry.get_or_create(
|
||||
date = date
|
||||
)
|
||||
if new:
|
||||
count = self.models.JournalEntry.select().count()
|
||||
count = models.JournalEntry.select().count()
|
||||
await query.edit_message_text(
|
||||
text=f"Journal entry no. {count}. What happened on {self.current_model.date_pretty}?"
|
||||
)
|
||||
@@ -128,8 +127,8 @@ class JournalHandler(BaseHandler):
|
||||
return ENTRY_OPTIONS
|
||||
|
||||
if context.chat_data.get("delete", False): # if not set, delete was not chosen
|
||||
with self.models.db:
|
||||
self.current_model = self.models.JournalEntry.get_or_none(
|
||||
with models.db:
|
||||
self.current_model = models.JournalEntry.get_or_none(
|
||||
date = date
|
||||
)
|
||||
if self.current_model:
|
||||
@@ -139,15 +138,15 @@ class JournalHandler(BaseHandler):
|
||||
context.chat_data["delete"] = False
|
||||
return ConversationHandler.END
|
||||
else:
|
||||
with self.models.db:
|
||||
self.current_model, new = self.models.JournalEntry.get_or_create(
|
||||
with models.db:
|
||||
self.current_model, new = 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
|
||||
else:
|
||||
count = self.models.JournalEntry.select().count()
|
||||
count = models.JournalEntry.select().count()
|
||||
await update.message.reply_text(
|
||||
text=f"Journal entry no. {count}. What happened on {self.current_model.date_pretty}?"
|
||||
)
|
||||
@@ -155,7 +154,7 @@ class JournalHandler(BaseHandler):
|
||||
|
||||
|
||||
async def content_save(self, update, context):
|
||||
with self.models.db:
|
||||
with models.db:
|
||||
self.current_model.author_id = update.message.from_user.id
|
||||
|
||||
if update.message.text:
|
||||
@@ -187,7 +186,7 @@ class JournalHandler(BaseHandler):
|
||||
|
||||
|
||||
async def delete_entry(self, update, context):
|
||||
with self.models.db:
|
||||
with models.db:
|
||||
self.current_model.delete_instance()
|
||||
context.chat_data["delete"] = False
|
||||
await update.message.reply_text(text="Entry deleted ✅")
|
||||
|
@@ -15,8 +15,7 @@ from ..basehandler import BaseHandler
|
||||
class ListHandler(BaseHandler):
|
||||
"""Create and edit lists"""
|
||||
|
||||
def __init__(self, entry_string, models):
|
||||
del models # not needed here, but part of the template
|
||||
def __init__(self, entry_string):
|
||||
self.entry_string = entry_string
|
||||
|
||||
set_db(PERSISTENCE_DIR / "lists.sqlite")
|
||||
|
@@ -1,15 +1,14 @@
|
||||
import os
|
||||
from telegram.ext import ConversationHandler, CommandHandler, MessageHandler, filters, CallbackQueryHandler, CallbackContext
|
||||
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update, InputMediaPhoto
|
||||
# ACTION_CHOICE, DATE_ENTRY, ADD_CONTENT = range(3)
|
||||
import models
|
||||
MEMORY_CHOICE = range(1)
|
||||
|
||||
|
||||
from .basehandler import BaseHandler
|
||||
|
||||
class MemoryHandler(BaseHandler):
|
||||
def __init__(self, entry_string, models):
|
||||
self.models = models
|
||||
def __init__(self, entry_string):
|
||||
self.entry_string = entry_string
|
||||
self.handler = ConversationHandler(
|
||||
entry_points=[CommandHandler(entry_string, self.entry_point, )],
|
||||
@@ -34,13 +33,13 @@ class MemoryHandler(BaseHandler):
|
||||
search_string = " ".join(context.args)
|
||||
|
||||
if search_string == '~photo':
|
||||
matching_models = self.models.JournalEntry.select().where(self.models.JournalEntry.media_path != "").order_by(self.models.JournalEntry.date)
|
||||
matching_models = models.JournalEntry.select().where(models.JournalEntry.media_path != "").order_by(models.JournalEntry.date)
|
||||
else: # searching for text
|
||||
matching_models = self.models.JournalEntry.select().where(
|
||||
self.models.JournalEntry.text.contains(
|
||||
matching_models = models.JournalEntry.select().where(
|
||||
models.JournalEntry.text.contains(
|
||||
search_string
|
||||
)
|
||||
).order_by(self.models.JournalEntry.date)
|
||||
).order_by(models.JournalEntry.date)
|
||||
|
||||
|
||||
# exit if no memory matches the string
|
||||
|
@@ -6,16 +6,14 @@ from telegram import InlineKeyboardButton, InlineKeyboardMarkup
|
||||
from telegram.constants import ParseMode
|
||||
import os
|
||||
|
||||
|
||||
FIRST = 1
|
||||
from .basehandler import BaseHandler
|
||||
class StatusHandler(BaseHandler):
|
||||
"""Shows a short status of the program."""
|
||||
|
||||
def __init__(self, entry_string, models):
|
||||
def __init__(self, entry_string):
|
||||
self.start_time = datetime.datetime.now()
|
||||
self.entry_string = entry_string
|
||||
self.models = models
|
||||
self.handler = ConversationHandler(
|
||||
entry_points=[CommandHandler(self.entry_string, self.entry_point)],
|
||||
states={
|
||||
|
Reference in New Issue
Block a user