Ejemplo n.º 1
0
def page_settings_nodes(db):
    user = bottle.request.get_user()

    nodes = db.query(DataCollectingNode).filter(
        DataCollectingNode.owner_id == user.user_id,
        DataCollectingNode.is_in_use == True).order_by(
            DataCollectingNode.dcn_name).all()

    res_nodes = []
    for node in nodes:
        node.devices_count = db.query(DataCollectingDevice).filter(
            DataCollectingDevice.dcn_id == node.dcn_id,
            DataCollectingDevice.is_in_use == True).count()

        res_nodes.append(node)

    breadcrumbs = {"path": [], "current": "Settings nodes"}

    params = get_page_template_values(
        {
            "user": bottle.request.get_user(),
            "nodes": res_nodes,
            "breadcrumbs": breadcrumbs
        },
        page_title="Settings nodes",
        page_header="Settings/Nodes",
        page_description="nodes list")

    return template("settings/settings_nodes_list.tpl", **params)
Ejemplo n.º 2
0
def page_node_information(db, node_uid):
    user = bottle.request.get_user()

    node = db.query(DataCollectingNode).filter(
        DataCollectingNode.owner_id == user.user_id,
        DataCollectingNode.dcn_uid == node_uid,
        DataCollectingNode.is_in_use == True).scalar()

    if node is None:
        bottle.abort(404)

    node.devices = db.query(DataCollectingDevice).filter(
        DataCollectingDevice.dcn_id == node.dcn_id,
        DataCollectingDevice.is_in_use == True).order_by(
            DataCollectingDevice.dcd_name).all()

    breadcrumbs = {"path": [("/brief", "Brief")], "current": node.dcn_name}

    params = get_page_template_values(
        {
            "user": bottle.request.get_user(),
            "node": node,
            "breadcrumbs": breadcrumbs,
        },
        page_title="Node [{}]".format(node.dcn_name),
        page_header=node.dcn_name,
        page_description="node information")

    return template("brief/node.tpl", **params)
Ejemplo n.º 3
0
def page_settings_devices(db):
    user = bottle.request.get_user()

    nodes = db.query(DataCollectingNode.dcn_id).filter(
        DataCollectingNode.owner_id == user.user_id,
        DataCollectingNode.is_in_use == True).subquery()

    data = db.query(DataCollectingDevice, DataCollectingNode).filter(
        DataCollectingDevice.dcn_id.in_(nodes),
        DataCollectingDevice.is_in_use == True).join(
            DataCollectingNode,
            DataCollectingDevice.dcn_id == DataCollectingNode.dcn_id).order_by(
                DataCollectingDevice.dcd_name).all()

    breadcrumbs = {"path": [], "current": "Settings devices"}

    params = get_page_template_values(
        {
            "user": bottle.request.get_user(),
            "data": data,
            "breadcrumbs": breadcrumbs
        },
        page_title="Settings devices",
        page_header="Settings/Devices",
        page_description="devices list")

    return template("settings/settings_devices_list.tpl", **params)
Ejemplo n.º 4
0
def page_brief_root(db):
    user = bottle.request.get_user()

    nodes = db.query(DataCollectingNode).filter(
        DataCollectingNode.owner_id == user.user_id,
        DataCollectingNode.is_in_use == True).order_by(
            DataCollectingNode.dcn_name).all()

    breadcrumbs = {"path": [], "current": "Brief"}

    avail_nodes = []
    for node in nodes:
        node.devices = db.query(DataCollectingDevice).filter(
            DataCollectingDevice.dcn_id == node.dcn_id,
            DataCollectingDevice.is_in_use == True).order_by(
                DataCollectingDevice.dcd_name).all()
        avail_nodes.append(node)

    params = get_page_template_values(
        {
            "user": bottle.request.get_user(),
            "nodes": avail_nodes,
            "breadcrumbs": breadcrumbs,
        },
        page_title="Brief",
        page_header="Data collecting nodes",
        page_description="list of avail node")

    return template("brief/root.tpl", **params)
Ejemplo n.º 5
0
def page_device_information(db, device_uid):
    user = bottle.request.get_user()

    data = db.query(DataCollectingDevice, DataCollectingNode).filter(
        DataCollectingDevice.dcd_uid == device_uid,
        DataCollectingDevice.is_in_use == True).join(
            DataCollectingNode,
            DataCollectingDevice.dcn_id == DataCollectingNode.dcn_id).filter(
                DataCollectingNode.owner_id == user.user_id,
                DataCollectingNode.is_in_use == True).first()

    if data is None:
        bottle.abort(404)

    dcd, dcn = data

    requests = db.query(LoggedRequest).filter(
        LoggedRequest.dcd_id == dcd.dcd_id,
        LoggedRequest.is_in_use == True).order_by(
            sqlalchemy.desc(LoggedRequest.adding_dts),
            sqlalchemy.desc(
                LoggedRequest.request_uid)).limit(MAX_REQUESTS_COUNT)

    res_requests = []
    for request in requests:
        parameters = db.query(RequestParameters).filter(
            RequestParameters.request_id == request.request_id,
            RequestParameters.is_in_use == True).order_by(
                RequestParameters.parameter_name,
                RequestParameters.adding_dts).limit(MAX_PARAMS_COUNT)

        request.parameters = parameters
        res_requests.append(request)

    dcd.requests = res_requests

    breadcrumbs = {
        "path": [("/brief", "Brief"),
                 ("/brief/node/{}".format(dcn.dcn_uid), dcn.dcn_name)],
        "current":
        dcd.dcd_name
    }

    params = get_page_template_values(
        {
            "user": bottle.request.get_user(),
            "device": dcd,
            "breadcrumbs": breadcrumbs,
            "max_params_count": MAX_PARAMS_COUNT,
            "max_requests_count": MAX_REQUESTS_COUNT
        },
        page_title="Device [{}]".format(dcd.dcd_name),
        page_header=dcd.dcd_name,
        page_description="device information [{}]".format(dcd.dcd_uid))

    return template("brief/device.tpl", **params)
