-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
96 lines (73 loc) · 2.51 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
from flask import Flask, render_template, request, jsonify
from flask_login import login_required, logout_user, current_user
from helpers import *
from data_retrieval import *
from login.__init__ import *
app = Flask('PreTweet', static_url_path='/')
init_login(app)
@app.route("/logout", methods=['GET', 'POST'])
@login_required
def logout():
logout_user()
flash("You have logged out")
login_manager.login_view = 'twitter.login'
return redirect(url_for("index"))
@app.route("/", methods=['GET', 'POST'])
def index():
if not current_user.is_anonymous:
user_id = current_user.get_id()
return render_template('app.html')
else:
return render_template('index.html')
@app.route("/posts", methods=['GET', 'PUT'])
@login_required
def posts():
if request.method == 'GET':
# return all pending posts
posts = get_user_posts(current_user.get_id())
response = []
for post in posts:
response.append(post_to_json(post[0]))
return jsonify(response), 200
if request.method == 'PUT':
# add a partial post to database
post = add_user_post(current_user.get_id(), request.get_json()['content'], request.get_json()['time'])
return post_to_json(post[0][0]), 200
return "{}", 200
@app.route('/posts/<id>', methods=['DELETE'])
@login_required
def posts_delete(id):
delete_post(id)
return '{}', 200
@app.route("/request-review", methods=['POST'])
@login_required
def request_review():
if request.method == 'POST':
request_post_review(request.get_json()['id'])
return "{}", 200
return "{}", 200
@app.route("/review", methods=['GET', 'POST'])
@login_required
def write_review():
if request.method == 'GET':
pending = get_pending_posts()
pending_posts = []
for post in pending:
pending_posts.append([post[0], post[2]])
return render_template('review.html', posts=pending_posts)
if request.method == 'POST':
review_content = request.form['comments']
post_id = request.form['post-id']
add_review(current_user.get_id(), post_id, review_content)
resolve_post_review(post_id)
return redirect(url_for("index"))
@app.route("/tweet", methods=['POST'])
@login_required
def tweet():
if(request.method == 'POST'):
postTweet(current_user.get_id(), request.get_json()['id'])
return "{}", 200
return "{}", 200
if __name__ == '__main__':
app.run(debug=True, threading=False)
# notify_users()