示例#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(type_id=None, country_id=None):

    main = Main(db)
    pref = main.get_user_pref()
    if not type_id or not country_id:
        url = "/".join(["/summary/type", 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)

    content = []
    content.extend(["<input type='hidden'",
                    "name='summary_json'",
                    "id='summary_json'",
                    "value='" + flask.url_for("summarydata.summarydata",
                                              country_id=country_id,
                                              type_id=type_id) + "'",
                    "class='widget_urls'",
                    "/>"
                    ])
    main.store_user_pref(pref[0], country_id, type_id, pref[3])
    user_pref = main.make_html_user_pref()

    title = type_name + " - " + country_name
    return flask.render_template("type_summary.html",
                                 content="".join(content),
                                 title=title,
                                 user_pref=user_pref)
示例#3
0
def view():

    moderation = Moderation(db)
    new_submits, edits = moderation.get_resources_to_moderate()

    main = Main(db)
    user_pref = main.make_html_user_pref()

    baseurl = "/geoid/"
    return flask.render_template("moderation.html",
                                 new_submits=new_submits,
                                 edits=edits,
                                 baseurl=baseurl,
                                 user_pref=user_pref)
示例#4
0
def view(db_type=None, typ=None, country=None, state=None):

    if not typ or not country:
        typ = flask.request.args.get("type", "")
        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 = ["/map"]
        url_comp.extend(pref)
        url = "/".join(url_comp)
        #url = main.get_search_redirect_url("map")
        return flask.redirect(url)

    main.store_user_pref(db_type, country, typ, state)
    map_url = flask.url_for("location.location", country=country, type=typ, state=state)

    user_pref_html = main.make_html_user_pref()

    return flask.render_template("map.html", map_url=map_url, user_pref=user_pref_html)
示例#5
0
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)
示例#6
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)
示例#7
0
def view():

    main = Main(db)
    pref = main.get_user_pref()

    modules = []
    select = Select(db)

    met = select.read("metadata")
    metadata = met.fetchall()

    module = {}
    module['heading'] = "Cumulative Capacity by Category"
    module['content'] = []
    module['content'].append("<p style='text-align: center'><b>Total Cumulative Capacity: %s MWe</b></p>"
                             % sum([t['Cumulative_Capacity'] for t in types]))
    module['content'].append("<div id='pie_chart' style='width: 900px; height: 500px;'></div>")
    module['content'] = "".join(module['content'])
    modules.append(module)

    #keys, types = main.get_types_for_country(country_id)
    for t in types:
        type_name = main.get_type_name(t['Type_ID']).replace("_", " ")

        db_name = main.get_databases(type_id=t['Type_ID'])[1][0][0]
        dbn = ""
        if db_name == "PowerPlants":
            dbn = "power plants"
        else:
            dbn = ""

        s_link = []
        s_link.append("<a href='/summary/type/")
        s_link.append(str(t['Type_ID']))
        s_link.append("/" + str(country_id))
        s_link.append("'>Click Here</a>")

        map_link = []
        map_link.append("<a href='/map/")
        map_link.append(db_name.lower() + "/")
        map_link.append(str(t['Type_ID']) + "/")
        map_link.append(str(country_id) + "/0/")
        map_link.append("'>Map</a>")

        module = {}
        module['heading'] = type_name
        module['content'] = module_content.format(type_name=type_name,
                                                  db=dbn,
                                                  total=t['Number_of_Plants'],
                                                  cumulative_capacity=t['Cumulative_Capacity'],
                                                  summary_link="".join(s_link),
                                                  map_link="".join(map_link),
                                                  pie_id=type_name,
                                                  pie_value=t['Cumulative_Capacity'])

        modules.append(module)

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

    title = "Summary for " + country_name
    return flask.render_template("country_summary.html",
                                 modules=modules, title=title,
                                 country=country_name,
                                 user_pref=user_pref,
                                 body_onload="Chart.plotPieChart('', 'pie_chart')")
