Commit 36202b83c858002ca675bb2b997af3d933e33bf9

  • avatar
  • admin
  • Wed Apr 11 15:09:59 IST 2012
Language and location auto-completion implemented.
  
1111from urllib import quote_plus
1212from urllib import unquote_plus
1313import conf
14import oursql
15from flask import jsonify
1416app = Flask(__name__)
1517@app.before_request
1618def first():
346346 query.reverse()
347347 return render_template('directory.html', name=query, mymodule = quote_plus, myset=set, mylist= list)
348348
349@app.route('/getLang')
349@app.route('/getLoc', methods=['GET'])
350def get_loc():
351 term = request.args['term']
352 connection = oursql.Connection(conf.DBHOST[0],conf.DBUSRNAME[0],conf.DBPASSWD[0],db=conf.DBNAME[0])
353 cursor = connection.cursor(oursql.DictCursor)
354 cursor.execute('select l.name, c.country_name from `location` as l, `codes` as c where l.name like ? and l.code=c.code limit ?', (term+'%', 5))
355 r = cursor.fetchall()
356 connection.close()
357 d = {}
358 d['return'] = r
359 return jsonify(d)
360@app.route('/getLang', methods=['GET'])
350361def get_lang():
351 collection = g.db['alipi_lang']
352 term = '^{0}.*'.format(request.args['term'][0])
353 query = collection.group(
354 key = Code('function(doc){return {"name" : doc.name}}'),
355 condition={"name":{'$regex':term, '$options':'i'}},
356 initial={'na': []},
357 reduce=Code('function(doc,out){out.na.push(doc);}')
358 )
359 string = {'name':[]}
360 if len(query) != 0:
361 for i in query:
362 for x in i['na']:
363 if x != '_id':
364 string['name'].append((x['name']))
365 return jsonify(string)
366
362 term = request.args['term']
363 connection = oursql.Connection(conf.DBHOST[0],conf.DBUSRNAME[0],conf.DBPASSWD[0],db=conf.DBNAME[0])
364 cursor = connection.cursor(oursql.DictCursor)
365 cursor.execute('select * from `languages` as l where l.name like ? limit ?', (term+'%',5))
366 r = cursor.fetchall()
367 connection.close()
368 d = {}
369 d['return'] = r
370 return jsonify(d)
367371import logging,os
368372from logging import FileHandler
369373