-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
56 lines (44 loc) · 1.9 KB
/
app.py
File metadata and controls
56 lines (44 loc) · 1.9 KB
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
from flask import Flask, url_for, request, render_template, jsonify, flash, redirect
from flask_bootstrap import Bootstrap
from task_db import TaskDB
from nocache import nocache
TASKS_TO_SERVE = 5
DB_FILENAME = 'db/db.pickle'
app = Flask(__name__)
app.secret_key = 'many random bytes'
Bootstrap(app)
db = TaskDB(DB_FILENAME)
@app.route('/')
def main():
return render_template('explore.html', tasks=db.get_tasks_dict(), num_tasks=db.max_id)
@app.route('/create', methods=['GET', 'POST'])
def create():
if request.method == 'GET':
return render_template('create.html', types=db.task_types)
else:
title = request.form['title']
description = request.form['description']
task_type = request.form['task_type']
duration = request.form['duration']
in_out_everywhere = request.form['in_out_everywhere']
task_comments = {'Mottig': 'Amazing task, really made me smile!!!',
'Nofar': 'Totally changed my life :)',
'Eshed The King': 'How am I ??',
'LouisL': 'I wish I could\'ve go back in time and do it again'}
try:
db.insert_task(title=title, desc=description, creator='Motti The King', in_out_everywhere=in_out_everywhere,
task_type=task_type, location='Jerusalem', duration=duration, value=1,
comments=task_comments)
except:
flash('Task creation faild!', category='error')
return redirect(url_for('create'))
flash('Task created!', category='info')
return redirect(url_for('main'))
@app.route('/do/<task_id>')
def do(task_id=None):
task = db.get_by_id(int(task_id))
return render_template('do.html', task=task)
@app.route('/comments/<task_id>')
def comments(task_id=None):
task_comments = db.get_by_id(int(task_id))
return render_template('comments.html', task=task_comments)