예제 #1
0
def view(db_type=None, type_id=None, country_id=None, state_id=None):

    main = Main(db)
    pref = main.get_user_pref()
    if not type_id or not country_id:
        url = "/".join(["/allunits", pref[0], pref[1], pref[2]])
        #url = main.get_search_redirect_url("summary/type", return_type="type_summary")
        #print(url)
        return flask.redirect(url)

    type_name = main.get_type_name(type_id)
    country_name = main.get_country_name(country_id)

    units = []
    moderation = Moderation(db)
    res_label, resources = moderation.get_all_resources(country_id=country_id, type_id=type_id)
    for res in resources:
        desc_id = res[0]
        name = res[1]
        unit = {"resource_name": name, "resource_id": desc_id}
        geo_resource = GeoResource(db, desc_id)
        html = Html(geo_resource)
        html.editable = False
        unit["content"] = html.make_unit_module("Unit_Description")
        units.append(unit)

    main.store_user_pref(pref[0], country_id, type_id, pref[3])
    user_pref = main.make_html_user_pref()

    return flask.render_template("allunits.html",
                                 resources=units,
                                 country=country_name,
                                 type=type_name,
                                 user_pref=user_pref)
예제 #2
0
def view(description_id=None):

    if not description_id:
        description_id = flask.request.args.get("pid", 0)

    geo_resource = None
    prefs = None

    main = Main(db)
    if int(description_id) == 0:
        prefs = main.get_user_pref()
        geo_resource = GeoResource(db, description_id, type_id=prefs[1], country_id=prefs[2], state_id=prefs[3])
    else:
        geo_resource = GeoResource(db, description_id)

    html_repr = Html(geo_resource)
    html = html_repr.generate_editable()
    title = geo_resource.get_resource_name(geo_resource.type_name)
    if not title:
        title = "New %s %s" % (main.get_type_name(prefs[1]), prefs[0])
    user_pref = main.make_html_user_pref()
    return flask.render_template("form.html", modules=html, title=title,
                                 user_pref=user_pref,
                                 is_moderated=geo_resource.is_moderated if description_id > 0 else True)