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 ✅")
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user