Commit 748bdd76ed18d0b7a40fae3fb579656e8ee39f53
- Diff rendering mode:
- inline
- side by side
server/alipi.py
(11 / 31)
  | |||
2 | 2 | from flask import request | |
3 | 3 | from flask import render_template | |
4 | 4 | import lxml.html | |
5 | import cgi | ||
6 | 5 | import pymongo | |
7 | 6 | from bson import Code | |
8 | 7 | import urllib2 | |
9 | 8 | import StringIO | |
10 | import gdata.gauth | ||
11 | import gdata.blogger.client | ||
12 | 9 | from flask import g | |
13 | 10 | from flask import redirect | |
14 | 11 | from urllib import quote_plus | |
15 | 12 | from urllib import unquote_plus | |
16 | 13 | app = Flask(__name__) | |
17 | connection = pymongo.Connection('localhost',27017) #Create the object once and use it. | ||
18 | db = connection['dev_alipi'] | ||
19 | collection = db['post'] | ||
14 | @app.before_request() | ||
15 | def first(): | ||
16 | g.connection = pymongo.Connection('localhost',27017) #Create the object once and use it. | ||
17 | g.db = g.connection['dev_alipi'] | ||
18 | @app.do_teardown_request() | ||
19 | def close(): | ||
20 | g.connection.close() | ||
20 | 21 | @app.route('/') | |
21 | 22 | def start_page() : | |
22 | 23 | d = {} | |
… | … | ||
61 | 61 | style.set("rel","stylesheet") | |
62 | 62 | style.set("type", "text/css") | |
63 | 63 | style.set("href", "http://dev.a11y.in/alipi/stylesheet.css") | |
64 | |||
65 | # if collection.find_one({"about" : request.args['foruri']}) is not None: | ||
66 | # overlay1 = root.makeelement('div') | ||
67 | # root.body.append(overlay1) | ||
68 | # overlay1.set("id", "overlay1") | ||
69 | |||
70 | # opt = root.makeelement('option') | ||
71 | # opt.text = "Choose a narration" | ||
72 | |||
73 | 64 | script_jq_cust = root.makeelement('script') | |
74 | 65 | root.body.append(script_jq_cust) | |
75 | 66 | script_jq_cust.set("src", "https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js") | |
… | … | ||
144 | 144 | style.set("rel","stylesheet") | |
145 | 145 | style.set("type", "text/css") | |
146 | 146 | style.set("href", "http://dev.a11y.in/alipi/stylesheet.css") | |
147 | |||
148 | # overlay2 = root.makeelement('div') | ||
149 | # root.body.append(overlay2) | ||
150 | # overlay2.set("id", "overlay2") | ||
151 | |||
152 | # btn = root.makeelement('input') | ||
153 | # overlay2.append(btn) | ||
154 | # btn.set("id", "edit-button") | ||
155 | # btn.set("type", "submit") | ||
156 | # btn.set("onClick", "a11ypi.testContext();page_edit('4seiz', '4l85060vb9', '336e2nootv6nxjsvyjov', 'VISUAL', 'false', '');") | ||
157 | # btn.set("value", "EDIT") | ||
158 | 147 | root.body.set("onload","a11ypi.ren();a11ypi.tweet(); a11ypi.facebook();a11ypi.loadOverlay();") | |
159 | 148 | return lxml.html.tostring(root) | |
160 | 149 | ||
… | … | ||
278 | 278 | style.set("type", "text/css") | |
279 | 279 | style.set("href", "http://dev.a11y.in/alipi/stylesheet.css") | |
280 | 280 | ||
281 | collection = g.db['post'] | ||
281 | 282 | if collection.find_one({"about" : request.args['foruri']}) is not None: | |
282 | 283 | overlay1 = root.makeelement('div') | |
283 | 284 | root.body.append(overlay1) | |
… | … | ||
297 | 297 | ||
298 | 298 | @app.route('/directory') | |
299 | 299 | def show_directory(): | |
300 | # for i in collection.find(): | ||
301 | # if i.has_key('about'): | ||
302 | # if i['about'] != 'undefined' and i['about'] != '': | ||
303 | # ren.append("http://y.a11y.in/web?foruri="+quote_plus(i['about'])+'&lang='+i['lang']) | ||
300 | collection = g.db['post'] | ||
304 | 301 | query = collection.group( | |
305 | 302 | key = Code('function(doc){return {"about" : doc.about,"lang":doc.lang}}'), | |
306 | 303 | condition={"about":{'$regex':'^[/\S/]'}}, | |
307 | 304 | initial={'na': []}, | |
308 | 305 | reduce=Code('function(doc,out){out.na.push(doc.blog)}') | |
309 | 306 | ) | |
307 | query.reverse() | ||
310 | 308 | return render_template('directory.html', name=query, mymodule = quote_plus, myset=set, mylist= list) | |
311 | 309 | ||
312 | 310 | @app.route('/getLang') | |
313 | 311 | def get_lang(): | |
314 | collection = db['alipi_lang'] | ||
312 | collection = g.db['alipi_lang'] | ||
315 | 313 | term = '^{0}.*'.format(request.args['term'][0]) | |
316 | 314 | query = collection.group( | |
317 | 315 | key = Code('function(doc){return {"name" : doc.name}}'), |