def home_list(city=None): if not city: city_dict = session.get("curcity", None) else: city_dict = get_city(city) session["curcity"] = city_dict cates = db.Cate.find({}).sort("no", ASCENDING) return render_template("home_list.html", cates=cates, city=city_dict)
def entry_list(cate=None, q=None): city = session.get("curcity", get_city("hangzhou")) query_dict = {"city_label": city["label"], "status": "show"} args = {"_id": 1, "title": 1, "address": 1} pos = request.args.get("pos", None) if pos: lat, lon = pos.split(",") query_dict["_location"] = {"$maxDistance": 0.091, "$near": [float(lon), float(lat)]} st = int(request.args.get("st", 1)) # process functions if cate: query_dict["tags"] = cate if q: rqs = [e.lower() for e in re.split("\s+", q) if e] regex = re.compile(r"%s" % "|".join(rqs), re.IGNORECASE) query_dict["$or"] = [{"title": regex}, {"brief": regex}, {"desc": regex}, {"tags": {"$in": rqs}}] cur_entry = db.Entry.find(query_dict, args) num = cur_entry.count() entries = list(cur_entry.skip(st).limit(20)) for e in entries: e["pk"] = str(e["_id"]) del e["_id"] # what's next url = None if st + 20 < num: if q: condition = "key:%s" % q else: condition = "tag:%s" % cate if pos: url = url_for("search", st=st + 20, q=condition, pos=pos) else: url = url_for("search", st=st + 20, q=condition) return render_template( "entry_list.html", valid_city=db.City.find_one({"label": city["label"], "block": False}), entries=entries, city=city, q=q, cate=db.Cate.find_one({"label": cate}), data_url=url, )
def home_list(city=None): if not city: city_dict = session.get('curcity', None) else: city_dict = get_city(city) session['curcity'] = city_dict cates = db.Cate.find({}).sort('no', ASCENDING) return render_template('home_list.html', cates=cates, city=city_dict)
def search(): city = session.get("curcity", get_city("hangzhou")) query_dict = {"city_label": city["label"], "status": "show"} args = {"_id": 1, "title": 1, "address": 1} pos = request.args.get("pos", None) if pos: lat, lon = pos.split(",") query_dict["_location"] = {"$maxDistance": 0.091, "$near": [float(lon), float(lat)]} condition = request.args.get("q") if ":" in condition: field, value = condition.split(":") else: abort(400) st = int(request.args.get("st", 1)) # process functions def do_tag(tag): query_dict["tags"] = tag return db.Entry.find(query_dict, args) def do_key(data): rqs = [e.lower() for e in re.split("\s+", data) if e] regex = re.compile(r"%s" % "|".join(rqs), re.IGNORECASE) query_dict["$or"] = [{"title": regex}, {"brief": regex}, {"desc": regex}, {"tags": {"$in": rqs}}] return db.Entry.find(query_dict, args) handle_q = {"tag": do_tag, "key": do_key} if field in handle_q: cur_entry = handle_q[field](value) num = cur_entry.count() entries = list(cur_entry.skip(st).limit(20)) for e in entries: e["pk"] = str(e["_id"]) del e["_id"] # what's next if st + 20 < num: if pos: next = url_for("search", q=condition, st=st + 20, pos=pos) else: next = url_for("search", q=condition, st=st + 20) else: next = None return render_template("macros/_listcell.html", entries=entries, next=next) else: abort(400)
def entry_list(cate=None, q=None): city = session.get('curcity', get_city('hangzhou')) query_dict = { 'city_label': city['label'], 'status': 'show', } args = { '_id': 1, 'title': 1, 'address': 1, } pos = request.args.get('pos', None) if pos: lat, lon = pos.split(',') query_dict['_location'] = { '$maxDistance': 0.091, '$near': [float(lon), float(lat)] } st = int(request.args.get('st', 1)) # process functions if cate: query_dict['tags'] = cate if q: rqs = [e.lower() for e in re.split('\s+', q) if e] regex = re.compile(r'%s' % '|'.join(rqs), re.IGNORECASE) query_dict['$or'] = [{'title': regex}, {'brief': regex}, {'desc': regex}, {'tags': {'$in': rqs}}] cur_entry = db.Entry.find(query_dict, args) num = cur_entry.count() entries = list(cur_entry.skip(st).limit(20)) for e in entries: e['pk'] = str(e['_id']) del e['_id'] # what's next url = None if st + 20 < num: if q: condition = 'key:%s' % q else: condition = 'tag:%s' % cate if pos: url = url_for('search', st=st+20, q=condition, pos=pos) else: url = url_for('search', st=st+20, q=condition) return render_template('entry_list.html', valid_city=db.City.find_one({'label': city['label'], 'block': False}), entries=entries, city=city, q=q, cate=db.Cate.find_one({'label': cate}), data_url=url)
def search(): city = session.get('curcity', get_city('hangzhou')) query_dict = { 'city_label': city['label'], 'status': 'show', } args = { '_id': 1, 'title': 1, 'address': 1, } pos = request.args.get('pos', None) if pos: lat, lon = pos.split(',') query_dict['_location'] = { '$maxDistance': 0.091, '$near': [float(lon), float(lat)] } condition = request.args.get('q') if ':' in condition: field, value = condition.split(':') else: abort(400) st = int(request.args.get('st', 1)) # process functions def do_tag(tag): query_dict['tags'] = tag return db.Entry.find(query_dict, args) def do_key(data): rqs = [e.lower() for e in re.split('\s+', data) if e] regex = re.compile(r'%s' % '|'.join(rqs), re.IGNORECASE) query_dict['$or'] = [{'title': regex}, {'brief': regex}, {'desc': regex}, {'tags': {'$in': rqs}}] return db.Entry.find(query_dict, args) handle_q = { 'tag': do_tag, 'key': do_key, } if field in handle_q: cur_entry = handle_q[field](value) num = cur_entry.count() entries = list(cur_entry.skip(st).limit(20)) for e in entries: e['pk'] = str(e['_id']) del e['_id'] # what's next if st + 20 < num: if pos: next = url_for('search', q=condition, st=st+20, pos=pos) else: next = url_for('search', q=condition, st=st+20) else: next = None return render_template('macros/_listcell.html', entries=entries, next=next) else: abort(400)
cates=cates, city=city_dict) @app.route('/setcity/<latlon>') @app.route('/setcity/') def setcity(latlon=None): if latlon: try: city_label = http_client.fetch('http://l.n2u.in/city/%s' % latlon) except httpclient.HTTPError, e: city_label = 'hangzhou' else: city_label = get_city_by_ip() city_dict = get_city(city_label) session['curcity'] = city_dict return jsonify(city_dict) @app.route('/getcity/<latlon>') @app.route('/getcity/') def getcity(latlon=None): if latlon: try: city_label = http_client.fetch('http://l.n2u.in/city/%s' % latlon) except httpclient.HTTPError, e: city_label = 'hangzhou' else: city_label = get_city_by_ip()
return render_template("home_list.html", cates=cates, city=city_dict) @app.route("/setcity/<latlon>") @app.route("/setcity/") def setcity(latlon=None): if latlon: try: city_label = http_client.fetch("http://l.n2u.in/city/%s" % latlon) except httpclient.HTTPError, e: city_label = "hangzhou" else: city_label = get_city_by_ip() city_dict = get_city(city_label) session["curcity"] = city_dict return jsonify(city_dict) @app.route("/getcity/<latlon>") @app.route("/getcity/") def getcity(latlon=None): if latlon: try: city_label = http_client.fetch("http://l.n2u.in/city/%s" % latlon) except httpclient.HTTPError, e: city_label = "hangzhou" else: city_label = get_city_by_ip()