generated from TempeHS/Secure_Flask_PWA_Template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentry_form.py
35 lines (32 loc) · 1.32 KB
/
entry_form.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
import bleach
from datetime import datetime
import logging
# Function to handle the entry input, includes sanitisation
# Coverts datetime to string for database
# Calculates time worked and rounds to nearest 15 mins
def entry_input(session, request_form):
devtag = session.get("devtag")
project = request_form["project"]
project = bleach.clean(project)
diary_entry = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
start_time = datetime.strptime(request_form["start_time"], "%Y-%m-%dT%H:%M")
end_time = datetime.strptime(request_form["end_time"], "%Y-%m-%dT%H:%M")
time_diff = (end_time - start_time).total_seconds() / 60
time_worked = round(time_diff / 60 * 4) / 4
repo = request_form["repo"]
developer_notes = request_form["developer_notes"]
developer_notes = bleach.clean(developer_notes)
code_additions = request_form["code_additions"]
code_additions = bleach.clean(code_additions)
data = {
"devtag": devtag,
"project": project,
"diary_entry": diary_entry,
"start_time": start_time.strftime("%Y-%m-%d %H:%M:%S"),
"end_time": end_time.strftime("%Y-%m-%d %H:%M:%S"),
"time_worked": str(time_worked),
"repo": repo,
"developer_notes": developer_notes,
"code_additions": code_additions,
}
return data