def get_todos(cls, chan, user=None, patern="", limit=5): request = (Todo.chan == chan) if user: request = request & (Todo.user == user) if patern and patern.strip(): request = request & (Todo.message.contains(patern)) return (Todo.select() .where(request) .limit(limit))
def get_todo(cls, ident): try: int(ident) except ValueError: return None try: todo = Todo.get(id=ident) except Todo.DoesNotExist: return None return todo
def add_todo(cls, chan, value, user): Todo.create(chan=chan, user=user, message=value)