Esempio n. 1
0
def objects_management():
    add_node_form = AddNode(request.form)
    add_link_form = AddLink(request.form)
    all_nodes = Node.choices()
    add_link_form.source.choices = add_link_form.destination.choices = all_nodes
    if request.method == 'POST':
        file = request.files['file']
        if allowed_file(secure_filename(file.filename), {'xls', 'xlsx'}):
            book = open_workbook(file_contents=file.read())
            for obj_type, cls in object_class.items():
                try:
                    sheet = book.sheet_by_name(obj_type)
                # if the sheet cannot be found, there's nothing to import
                except XLRDError:
                    continue
                properties = sheet.row_values(0)
                for row_index in range(1, sheet.nrows):
                    kwargs = dict(zip(properties, sheet.row_values(row_index)))
                    kwargs['type'] = obj_type
                    object_factory(**kwargs)
                db.session.commit()
    return render_template(
        'object_management.html',
        names=pretty_names,
        node_fields=node_public_properties,
        nodes=Node.serialize(),
        link_fields=link_public_properties,
        links=Link.serialize(),
        add_node_form=add_node_form,
        add_link_form=add_link_form
    )
Esempio n. 2
0
def pool_management():
    pool_object_form = PoolObjectsForm(request.form)
    pool_object_form.devices.choices = Device.choices()
    pool_object_form.links.choices = Link.choices()
    return render_template('pool_management.html',
                           form=AddPoolForm(request.form),
                           pool_object_form=pool_object_form,
                           names=pretty_names,
                           fields=pool_public_properties,
                           pools=Pool.serialize())
Esempio n. 3
0
def link_management():
    add_link_form = AddLink(request.form)
    all_devices = [(n.name, n.name) for n in Device.query.all()]
    add_link_form.source.choices = all_devices
    add_link_form.destination.choices = all_devices
    return render_template('link_management.html',
                           names=pretty_names,
                           fields=link_public_properties,
                           links=Link.serialize(),
                           add_link_form=add_link_form)
Esempio n. 4
0
def view(view_type):
    add_device_form = AddDevice(request.form)
    add_link_form = AddLink(request.form)
    all_devices = Device.choices()
    add_link_form.source.choices = all_devices
    add_link_form.destination.choices = all_devices
    view_options_form = ViewOptionsForm(request.form)
    google_earth_form = GoogleEarthForm(request.form)
    scheduling_form = SchedulingForm(request.form)
    scheduling_form.job.choices = Job.choices()
    scheduling_form.devices.choices = all_devices
    scheduling_form.pools.choices = Pool.choices()
    labels = {'device': 'name', 'link': 'name'}
    if 'view_options' in request.form:
        # update labels
        labels = {
            'device': request.form['device_label'],
            'link': request.form['link_label']
        }
    # for the sake of better performances, the view defaults to markercluster
    # if there are more than 2000 devices
    view = 'leaflet' if len(Device.query.all()) < 2000 else 'markercluster'
    if 'view' in request.form:
        view = request.form['view']
    # name to id
    name_to_id = {
        device.name: id for id, device in enumerate(Device.query.all())
    }
    return render_template(
        f'{view_type}_view.html',
        pools=Pool.query.all(),
        parameters=Parameters.query.one().serialized,
        view=view,
        scheduling_form=scheduling_form,
        view_options_form=view_options_form,
        google_earth_form=google_earth_form,
        add_device_form=add_device_form,
        add_link_form=add_link_form,
        device_fields=device_public_properties,
        link_fields=link_public_properties,
        labels=labels,
        names=pretty_names,
        device_subtypes=device_subtypes,
        link_colors=link_subtype_to_color,
        name_to_id=name_to_id,
        devices=Device.serialize(),
        links=Link.serialize()
    )
Esempio n. 5
0
def view(view_type):
    add_node_form = AddNode(request.form)
    add_link_form = AddLink(request.form)
    all_nodes = Node.choices()
    add_link_form.source.choices = add_link_form.destination.choices = all_nodes
    view_options_form = ViewOptionsForm(request.form)
    google_earth_form = GoogleEarthForm(request.form)
    scheduling_form = SchedulingForm(request.form)
    scheduling_form.scripts.choices = Script.choices()
    scheduling_form.nodes.choices = all_nodes
    scheduling_form.pools.choices = Pool.choices()
    labels = {'node': 'name', 'link': 'name'}
    if 'view_options' in request.form:
        # update labels
        labels = {
            'node': request.form['node_label'],
            'link': request.form['link_label']
        }
    # for the sake of better performances, the view defaults to markercluster
    # if there are more than 2000 nodes
    view = 'leaflet' if len(Node.query.all()) < 2000 else 'markercluster'
    if 'view' in request.form:
        view = request.form['view']
    # name to id
    name_to_id = {node.name: id for id, node in enumerate(Node.query.all())}
    return render_template('{}_view.html'.format(view_type),
                           pools=Pool.query.all(),
                           parameters=Parameters.query.one().serialized,
                           view=view,
                           scheduling_form=scheduling_form,
                           view_options_form=view_options_form,
                           google_earth_form=google_earth_form,
                           add_node_form=add_node_form,
                           add_link_form=add_link_form,
                           node_fields=node_public_properties,
                           link_fields=link_public_properties,
                           labels=labels,
                           names=pretty_names,
                           subtypes=list(node_class),
                           name_to_id=name_to_id,
                           nodes=Node.serialize(),
                           links=Link.serialize())
Esempio n. 6
0
def view(view_type):
    add_link_form = AddLink(request.form)
    all_devices = Device.choices()
    add_link_form.source.choices = all_devices
    add_link_form.destination.choices = all_devices
    labels = {'device': 'name', 'link': 'name'}
    if 'view_options' in request.form:
        labels = {
            'device': request.form['device_label'],
            'link': request.form['link_label']
        }
    if len(Device.query.all()) < 50:
        view = 'glearth'
    elif len(Device.query.all()) < 2000:
        view = 'leaflet'
    else:
        view = 'markercluster'
    if 'view' in request.form:
        view = request.form['view']
    # name to id
    name_to_id = {
        device.name: id
        for id, device in enumerate(Device.query.all())
    }
    return render_template(f'{view_type}_view.html',
                           pools=Pool.query.all(),
                           parameters=Parameters.query.one().serialized,
                           view=view,
                           view_options_form=ViewOptionsForm(request.form),
                           google_earth_form=GoogleEarthForm(request.form),
                           add_device_form=AddDevice(request.form),
                           add_link_form=add_link_form,
                           device_fields=device_public_properties,
                           link_fields=link_public_properties,
                           labels=labels,
                           names=pretty_names,
                           device_subtypes=device_subtypes,
                           link_colors=link_subtype_to_color,
                           name_to_id=name_to_id,
                           devices=Device.serialize(),
                           links=Link.serialize())