-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
104 lines (87 loc) · 2.85 KB
/
models.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
from datetime import datetime
from db import Base
import calendar
from sqlalchemy import Column, String, DateTime, ForeignKey
from sqlalchemy.sql.functions import current_timestamp
from sqlalchemy.dialects.mysql import INTEGER, BOOLEAN
import hashlib
SQLITE3_NAME = "./db.sqlite3"
class User(Base):
'''
Userテーブル
id : 主キー
username : ユーザネーム
password : パスワード
mail : メールアドレス
'''
__tablename__ = 'user'
id = Column(
'id',
INTEGER(unsigned=True),
primary_key=True,
autoincrement=True,
)
username = Column('username', String(256))
password = Column('password', String(256))
mail = Column('mail', String(256))
def __init__(self, username, password, mail):
self.username = username
# パスワードはハッシュ化して保存
self.password = hashlib.md5(password.encode()).hexdigest()
self.mail = mail
def __str__(self):
return str(self.id) + ':' + self.username
class Task(Base):
'''
toDoタスク
id : 主キー
user_id : 外部キー
content : 内容
deadline : 締め切り
date : 作成日
done : タスクを終了したか
'''
__tablename__ = 'task'
id = Column(
'id',
INTEGER(unsigned=True),
primary_key=True,
autoincrement=True,
)
user_id = Column('user_id', ForeignKey('user.id'))
content = Column('content', String(256))
deadline = Column(
'deadline',
DateTime,
default=None,
nullable=False,
)
date = Column(
'date',
DateTime,
default=datetime.now(),
nullable=False,
server_default=current_timestamp(),
)
done = Column('done', BOOLEAN, default=False, nullable=False)
def __init__(self, user_id: int, content: str, deadline: datetime, date: datetime = datetime.now()):
self.user_id = user_id
self.content = content
self.deadline = deadline
self.date = date
self.done = False
def __str__(self):
return str(self.id) + \
': user_id -> ' + str(self.user_id) + \
', content -> ' + self.content + \
', deadline -> ' + self.deadline.strftime('%Y/%m/%d - %H:%M:%S') + \
', date -> ' + self.date.strftime('%Y/%m/%d - %H:%M:%S') + \
', done -> ' + str(self.done)
class MyCalendar(calendar.LocaleHTMLCalendar):
def __init__(self, username, linked_date: dict):
calendar.LocaleHTMLCalendar.__init__(self,
firstweekday=6,
locale='ja_jp')
# 何か予定がある日付はリンクする
self.username = username
self.linked_date = linked_date # dict{'datetime': done}