Esempio n. 1
0
    def __create_associated_infrastructure(self):

        html = []
        result = self.resource.select.read("Associated_Infrastructure",
                                  where=[["Parent_Plant_ID",
                                          "=",
                                          self.resource.parent_plant_id]]
                                  )

        #keys = result.column_names
        values = result.fetchall()
        for value in values:
            ai_parent_plant_id = value["Associated_Parent_Plant_ID"]

            ai_res = GeoResource(self.resource.connection, description_id=ai_parent_plant_id)

            html.append("<b><a href=\"geoid/%s\" target=\"_blank\">%s</a></b><br/>" % (ai_res.get_latest_revision_id(),
                                                                                ai_res.get_resource_name()))

        html.append('<div id="searchAI" class="ai-search-module">')
        html.append("<div id='aiDatabase_Type' class='aiSelectable'></div>")
        html.append("<div id='aiType' class='aiSelectable'></div>")
        html.append("<div id='aiCountry' class='aiSelectable'></div>")
        html.append("<div id='aiState' class='aiSelectable'></div>")
        html.append("<div class='aiUpdateButton' id='aiUpdateButton'>")
        html.append("<button id='createAIResource' class='createAIResource'>Create</button>")
        html.append("</div>")

        html.append("</div>")
        html.append("<div id='aiResources' class='aiSelectable' style='top: 20px;'>")
        html.append("</div>")
        return "".join(html)
Esempio n. 2
0
    def get_resources_to_moderate(self):
        """
        Returns a list of resources awaiting moderation.
        Will return both new and edited resources.
        """

        select = Select(self.db_conn)

        description_ids = select.read("History",
                                      columns=[
                                          "Parent_Plant_ID",
                                          "Description_ID"
                                      ],
                                      where=[["Moderated", "=", "0"]],
                                      order_by=["Description_ID", "desc"]
        )

        main = Main(self.db_conn)
        new_submits = []
        edits = []

        for description_id in description_ids:

            if not description_id['Parent_Plant_ID']:
                #TODO: this should not happen. all versions shd have a parent. error from old code?
                continue

            geo_resource = GeoResource(self.db_conn, description_id['Description_ID'])
            type_id = geo_resource.type_id
            country_id = geo_resource.country_id

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

            geo_name = geo_resource.get_resource_name(type_name=type_name)
            if description_id['Description_ID'] == description_id['Parent_Plant_ID']:
                new_submits.append({
                    'type_name': type_name,
                    'country_name': country_name,
                    'geo_name': geo_name,
                    'description_id': str(description_id['Description_ID'])
                })
            else:
                edits.append({
                    'type_name': type_name,
                    'country_name': country_name,
                    'geo_name': geo_name,
                    'description_id': str(description_id['Description_ID'])
                })
        return new_submits, edits
Esempio n. 3
0
    def get_resources_to_moderate(self):
        """
        Returns a list of resources awaiting moderation.
        Will return both new and edited resources.
        """

        select = Select(self.db_conn)

        description_ids = select.read(
            "History",
            columns=["Parent_Plant_ID", "Description_ID"],
            where=[["Moderated", "=", "0"]],
            order_by=["Description_ID", "desc"],
        )

        main = Main(self.db_conn)
        new_submits = []
        edits = []

        for description_id in description_ids:
            geo_resource = GeoResource(self.db_conn, description_id["Description_ID"])
            type_id = geo_resource.type_id
            country_id = geo_resource.country_id

            type_name = main.get_type_name(type_id)
            country_name = main.get_country_name(country_id)
            geo_name = geo_resource.get_resource_name(type_name=type_name)
            if description_id["Description_ID"] == description_id["Parent_Plant_ID"]:
                new_submits.append(
                    {
                        "type_name": type_name,
                        "country_name": country_name,
                        "geo_name": geo_name,
                        "description_id": str(description_id["Description_ID"]),
                    }
                )
            else:
                edits.append(
                    {
                        "type_name": type_name,
                        "country_name": country_name,
                        "geo_name": geo_name,
                        "description_id": str(description_id["Description_ID"]),
                    }
                )
        return new_submits, edits
Esempio n. 4
0
    def for_one_resource(self, description_id):
        """
        Returns the location for a resource.

        :@param description_id
        :@returns dict: {lat, lng, overlays}
        """

        gresource = GeoResource(self.connection, description_id)

        type_id = gresource.type_id
        type_name = self.main.get_type_name(type_id)

        (lat, lng), (lat_end, lng_end) = self.__get_lat_lng(type_name + "_Location", description_id)

        overlay_result = self.select.read(type_name + "_Overlays",
                                          where=[["Description_ID",
                                                  "=",
                                                  description_id]]
                                          )

        o_results = overlay_result.fetchall()
        overlays = []

        for overlay in o_results:
            details = {}
            details['color'] = overlay['Color']
            details['weight'] = overlay['Weight']
            details['opacity'] = overlay['Opacity']
            details['points'] = overlay['Points']
            details['numLevels'] = overlay['Num_Levels']
            details['zoomFactor'] = overlay['Zoom_Factor']
            details['overlayType'] = overlay['Overlay_Type']
            details['overlayName'] = overlay['Overlay_Name']
            overlays.append(details)

        locations = {}
        locations['lat'] = lat
        locations['lng'] = lng
        if lat_end and lng_end:
            locations['lat_end'] = lat_end
            locations['lng_end'] = lng_end
        locations['name'] = gresource.get_resource_name(type_name)
        locations['overlays'] = overlays
        return {"locations": [locations]}
Esempio n. 5
0
def view(did=None):

    if not did:
        did = flask.request.args.get("did", "")

    resource = GeoResource(db, description_id=did)

    select = Select(db)
    result = select.read("Associated_Infrastructure",
                            where=[["Parent_Plant_ID",
                                    "=",
                                    resource.parent_plant_id]]
                        )

    keys = result.column_names
    values = result.fetchall()
    html = []
    html.append("<ul>")
    for value in values:
        ai_parent_plant_id = value["Associated_Parent_Plant_ID"]
        ai_res = GeoResource(db, description_id=ai_parent_plant_id)
        html.append("<li>")
        html.append("<b><a href=\"/geoid/%s\" target=\"_blank\">%s</a></b><br/>" % (ai_res.get_latest_revision_id(),
                                                                                   ai_res.get_resource_name()))
        html.append("</li>")

    html.append("</ul>")
    """
    html.append('<div id="searchAI" class="ai-search-module">')
    html.append("<div id='aiDatabase_Type' class='aiSelectable'></div>")
    html.append("<div id='aiType' class='aiSelectable'></div>")
    html.append("<div id='aiCountry' class='aiSelectable'></div>")
    html.append("<div id='aiState' class='aiSelectable'></div>")
    html.append("<div class='aiUpdateButton' id='aiUpdateButton' style='padding-top: 10px;'>")
    html.append("<button id='createAIResource' class='createAIResource'>Add Associated Infrastructure</button>")
    html.append("</div>")

    html.append("</div>")
    html.append("<div id='aiResources' class='aiSelectable' style='top: 20px;'>")
    html.append("</div>")
    """
    return "".join(html)
Esempio n. 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)