-
Notifications
You must be signed in to change notification settings - Fork 0
/
JournalController.py
49 lines (37 loc) · 1.28 KB
/
JournalController.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from Journal import Journal, db
from datetime import date, timedelta
from PyQt5.QtCore import QTimer
import time
class JournalController():
def __init__(self):
self.viewID = Journal.get(date = date.today()).id
db.connect()
if not Journal.table_exists():
Journal.create_table(True)
self.create()
def reset(self):
self.create()
def create(self):
try:
self.journal = Journal.get(date = date.today())
except Journal.DoesNotExist:
self.journal = Journal.create(text = "", date = date.today())
def update(self, text):
self.journal.text = text
self.journal.save()
def forward(self):
try:
journals = Journal.select().where(Journal.id > self.viewID).order_by(Journal.date.asc())
self.viewID = journals[0].id
return journals[0]
except IndexError:
return False
def back(self):
try:
journals = Journal.select().where(Journal.id < self.viewID).order_by(Journal.date.desc())
self.viewID = journals[0].id
return journals[0]
except IndexError:
return False
def get(self, date = date.today()):
return Journal.get(date = date)