def view(db_type=None, typ=None, country=None, state=None): if not typ or not country: typ = flask.request.args.get("type", 0) country = flask.request.args.get("country", 0) state = flask.request.args.get("state", 0) main = Main(db) if not typ or not country: pref = main.get_user_pref() url_comp = ["/resources"] url_comp.extend(pref) url = "/".join(url_comp) #url = main.get_search_redirect_url("resources") return flask.redirect(url) moderation = Moderation(db) keys, values = moderation.get_all_resources(country_id=country, type_id=typ) baseurl = "/geoid/" # storing the prefs to a cookie main.store_user_pref(db_type, country, typ, state) type_name = main.get_type_name(typ) country_name = main.get_country_name(country) state_name = None if state > 0: state_name = main.get_state_name(state) user_pref = main.make_html_user_pref() return flask.render_template("resources.html", values=values, baseurl=baseurl, user_pref=user_pref, type=type_name, country=country_name, state=state_name if state > 0 else False, category=db_type)
def view(): typ = flask.request.args.get("type", 0) country = flask.request.args.get("country", 0) state = flask.request.args.get("state", 0) description_id = flask.request.args.get("description_id", 0) loc = Location(db) try: desc_id = int(description_id) except ValueError: desc_id = 0 if desc_id > 0: return flask.jsonify(data=loc.for_one_resource(description_id=description_id)) elif int(typ) > 0 and int(country) > 0: return flask.jsonify(data=loc.for_many_resources(type_id=typ, country_id=country)) else: main = Main(db) prefs = main.get_user_pref() country_name = main.get_country_name(prefs[2]) state_name = main.get_state_name(prefs[3]) bound_location = "%s, %s" % (state_name, country_name) return flask.jsonify(data={"boundLocation": bound_location})