Commit 748bdd76ed18d0b7a40fae3fb579656e8ee39f53

  • avatar
  • admin
  • Tue Feb 28 21:46:56 IST 2012
Removed unwanted imported libs, adding teardown code
  
22from flask import request
33from flask import render_template
44import lxml.html
5import cgi
65import pymongo
76from bson import Code
87import urllib2
98import StringIO
10import gdata.gauth
11import gdata.blogger.client
129from flask import g
1310from flask import redirect
1411from urllib import quote_plus
1512from urllib import unquote_plus
1613app = Flask(__name__)
17connection = pymongo.Connection('localhost',27017) #Create the object once and use it.
18db = connection['dev_alipi']
19collection = db['post']
14@app.before_request()
15def 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()
19def close():
20 g.connection.close()
2021@app.route('/')
2122def start_page() :
2223 d = {}
6161 style.set("rel","stylesheet")
6262 style.set("type", "text/css")
6363 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
7364 script_jq_cust = root.makeelement('script')
7465 root.body.append(script_jq_cust)
7566 script_jq_cust.set("src", "https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js")
144144 style.set("rel","stylesheet")
145145 style.set("type", "text/css")
146146 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")
158147 root.body.set("onload","a11ypi.ren();a11ypi.tweet(); a11ypi.facebook();a11ypi.loadOverlay();")
159148 return lxml.html.tostring(root)
160149
278278 style.set("type", "text/css")
279279 style.set("href", "http://dev.a11y.in/alipi/stylesheet.css")
280280
281 collection = g.db['post']
281282 if collection.find_one({"about" : request.args['foruri']}) is not None:
282283 overlay1 = root.makeelement('div')
283284 root.body.append(overlay1)
297297
298298@app.route('/directory')
299299def 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']
304301 query = collection.group(
305302 key = Code('function(doc){return {"about" : doc.about,"lang":doc.lang}}'),
306303 condition={"about":{'$regex':'^[/\S/]'}},
307304 initial={'na': []},
308305 reduce=Code('function(doc,out){out.na.push(doc.blog)}')
309306 )
307 query.reverse()
310308 return render_template('directory.html', name=query, mymodule = quote_plus, myset=set, mylist= list)
311309
312310@app.route('/getLang')
313311def get_lang():
314 collection = db['alipi_lang']
312 collection = g.db['alipi_lang']
315313 term = '^{0}.*'.format(request.args['term'][0])
316314 query = collection.group(
317315 key = Code('function(doc){return {"name" : doc.name}}'),