Commit 1a7990c568f0000388ae067c8cefc2d9befd0d93
- Diff rendering mode:
- inline
- side by side
swtr.py
(30 / 11)
  | |||
38 | 38 | g.collection = db[app.config["COLLECTION_NAME"]] | |
39 | 39 | ||
40 | 40 | ||
41 | |||
41 | 42 | @app.teardown_request | |
42 | 43 | def close_db(exception): | |
43 | 44 | g.connection.disconnect() | |
… | … | ||
66 | 66 | response.headers['Access-Control-Allow-Origin'] = '*' | |
67 | 67 | data = {} | |
68 | 68 | data_list = [] | |
69 | escaped_form_data = json.loads(unquote_plus(request.form['data'])) | ||
70 | for i in escaped_form_data: | ||
71 | id = g.collection.insert({'user':i['user'],'title':i['title'], 'text':i['text'],'top':i['top'],'bottom':i['bottom'],'left':i['left'],'right':i['right'],'url':i['url']}) #Change i['user'] to 'i'. | ||
69 | for i in json.loads(request.form['data']): | ||
70 | id = g.collection.insert(i) | ||
72 | 71 | data['permalink'] = app.config['URL']+'/posts/'+str(ObjectId(id)) | |
72 | data['id'] = str(ObjectId(id)) | ||
73 | 73 | data_list.append(data) | |
74 | 74 | response.data = json.dumps(data_list) | |
75 | 75 | return response | |
… | … | ||
90 | 90 | return render_template('login.html', error=error) | |
91 | 91 | ||
92 | 92 | ||
93 | @app.route('/query/<post_id>',methods=['GET']) | ||
94 | def return_database_entry(post_id): | ||
95 | try: | ||
96 | res = g.collection.find_one({'_id':ObjectId(post_id)}) | ||
97 | if(res): | ||
98 | res['blog'] = url_for('show_specific_entry', post_id = str(res['_id'])) | ||
99 | del(res['_id']) | ||
100 | return jsonify(res) | ||
101 | # entries = make_list(res) | ||
102 | # return render_template('show_posts.html', entries=res, str=str) | ||
103 | else: | ||
104 | abort(404) | ||
105 | except InvalidId: | ||
106 | abort(404) | ||
107 | |||
108 | |||
109 | |||
93 | 110 | @app.route('/posts/<post_id>',methods=['GET']) | |
94 | 111 | def show_specific_entry(post_id): | |
95 | 112 | try: | |
96 | res = g.collection.find({'_id':ObjectId(post_id)}); | ||
113 | res = g.collection.find({'_id':ObjectId(post_id)}) | ||
114 | print res | ||
97 | 115 | if(res.count() > 0): | |
98 | entries = make_list(res) | ||
99 | return render_template('show_posts.html', entries=entries, str=str) | ||
116 | #entries = make_list(res) | ||
117 | return render_template('show_posts.html', entries=res, str=str) | ||
100 | 118 | else: | |
101 | 119 | abort(404) | |
102 | 120 | except InvalidId: | |
… | … | ||
137 | 137 | def make_list(res): | |
138 | 138 | entries = [] | |
139 | 139 | for row in res: | |
140 | d = dict() | ||
140 | d = row | ||
141 | 141 | d['id'] = str(row['_id']) | |
142 | d['text'] = row['text'] | ||
143 | d["title"] = row["title"] | ||
144 | d["user"] = row["user"] | ||
142 | # d['text'] = row['text'] | ||
143 | # d["title"] = row["title"] | ||
144 | # d["user"] = row["user"] | ||
145 | 145 | entries.append(d) | |
146 | 146 | return entries | |
147 | 147 | ||
148 | 148 | if __name__ == '__main__': | |
149 | app.run() | ||
149 | app.run(debug=True, port=5001) |
templates/show_posts.html
(7 / 3)
  | |||
12 | 12 | <body> | |
13 | 13 | <ul class=entries> | |
14 | 14 | {% for entry in entries %} | |
15 | <li><h2>{{ entry.title }}</h2>@<b>{{entry.user}}</b> <a href=""><i class="icon-trash" onclick=deletePost({{ entry.id|string|tojson|safe }});></i></a> | ||
16 | <p> {{ entry.text|safe }} </p> | ||
17 | {% endfor %} | ||
15 | <li><h2>{{ entry.title }}</h2>@<b>{{entry.author}}</b> | ||
16 | {% if entry.type == 1 %} | ||
17 | <p> re-narrate "{{ entry.about|safe }}{{ entry.xpath|safe }}" with "{{ entry.data|safe }}" at "{{ entry.location|safe }}" in "{{ entry.lang|safe }}"</p> | ||
18 | <a href=""><i class="icon-trash" onclick=deletePost({{ entry.id|string|tojson|safe }});></i></a> | ||
19 | {% endif %} | ||
20 | <!-- <p> {{ entry.text|safe }} </p> --> | ||
21 | {% endfor %} | ||
18 | 22 | </ul> | |
19 | 23 | </body> |