-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
84 lines (65 loc) · 2.37 KB
/
app.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
from flask import Flask, jsonify, request, redirect, send_from_directory, flash
from werkzeug.utils import secure_filename
import logging
import os
import task
import pathlib
import json
import never_note
app = Flask(__name__)
UPLOAD_FOLDER = os.path.dirname(os.path.abspath(__file__)) + '/tmp'
ALLOWED_EXTENSIONS = {'json'}
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
task_list = []
done_tasks_list = []
def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@app.route('/', methods=['GET'])
def render_site():
return never_note.render_task_desk(task_list, done_tasks_list)
@app.route('/favicon.ico')
def favicon():
"""Handles browser's request for favicon"""
return send_from_directory(
os.path.join(app.root_path, 'static'),
'favicon.ico'
)
@app.route('/add_task', methods=["POST"])
def add_task():
task_date = request.form.get("task_date")
task_name = request.form.get("task_name")
task_info = request.form.get("task_info")
task_complexity = request.form.get("task_complexity")
task_list.append(task.Task(task_date, task_name, task_info, task_complexity, "todo"))
return redirect('/')
@app.route('/move_right/<task_id>', methods=["POST"])
def move_right(task_id=None):
task_id = int(task_id)
try:
task_list[task_id].move_right()
except ValueError:
task_list[task_id].finish()
done_tasks_list.append(task_list[task_id])
task_list.pop(task_id)
return redirect('/')
@app.route('/add_task_sheet', methods=["POST"])
def add_task_sheet():
if "task_sheet_name" not in request.files: # no file part
return redirect('/')
file = request.files["task_sheet_name"]
if file.filename == '': # no file selected
return redirect('/')
elif file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
global task_list
global done_tasks_list
with open('tmp/' + filename) as inp_file:
imported = json.load(inp_file)
task_list, done_tasks_list = never_note.import_sheet(imported)
return redirect('/')
@app.route('/get_task_sheet', methods=["GET"])
def get_task_sheet():
return never_note.export_sheet(task_list, done_tasks_list)
if __name__ == '__main__':
app.run()