示例#8
0
def view(country_id=None, country_abbr=None):

    main = Main(db)
    pref = main.get_user_pref()

    if not country_id and not country_abbr:
        url = "/".join(["/summary/country", pref[2]])
        #url = main.get_search_redirect_url("summary/country",
        #                                   return_type='country_summary')
        return flask.redirect(url)
    elif country_abbr:
        country_id = main.get_country_id_from_abbr(country_abbr)
        return flask.redirect("/summary/country/" + str(country_id))

    country_name = main.get_country_name(country_id)

    modules = []
    select = Select(db)

    res = select.read("metadata",
                      columns=["Type_ID",
                               "Number_of_Plants",
                               "Cumulative_Capacity_Total"],
                      where=[["Country_ID", "=", country_id]],
                      order_by=["Type_ID", "asc"])
    types = res.fetchall()

    module_content = """
    <table style="width: 90%">
    <tr>
        <td style="width: 70%">Number of {type_name} {db}:</td>
        <td>{total}</td>
    </tr>
    <tr>
        <td style="width: 70%">Total Cumulative Capacity (MWe):</td>
        <td>{cumulative_capacity}</td>
    </tr>
    <tr>
        <td style="width: 70%">Map All {type_name} {db}:</td>
        <td>{map_link}</td>
    </tr>
    <tr>
        <td style="width: 70%">List All Units in Individual Plants</td>
        <td>{all_units_link}</td>
    </tr>
    <tr>
        <td style="width: 70%">Complete summary:</td>
        <td>{summary_link}</td>
    </tr>
</table>
<input type='hidden' id='{pie_id}' class='pie_chart_values' value='{pie_value}' />
"""

    module = {}
    module['heading'] = "Installed Capacity by Category"
    module['content'] = []
    module['content'].append("<p style='text-align: center'><b>Total Cumulative Capacity: %s MWe</b></p>"
                             % sum([t['Cumulative_Capacity_Total'] for t in types]))
    module['content'].extend(["<div id='pie_chart'>",
                              "<div id='pie_chart_1'>",
                              "<div id='pie_chart_1_title' style='text-align: center'>",
                              "<b>Traditional Energy Sources</b></div>",
                              "</div>",
                              "<div id='pie_chart_2'>",
                              "<div id='pie_chart_2_title' style='text-align: center'>",
                              "<b>Renewable Energy Sources</b></div>",
                              "</div>",
                              "</div>"])
    module['content'] = "".join(module['content'])
    modules.append(module)

    #keys, types = main.get_types_for_country(country_id)
    for t in types:
        type_name = main.get_type_name(t['Type_ID']).replace("_", " ")

        db_name = main.get_databases(type_id=t['Type_ID'])[1][0][0]
        dbn = ""
        if db_name == "PowerPlants":
            dbn = "power plants"
        else:
            dbn = ""

        s_link = []
        s_link.append("<a href='/summary/type/")
        s_link.append(str(t['Type_ID']))
        s_link.append("/" + str(country_id))
        s_link.append("'>Click Here</a>")

        map_link = []
        map_link.append("<a href='/map/")
        map_link.append(db_name.lower() + "/")
        map_link.append(str(t['Type_ID']) + "/")
        map_link.append(str(country_id) + "/0/")
        map_link.append("'>Map</a>")

        all_units = []
        all_units.append("<a href='/allunits/")
        all_units.append(pref[0] + "/")
        all_units.append(str(t['Type_ID']) + "/")
        all_units.append(str(country_id))
        all_units.append("'>All Units</a>")

        module = {}
        module['heading'] = type_name
        module['content'] = module_content.format(type_name=type_name,
                                                  db=dbn,
                                                  total=t['Number_of_Plants'],
                                                  cumulative_capacity=t['Cumulative_Capacity_Total'],
                                                  summary_link="".join(s_link),
                                                  map_link="".join(map_link),
                                                  all_units_link="".join(all_units),
                                                  pie_id=type_name,
                                                  pie_value=t['Cumulative_Capacity_Total'])

        modules.append(module)

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

    title = "Summary for " + country_name
    return flask.render_template("country_summary.html",
                                 modules=modules, title=title,
                                 country=country_name,
                                 user_pref=user_pref,
                                 body_onload="CountrySummary.init()")