-
Notifications
You must be signed in to change notification settings - Fork 2
/
staff-attendence-system.py
96 lines (77 loc) · 3.35 KB
/
staff-attendence-system.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
import os
from app import create_app, db
app = create_app()
@app.cli.command()
def test():
"""Run the unit tests."""
import unittest
tests = unittest.TestLoader().discover('tests')
unittest.TextTestRunner(verbosity=2).run(tests)
@app.cli.command()
def ipy():
"""Open IPython Debug Shell"""
ctx = app.app_context()
ctx.push()
from app.model import (Department, Leave, Role,
Overtime, TemporaryOvertime,
SignSheet, User, WorkArrangement)
__import__('IPython').embed()
ctx.pop()
@app.cli.command()
def init_db():
"""Init database and create basic test data."""
file = 'db.sqlite3'
if os.path.exists(file):
os.remove(file)
db.drop_all()
db.create_all()
create_test_data()
def create_test_data():
"""新建测试数据"""
from itertools import chain
from datetime import date, time, datetime
from app.model import (Department, Leave, Role,
Overtime, TemporaryOvertime,
SignSheet, User, WorkArrangement)
signsheet = [SignSheet(ID=1, staffID=1,
commitStamp=datetime(2000, 1, 1, 1, 1))]
departments = [Department(ID=1, name="销售"),
Department(ID=2, name="财务"),
Department(ID=3, name="技术")]
users = [User(ID=1, password="123456", name="老王",
role=Role.MANAGER, gender=False),
User(ID=2, password="123456", name="马大叔",
role=Role.CHARGE, gender=True, birthday=datetime(1978, 2, 15), department=departments[0], email="[email protected]", image_url="img/ma.jpg"),
User(ID=3, password="123456", name="木木",
role=Role.CHARGE, birthday=datetime(1981, 11, 30), gender=False, department=departments[1], email="[email protected]"),
User(ID=4, password="123456", name="小马",
role=Role.STAFF, gender=False, department=departments[0], email="[email protected]"),
User(ID=5, password="123456", name="小刚",
role=Role.STAFF, gender=False, department=departments[0]),
User(ID=6, password="123456", name="徐徐",
role=Role.STAFF, gender=True, department=departments[1]),
User(ID=7, password="123456", name="赵赵",
role=Role.STAFF, gender=True, department=departments[1], image_url="img/zhao.jpg")]
for d in chain(departments, users):
d.update_db()
def overtime(b, e, r):
return {
"beginDateTime": b,
"endDateTime": e,
"reason": r
}
Overtime(staff=users[3], status=1, reviewer=users[1], reason="晚上加班睡的香", beginDateTime=datetime(
2019, 6, 12, 18, 0), endDateTime=datetime(2019, 6, 13, 1, 0)).update_db()
Leave(staff=users[3], status=0, type=0, reason="回家种地", beginDateTime=datetime(
2019, 6, 14), endDateTime=datetime(2019, 6, 22)).update_db()
w = WorkArrangement(staff=users[3], date=date(2019, 6, 12), beginTime=time(
8, 0), endTime=time(18, 0))
s1 = SignSheet(user=users[4])
s1.commitStamp = datetime(2019, 6, 12, 8, 5)
s1.update_db()
s2 = SignSheet(user=users[4])
s2.commitStamp = datetime(2019, 6, 12, 17, 55)
s2.update_db()
w.beginSign = s1
w.endSign = s2
w.update_db()