Commit 36202b83c858002ca675bb2b997af3d933e33bf9
- Diff rendering mode:
- inline
- side by side
server/alipi.py
(23 / 17)
  | |||
11 | 11 | from urllib import quote_plus | |
12 | 12 | from urllib import unquote_plus | |
13 | 13 | import conf | |
14 | import oursql | ||
15 | from flask import jsonify | ||
14 | 16 | app = Flask(__name__) | |
15 | 17 | @app.before_request | |
16 | 18 | def first(): | |
… | … | ||
346 | 346 | query.reverse() | |
347 | 347 | return render_template('directory.html', name=query, mymodule = quote_plus, myset=set, mylist= list) | |
348 | 348 | ||
349 | @app.route('/getLang') | ||
349 | @app.route('/getLoc', methods=['GET']) | ||
350 | def 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']) | ||
350 | 361 | def 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) | ||
367 | 371 | import logging,os | |
368 | 372 | from logging import FileHandler | |
369 | 373 |