forked from b1naryth1ef/sandyslist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
155 lines (137 loc) · 5.4 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
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
145
146
147
148
149
150
151
152
153
154
155
from flask import Flask, flash, render_template, request, redirect, url_for, session
from datetime import datetime
from data import Request, FollowUp
app = Flask(__name__)
app.secret_key = "asdfalsdkfg38asdfl38as8dfa8"
def isMod():
return session.get('logged', False)
#-- Static Routes --
@app.route('/secret_login') #LOL SECURTUY IS GUD
def routeLogin():
session['logged'] = True
return redirect('/responses')
@app.route('/logout')
def routeLogout():
session['logged'] = False
return redirect('/')
@app.route('/')
def routeIndex(): return render_template('index.html')
@app.route('/post')
def routePost(): return render_template('post.html')
@app.route('/find') #@TODO Pagination (sort invalid)
@app.route('/find/<page>')
def routeSearch(page=1):
try: reqs = Request.objects().paginate(page=int(page), per_page=35) #@NOTE Hacky af
except: return redirect('/find/%s' % (int(page)-1))
return render_template('find.html', reqs=reqs, ismod=isMod(), page=int(page))
@app.route('/responses')
@app.route('/responses/<page>')
def routeResponese(page=1):
try: reqs = FollowUp.objects().paginate(page=int(page), per_page=35)
except: return redirect('/responses/%s' % (int(page)-1))
return render_template('mod.html', reqs=reqs, page=int(page))
# -- Dynamic Stuffs --
@app.route('/mod/<action>/<id>')
def routeMod(id=None, action=None):
if not isMod(): return redirect(url_for('/find'))
if not id: return render_template('find.html', reqs=Request.objects(), ismod=True)
if action == 'valid_resp':
q = FollowUp.objects(id=id)
if not len(q):
flash("Invalid response ID!", 'error')
return redirect('/responses')
q = q[0]
q.valid = True
q.save()
flash('Marked response as valid!', 'error')
return redirect('/responses')
elif action == 'delete_resp':
q = FollowUp.objects(id=id)
if not len(q):
flash("Invalid response ID!", 'error')
return redirect('/responses')
q[0].delete()
flash('Deleted response!', 'success')
return redirect('/responses')
elif action == 'delete_req':
q = Request.objects(id=id)
if not len(q):
flash("Invalid response ID!", 'error')
return redirect('/find')
q[0].delete()
flash("Marked request %s as invalid!" % id, 'success')
return redirect('/find')
@app.route('/help/<id>')
def routeHelp(id):
if not id:
return redirect(url_for('/find'))
p = Request.objects(id=id)
if not len(p):
return "No such request ID '%s'" % id
return render_template('help.html', p=p[0])
@app.route('/resp/<id>')
def routeResp(id):
if not id:
return redirect(url_for('/post'))
p = FollowUp.objects(id=id)
if not len(p):
return "No such response ID '%s'" % id
if p[0].valid:
return """Your help is needed! Please click <a href='/resp/%s/info'>here</a> to get contact information!
Make sure to follow up on this page to help us keep efforts organized and managed!""" % (p[0].id)
else:
return "Your post is still waiting moderation!" #@TODO Refresh page every x mins?
@app.route('/resp/<id>/info')
def routeRespInfo(id):
if not id:
return redirect(url_for('/post'))
p = FollowUp.objects(id=id)
if not len(p):
return "No such response ID '%s'" % id
if not p[0].valid:
return redirect(url_for('/resp/%s' % id))
p = p[0]
p.connected = True
p.entry.connected = True
p.entry.save()
p.save()
return "Please contact the person with this information: %s" % p.entry.contact #@TODO More info here?
@app.route('/internals/<route>', methods=['POST'])
def internals(route=None):
if route == 'needhelp':
for k, v in request.form.items():
if not v:
flash('You must give a value for %s! <a href="/post">Try again</a>' % k , 'error')
return redirect('/post')
obj = Request(
name=request.form.get('name'),
urgent={'on':True, 'off':False, None:False}[request.form.get('urgent')],
request=request.form.get('request'),
contact=request.form.get('phonenum'),
location=request.form.get('location'))
obj.save()
flash("Your request has been submitted to the system! We'll try to get to it ASAP.<br />Request ID: %s" % obj.id, 'success')
return redirect('/post')
elif route == "canhelp":
for k, v in request.form.items():
if not v:
flash('You must give a value for %s! <a href="/help/%s">Try again</a>' % (k, request.form.get('id')), 'error')
return redirect('/find')
p = Request.objects(id=request.form.get('id'))
if not len(p):
flash('Could not find the request ID "%s"' % id, 'error')
return redirect('/find')
p = p[0]
obj = FollowUp(
name=request.form.get('name'),
cangive=request.form.get('have'),
contact=request.form.get('phonenum'),
entry=p)
obj.save()
p.responses.append(obj)
flash("""
Your response has been filed, please check back at <a href="/resp/%s">your response page</a> often.
We'll update the page as soon as you can help!""" % (obj.id), 'success')
return redirect('/find')
if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0")