Ejemplo n.º 6
0
def page_reports_all_requests():
    breadcrumbs = {"path": [], "current": "Reports - all requests"}

    params = get_page_template_values(
        {
            "user": bottle.request.get_user(),
            "breadcrumbs": breadcrumbs
        },
        page_title="Reports all requests",
        page_header="All requests",
        page_description="all requests list")

    return template("reports/all_requests.tpl", **params)
Ejemplo n.º 7
0
def page_request_for_device_information(db, device_uid, request_uid):
    user = bottle.request.get_user()

    data = db.query(DataCollectingDevice, DataCollectingNode).filter(
        DataCollectingDevice.dcd_uid == device_uid,
        DataCollectingDevice.is_in_use == True).join(
            DataCollectingNode,
            DataCollectingDevice.dcn_id == DataCollectingNode.dcn_id).filter(
                DataCollectingNode.owner_id == user.user_id,
                DataCollectingNode.is_in_use == True).first()

    if data is None:
        bottle.abort(404)

    request = db.query(LoggedRequest).filter(
        LoggedRequest.request_uid == request_uid,
        LoggedRequest.is_in_use == True).scalar()

    if request is None:
        bottle.abort(404)

    dcd, dcn = data

    parameters = db.query(RequestParameters).filter(
        RequestParameters.request_id == request.request_id,
        RequestParameters.is_in_use == True).order_by(
            RequestParameters.parameter_name).all()

    breadcrumbs = {
        "path": [("/brief", "Brief"),
                 ("/brief/node/{}".format(dcn.dcn_uid), dcn.dcn_name),
                 ("/brief/device/{}".format(dcd.dcd_uid), dcd.dcd_name)],
        "current":
        "Request details"
    }

    params = get_page_template_values(
        {
            "user": bottle.request.get_user(),
            "device": dcd,
            "node": dcn,
            "parameters": parameters,
            "request": request,
            "breadcrumbs": breadcrumbs
        },
        page_title="Request details".format(request_uid),
        page_header="Request details",
        page_description="uid = {}".format(request_uid))

    return template("brief/request.tpl", **params)
Ejemplo n.º 8
0
def page_settings_for_device(db, device_uid):
    user = bottle.request.get_user()

    data = db.query(DataCollectingDevice, DataCollectingNode).filter(
        DataCollectingDevice.dcd_uid == device_uid,
        DataCollectingDevice.is_in_use == True).join(
            DataCollectingNode,
            DataCollectingDevice.dcn_id == DataCollectingNode.dcn_id,
        ).filter(DataCollectingNode.owner_id == user.user_id,
                 DataCollectingNode.is_in_use == True).order_by(
                     DataCollectingDevice.dcd_name).first()

    if data is None:
        bottle.abort(404)

    device, node = data

    if bottle.request.method == "POST":
        dcd_name = bottle.request.forms.device_name
        dcd_description = bottle.request.forms.device_description

        device.dcd_name = dcd_name
        device.description = dcd_description
        device.update_dts = datetime.datetime.utcnow()

        db.flush()
        db.commit()

        bottle.redirect("/settings/devices")

    breadcrumbs = {
        "path": [("/settings/devices", "Settings-Devices")],
        "current": device.dcd_name
    }

    params = get_page_template_values(
        {
            "user": bottle.request.get_user(),
            "device": device,
            "node": node,
            "breadcrumbs": breadcrumbs,
            "info_message_title": "Info title",
            "info_message_text": "Info text, line1\nline2"
        },
        page_title="Settings/{}".format(device.dcd_name),
        page_header="{}".format(device.dcd_name),
        page_description="Settings for device ({})".format(device.dcd_name))

    return template("settings/settings_device.tpl", **params)
Ejemplo n.º 9
0
def page_settings_for_node(db, node_uid):
    user = bottle.request.get_user()

    node = db.query(DataCollectingNode).filter(
        DataCollectingNode.dcn_uid == node_uid,
        DataCollectingNode.owner_id == user.user_id,
        DataCollectingNode.is_in_use == True).scalar()

    if node is None:
        bottle.abort(404)

    if bottle.request.method == "POST":
        node_name = bottle.request.forms.node_name
        # node_uid = bottle.request.params.get("node_uid")
        node_description = bottle.request.forms.node_description

        node.dcn_name = node_name
        node.description = str(node_description).strip()
        node.update_dts = datetime.datetime.utcnow()

        db.flush()
        db.commit()

        bottle.redirect("/settings/nodes")

    breadcrumbs = {
        "path": [("/settings/nodes", "Settings-Nodes")],
        "current": node.dcn_name
    }

    params = get_page_template_values(
        {
            "user": bottle.request.get_user(),
            "node": node,
            "breadcrumbs": breadcrumbs
        },
        page_title="Settings/{}".format(node.dcn_name),
        page_header="{}".format(node.dcn_name),
        page_description="Settings for node ({})".format(node.dcn_uid))

    return template("settings/settings_node.tpl", **params)