Improve how to retrieve & handle actions
This commit is contained in:
18
action.py
18
action.py
@@ -7,6 +7,18 @@ import datetime
|
||||
import logging
|
||||
import action
|
||||
|
||||
class Action:
|
||||
def __init__(self, row):
|
||||
if not row:
|
||||
logging.debug('Action - empty row')
|
||||
raise Exception('No action found - database need to be initialized.')
|
||||
else:
|
||||
logging.debug('Action - fill fields')
|
||||
self.project_id, self.task_id, self.note_id = row
|
||||
|
||||
def __str__(self):
|
||||
return str(self.__dict__)
|
||||
|
||||
def create_action(cursor, project_id = '', task_id = '', note_id = '', message = ''):
|
||||
query = """
|
||||
INSERT INTO action (project_id, task_id, note_id, username, message, created_at)
|
||||
@@ -21,11 +33,9 @@ def read_last_action(conn):
|
||||
logging.info('> last_action')
|
||||
# query = 'SELECT * FROM action WHERE id = (SELECT MAX(id) FROM action'
|
||||
# query = 'SELECT project_id, task_id, note_id FROM action'
|
||||
query = 'SELECT project_id, task_id, note_id FROM action ORDER BY created_at DESC LIMIT 1;'
|
||||
query = 'SELECT project_id, task_id, note_id FROM action ORDER BY id DESC LIMIT 1;'
|
||||
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(query)
|
||||
logging.debug('DEEEEEEEEBU')
|
||||
last_action = cursor.fetchone()
|
||||
logging.debug(last_action)
|
||||
last_action = Action(cursor.fetchone())
|
||||
return last_action
|
||||
Reference in New Issue
Block a user