This repository has been archived by the owner on Nov 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
144 lines (126 loc) · 4.94 KB
/
main.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import os, os.path, random, hashlib, sys, json
from flask import Flask, flash, render_template, redirect, request, url_for, jsonify, session, Response
from login import signup_f, login_f
from objects import get_all_objects, get_object, addevent, wszystkieob, infowyd, joinevent
from historia import *
app = Flask(__name__)
app.secret_key = '9je0jaj09jk9dkakdwjnjq'
@app.route('/')
def main():
if 'username' in session:
return redirect(url_for('index'))
else:
return redirect(url_for('login'))
@app.route('/index')
def index():
if 'username' in session:
return render_template('index.html', obiekty = get_all_objects(), username = session.get('username'))
else:
return redirect(url_for('login'))
@app.route('/train')
def train():
if 'username' in session:
return render_template('train.html', username = session.get('username'))
else:
return redirect(url_for('login'))
@app.route('/gym', methods=['GET', 'POST'])
def gym():
if 'username' in session:
obj_id = request.args.get('id')
if request.method == 'POST':
eventName = request.form['nazwa']
eventDesc = request.form['opis']
eventDate = request.form['data']
print(eventName, eventDesc, eventDate, obj_id)
addevent(eventName,eventDesc,session['username'],obj_id, eventDate)
return redirect('/gym?id='+obj_id)
event_id_list = wszystkieob(obj_id)
events = []
for event_id in event_id_list:
events.append(infowyd(event_id))
return render_template('gym.html', obiekty = get_object(obj_id), eventy=events, username = session.get('username'), num = obj_id)
else:
return redirect(url_for('main'))
@app.route('/event', methods=['GET', 'POST'])
def event():
if 'username' in session:
event_id = request.args.get('id')
event_info = infowyd(event_id)
if request.method == 'POST':
print(joinevent(event_id))
return redirect(request.url)
return render_template('event.html', event=event_info, username = session.get('username'))
else:
return redirect(url_for('main'))
@app.route('/myActivity', methods=['GET', 'POST'])
def myActivity():
if 'username' in session:
if request.method == 'POST':
sport = request.form['sport']
if sport == "gym":
gymname = request.form['trainplan']
inserttraining(session['username'], gymname)
else:
dist = request.form['dist']
hours = request.form['hours']
minutes = request.form['minutes']
try:
time = int(hours) * 60 + int(minutes)
except:
return Response("", status=500, mimetype='application/json')
insertactivity(session['username'], time, dist, sport)
return redirect(url_for('myActivity'))
return render_template('myActivity.html', username = session.get('username'), sb=selectbest, counttra=counttra)
else:
return redirect(url_for('main'))
@app.route('/login', methods=['GET', 'POST'])
def login():
if 'username' in session:
return redirect(url_for('index'))
if request.method == 'POST':
username = request.form['user']
password = request.form['password']
if login_f(username, password):
session['username'] = username
session['password'] = password
return redirect(url_for('main'))
else:
#zły login lub hasło
return render_template('login.html', info="Zły login lub hasło!")
return render_template('login.html', info = "")
@app.route('/addPic', methods=['POST'])
def addPic():
if 'username' in session:
names = []
for fkey in request.files:
file = request.files[fkey]
if file.filename == '':
continue
file.save('current')
data = open('current', 'rb').read()
digest = hashlib.md5()
digest.update(data)
names.append('static/paste/' + digest.hexdigest() + os.path.splitext(file.filename)[1])
os.rename('current', names[-1])
add_pictures(request.form.get('num'), names)
return redirect(url_for('main'))
@app.route('/signup', methods=['GET', 'POST'])
def signup():
if 'username' in session:
return redirect(url_for('index'))
if request.method == 'POST':
username = request.form['user']
password = request.form['password']
if signup_f(username, password):
return redirect(url_for('main'))
else:
#zły login lub hasło
return render_template('signup.html')
return render_template('signup.html')
@app.route('/logout', methods=['GET', 'POST'])
def logout():
del session['username']
del session['password']
return redirect('/')
if __name__=='__main__':
app.run(debug=True)