Пример #1
0
 def component_update(self):
     ret_dict = {}
     controls = self.request.POST.items()
     comp_id = self.request.matchdict['comp_id']
     comp = DBSession.query(Component).filter_by(_id=comp_id).one()
     form = Form(ComponentSchema().bind(),
                 formid='edit_component_form_' + comp_id,
                 action=self.request.route_url('component_update', comp_id=comp_id),
                 use_ajax=True,
                 ajax_options='{"success": function (rText, sText, xhr, form) { edit_component(rText);}}',
                 buttons=('Save',))
     try:
         vals = form.validate(controls)
         ret_dict['error'] = False
     except ValidationFailure as e:
         ret_dict['error'] = True
         ret_dict['component'] = comp.serialize
         ret_dict['form'] = e.render()
         return ret_dict
     comp.name = vals['name']
     comp.description = vals['description']
     ret_dict['form'] = form.render(component=comp)
     ret_dict['component'] = comp.serialize
     self.request.redis.publish('component_changes', 'changed '+str(comp_id))
     return ret_dict
Пример #2
0
def parameter_panel(context, request):
    schema = EditParameterSchema().bind(parameter=context)
    edit_parameter_form = Form(
        schema,
        action=request.route_url('parameter_update', param_id=context.id),
        formid='edit_parameter_form_' + str(context.id),
        use_ajax=True,
        ajax_options='{"success": function (rText, sText, xhr, form) {'
        '  edit_parameter(rText);}}',
        buttons=('Save', ))
    sensor_name = 'No sensor selected'
    if context.sensor is not None:
        sensor_name = context.sensor.periphery_controller.name + '-->' + context.sensor.name
    return {
        'parameter':
        context,
        'sensor_name':
        sensor_name,
        'edit_parameter_form':
        edit_parameter_form.render(),
        'delete_href':
        request.route_url('parameter_delete', param_id=context.id),
        'calendar_href':
        request.route_url('calendar_param_home', param_id=context.id)
    }
Пример #3
0
 def log_diagram_save(self):
     ret_dict = {}
     controls = self.request.POST.items()
     form = Form(
         LogDiagramSchema().bind(),
         formid='add_log_diagram_form',
         action=self.request.route_url('log_diagram_save'),
         use_ajax=True,
         ajax_options=
         '{"success": function (rText, sText, xhr, form) { add_log_diagram(rText);}}',
         buttons=('Save', ))
     try:
         vals = form.validate(controls)
         ret_dict['error'] = False
     except ValidationFailure as e:
         ret_dict['error'] = True
         ret_dict['form'] = e.render()
         return ret_dict
     new_log_diagram = LogDiagram(vals['name'], vals['description'],
                                  vals['period'])
     DBSession.add(new_log_diagram)
     DBSession.flush()
     ret_dict['form'] = form.render()
     ret_dict[
         'log_diagram_panel'] = self.request.layout_manager.render_panel(
             'log_diagram_panel', context=new_log_diagram)
     return ret_dict
 def device_link_update(self):
     ret_dict = {}
     dl_id = self.request.matchdict['dl_id']
     ret_dict['device_link_id'] = dl_id
     controls = self.request.POST.items()
     dl = DBSession.query(DeviceLink).filter_by(_id=dl_id).one()
     form = Form(DeviceLinkSchema().bind(device_link=dl),
                 formid='edit_device_link_' + dl_id,
                 action=self.request.route_url('device_link_update', dl_id=dl_id),
                 use_ajax=True,
                 ajax_options='{"success": function (rText, sText, xhr, form) {edit_device_link(rText);}}',
                 buttons=('Save',))
     try:
         vals = form.validate(controls)
         ret_dict['form'] = form.render()
         ret_dict['error'] = False
     except ValidationFailure as e:
         ret_dict['form'] = e.render()
         ret_dict['error'] = True
         return ret_dict
     dl.device_id = vals['device']
     dl.target = vals['target']
     dl.color = vals['color']
     ret_dict['device_link'] = dl.serialize
     ret_dict['device_link_name'] = dl.device.name + '-->' + dl.target
     return ret_dict
Пример #5
0
 def calendar_param_entry_save(self):
     """
     save new calendar entry
     """
     ret_dict = {}
     controls = self.request.POST.items()
     param = DBSession.query(Parameter).filter_by(_id=self.request.matchdict['param_id']).one()
     last_entry = DBSession.query(CalendarEntry).filter_by(parameter_id=param.id).order_by(
         desc(CalendarEntry.entry_number)).first()
     add_form = Form(CalendarEntrySchema().bind(),
                     formid='add_param_calender_entry',
                     action=self.request.route_url('calendar_param_entry_save', param_id=param.id),
                     use_ajax=True,
                     ajax_options='{"success": function(rt, st, xhr, form) { add_calendar_param_entry(rt);}}',
                     buttons=('Save',))
     try:
         vals = add_form.validate(controls)
         ret_dict['error'] = False
     except ValidationFailure as e:
         ret_dict['error'] = True
         ret_dict['form'] = e.render()
         return ret_dict
     inter = DBSession.query(SetpointInterpolation).filter_by(_id=vals['interpolation']).one()
     index = 1
     if last_entry is not None:
         index = last_entry.entry_number + 1
     new_entry = CalendarEntry(param, index, inter)
     DBSession.add(new_entry)
     DBSession.flush()
     ret_dict['form'] = add_form.render()
     ret_dict['entry_panel'] = self.request.layout_manager.render_panel('calendar_param_entry', context=new_entry)
     self.request.redis.publish('calendar_changes', 'param ' + str(param.id))
     return ret_dict
Пример #6
0
 def regulator_save(self):
     ret_dict = {}
     controls = self.request.POST.items()
     form = Form(NewRegulatorSchema().bind(),
                 formid='add_regulator_form',
                 action=self.request.route_url('regulator_save'),
                 use_ajax=True,
                 ajax_options='{"success": function (rText, sText, xhr, form) {add_regulator(rText);}}',
                 buttons=('Save',))
     try:
         vals = form.validate(controls)
         ret_dict['error'] = False
     except ValidationFailure as e:
         ret_dict['form'] = e.render()
         ret_dict['error'] = True
         return ret_dict
     new_reg = Regulator(vals['name'], vals['algorithm'], vals['description'])
     real_reg = regulator_factory(new_reg.algorithm_name)
     real_reg.initialize_db(new_reg)
     DBSession.add(new_reg)
     DBSession.flush()
     ret_dict['form'] = form.render()
     ret_dict['regulator_panel'] = self.request.layout_manager.render_panel('regulator_panel', context=new_reg)
     self.request.redis.publish('regulator_changes', 'added '+str(new_reg.id))
     return ret_dict
Пример #7
0
 def interpolation_save(self):
     """
     save new setpoint interpolation
     """
     ret_dict = {}
     controls = self.request.POST.items()
     add_form = Form(SetpointInterpolationSchema().bind(),
                     formid='add_interpolation_form',
                     action=self.request.route_url('interpolation_save'),
                     use_ajax=True,
                     ajax_options='{"success": function(rText, sText, xhr, form) { add_interpolation(rText);}}',
                     buttons=('Save',))
     try:
         vals = add_form.validate(controls)
         ret_dict['error'] = False
     except ValidationFailure as e:
         ret_dict['error'] = True
         ret_dict['form'] = e.render()
         return ret_dict
     new_inter = SetpointInterpolation(vals['name'], vals['order'], vals['start_value'], vals['end_time'],
                                       vals['end_value'], vals['description'])
     DBSession.add(new_inter)
     DBSession.flush()
     ret_dict['form'] = add_form.render()
     ret_dict['interpolation_panel'] = self.request.layout_manager.render_panel('interpolation_panel',
                                                                                context=new_inter)
     filename = self.request.registry.settings['plot_directory'] + '/interpolation_' + str(new_inter.id) + '.png'
     new_inter.plot('', filename)
     self.request.redis.publish('calendar_changes', 'interpolation saved')
     return ret_dict
Пример #8
0
 def periphery_controller_update(self):
     ret_dict = {}
     controls = self.request.POST.items()
     pc = DBSession.query(PeripheryController).filter_by(
         _id=self.request.matchdict['pc_id']).one()
     form = Form(
         PeripheryControllerSchema().bind(),
         formid='edit_periphery_controller_form_' + str(pc.id),
         action=self.request.route_url('periphery_controller_update',
                                       pc_id=pc.id),
         use_ajax=True,
         ajax_options=
         '{"success": function (rText, sText, xhr, form) { edit_periphery_controller(rText);}}',
         buttons=('Save', ))
     try:
         vals = form.validate(controls)
         ret_dict['error'] = False
     except ValidationFailure as e:
         ret_dict['error'] = True
         ret_dict['periphery_controller'] = pc.serialize
         ret_dict['form'] = e.render()
         return ret_dict
     pc.name = vals['name']
     ret_dict['form'] = form.render(periphery_controller=pc)
     ret_dict['periphery_controller'] = pc.serialize
     self.request.redis.publish('periphery_controller_changes',
                                'changed ' + str(pc.id))
     return ret_dict
Пример #9
0
 def log_diagram_update(self):
     ret_dict = {}
     ld_id = self.request.matchdict['ld_id']
     ret_dict['log_diagram_id'] = ld_id
     controls = self.request.POST.items()
     ld = DBSession.query(LogDiagram).filter_by(_id=ld_id).one()
     form = Form(
         LogDiagramSchema().bind(log_diagram=ld),
         formid='edit_log_diagram_' + ld_id,
         action=self.request.route_url('log_diagram_update', ld_id=ld_id),
         use_ajax=True,
         ajax_options=
         '{"success": function (rText, sText, xhr, form) {edit_log_diagram(rText);}}',
         buttons=('Save', ))
     try:
         vals = form.validate(controls)
         ret_dict['form'] = form.render()
         ret_dict['error'] = False
     except ValidationFailure as e:
         ret_dict['form'] = e.render()
         ret_dict['error'] = True
         return ret_dict
     ld.name = vals['name']
     ld.description = vals['description']
     ld.period = vals['period']
     ret_dict['log_diagram'] = ld.serialize
     return ret_dict
Пример #10
0
 def device_update(self):
     ret_dict = {}
     if self.request.POST['actuator'] == 'None':
         self.request.POST['actuator'] = None
     controls = self.request.POST.items()
     dev_id = self.request.matchdict['dev_id']
     dev = DBSession.query(Device).filter_by(_id=dev_id).one()
     form = Form(EditDeviceSchema().bind(device=dev),
                 formid='edit_device_form_' + dev_id,
                 action=self.request.route_url('device_update', dev_id=dev_id),
                 use_ajax=True,
                 ajax_options='{"success": function (rText, sText, xhr, form) {edit_device(rText);}}',
                 buttons=('Save',))
     try:
         vals = form.validate(controls)
         ret_dict['error'] = False
     except ValidationFailure as e:
         ret_dict['error'] = True
         ret_dict['device'] = dev.serialize
         ret_dict['form'] = e.render()
         return ret_dict
     if vals['actuator'] is not None:
         dev.actuator = DBSession.query(Actuator).filter_by(_id=vals['actuator']).one()
     else:
         dev.actuator = None
     ret_dict['form'] = form.render(device=dev)
     ret_dict['device'] = dev.serialize
     if dev.actuator is not None:
         ret_dict['actuator_name'] = dev.actuator.periphery_controller.name + '-->' + dev.actuator.name
     self.request.redis.publish('device_changes', 'changed '+str(dev.id))
     return ret_dict
Пример #11
0
    def display_views_home(self):
        layout = self.request.layout_manager.layout
        layout.add_javascript(
            self.request.static_url('farmgui:static/js/jquery.flot.js'))
        layout.add_javascript(
            self.request.static_url('farmgui:static/js/jquery.flot.time.js'))
        layout.add_javascript(
            self.request.static_url('deform:static/scripts/deform.js'))
        layout.add_javascript(
            self.request.static_url('deform:static/scripts/jquery.form.js'))
        layout.add_javascript(
            self.request.static_url('farmgui:static/js/display_functions.js'))
        layout.add_css(
            self.request.static_url('farmgui:static/css/plot_parameter.css'))

        add_log_diagram_form = Form(
            LogDiagramSchema().bind(),
            action=self.request.route_url('log_diagram_save'),
            formid='add_log_diagram_form',
            use_ajax=True,
            ajax_options='{"success": function (rText, sText, xhr, form) {'
            'add_log_diagram(rText);}}',
            buttons=('Save', ))
        log_diagrams = DBSession.query(LogDiagram).all()
        return {
            'log_diagrams': log_diagrams,
            'add_log_diagram_form': add_log_diagram_form.render()
        }
Пример #12
0
 def device_link_update(self):
     ret_dict = {}
     dl_id = self.request.matchdict['dl_id']
     ret_dict['device_link_id'] = dl_id
     controls = self.request.POST.items()
     dl = DBSession.query(DeviceLink).filter_by(_id=dl_id).one()
     form = Form(
         DeviceLinkSchema().bind(device_link=dl),
         formid='edit_device_link_' + dl_id,
         action=self.request.route_url('device_link_update', dl_id=dl_id),
         use_ajax=True,
         ajax_options=
         '{"success": function (rText, sText, xhr, form) {edit_device_link(rText);}}',
         buttons=('Save', ))
     try:
         vals = form.validate(controls)
         ret_dict['form'] = form.render()
         ret_dict['error'] = False
     except ValidationFailure as e:
         ret_dict['form'] = e.render()
         ret_dict['error'] = True
         return ret_dict
     dl.device_id = vals['device']
     dl.target = vals['target']
     dl.color = vals['color']
     ret_dict['device_link'] = dl.serialize
     ret_dict['device_link_name'] = dl.device.name + '-->' + dl.target
     return ret_dict
Пример #13
0
 def parameter_update(self):
     ret_dict = {}
     if self.request.POST['sensor'] == 'None':
         self.request.POST['sensor'] = None
     controls = self.request.POST.items()
     param_id = self.request.matchdict['param_id']
     param = DBSession.query(Parameter).filter_by(_id=param_id).one()
     form = Form(EditParameterSchema().bind(parameter=param),
                 formid='edit_parameter_form_' + param_id,
                 action=self.request.route_url('parameter_update', param_id=param_id),
                 use_ajax=True,
                 ajax_options='{"success": function (rText, sText, xhr, form) { edit_parameter(rText);}}',
                 buttons=('Save',))
     try:
         vals = form.validate(controls)
         ret_dict['error'] = False
     except ValidationFailure as e:
         ret_dict['error'] = True
         ret_dict['parameter'] = param.serialize
         ret_dict['form'] = e.render()
         return ret_dict
     if vals['sensor'] is not None:
         param.sensor = DBSession.query(Sensor).filter_by(_id=vals['sensor']).one()
     else:
         param.sensor = None
     ret_dict['form'] = form.render(parameter=param)
     ret_dict['parameter'] = param.serialize
     if param.sensor is not None:
         ret_dict['sensor_name'] = param.sensor.periphery_controller.name + '-->' + param.sensor.name
     else:
         ret_dict['sensor_name'] = 'not connected'
     self.request.redis.publish('parameter_changes', 'changed ' + str(param.id))
     return ret_dict
 def log_diagram_update(self):
     ret_dict = {}
     ld_id = self.request.matchdict['ld_id']
     ret_dict['log_diagram_id'] = ld_id
     controls = self.request.POST.items()
     ld = DBSession.query(LogDiagram).filter_by(_id=ld_id).one()
     form = Form(LogDiagramSchema().bind(log_diagram=ld),
                 formid='edit_log_diagram_' + ld_id,
                 action=self.request.route_url('log_diagram_update', ld_id=ld_id),
                 use_ajax=True,
                 ajax_options='{"success": function (rText, sText, xhr, form) {edit_log_diagram(rText);}}',
                 buttons=('Save',))
     try:
         vals = form.validate(controls)
         ret_dict['form'] = form.render()
         ret_dict['error'] = False
     except ValidationFailure as e:
         ret_dict['form'] = e.render()
         ret_dict['error'] = True
         return ret_dict
     ld.name = vals['name']
     ld.description = vals['description']
     ld.period = vals['period']
     ret_dict['log_diagram'] = ld.serialize
     return ret_dict
Пример #15
0
 def device_link_save(self):
     ret_dict = {}
     controls = self.request.POST.items()
     dis_id = self.request.matchdict['dis_id']
     form = Form(
         DeviceLinkSchema().bind(),
         formid='add_device_link_form_' + dis_id,
         action=self.request.route_url('device_link_save', dis_id=dis_id),
         use_ajax=True,
         ajax_options=
         '{"success": function (rt, st, xhr, form) { add_device_link(rt);}}',
         buttons=('Save', ))
     try:
         vals = form.validate(controls)
         ret_dict['error'] = False
     except ValidationFailure as e:
         ret_dict['error'] = True
         ret_dict['form'] = e.render()
         return ret_dict
     display = DBSession.query(Display).filter_by(_id=dis_id).one()
     device = DBSession.query(Device).filter_by(_id=vals['device']).one()
     new_device_link = DeviceLink(display, device, vals['target'],
                                  vals['color'])
     DBSession.add(new_device_link)
     DBSession.flush()
     ret_dict['form'] = form.render()
     ret_dict[
         'device_link_panel'] = self.request.layout_manager.render_panel(
             'device_link_panel', context=new_device_link)
     ret_dict['device_link'] = new_device_link.serialize
     return ret_dict
Пример #16
0
 def component_input_update(self):
     ret_dict = {}
     if self.request.POST['connected_output'] == 'None':
         self.request.POST['connected_output'] = None
     controls = self.request.POST.items()
     comp_in_id = self.request.matchdict['comp_in_id']
     comp_in = DBSession.query(ComponentInput).filter_by(_id=comp_in_id).one()
     form = Form(ComponentInputSchema().bind(),
                 formid='edit_component_input_form_' + comp_in_id,
                 action=self.request.route_url('component_input_update', comp_in_id=comp_in_id),
                 use_ajax=True,
                 ajax_options='{"success": function (rText, sText, xhr, form) { edit_component_input(rText);}}',
                 buttons=('Save',))
     try:
         vals = form.validate(controls)
         ret_dict['error'] = False
     except ValidationFailure as e:
         ret_dict['error'] = True
         ret_dict['component_input'] = comp_in.serialize
         ret_dict['form'] = e.render()
         return ret_dict
     comp_in.connected_output_id = vals['connected_output']
     ret_dict['form'] = form.render(component_input=comp_in)
     ret_dict['component_input'] = comp_in.serialize
     connected_output_name = 'not connected'
     if comp_in.connected_output is not None:
         connected_output_name = comp_in.connected_output.component.name + ': ' + comp_in.connected_output.name
     ret_dict['connected_output_name'] = connected_output_name
     self.request.redis.publish('component_input_changes', str(comp_in_id))
     return ret_dict
Пример #17
0
 def parameter_save(self):
     """
     save new parameter
     """
     ret_dict = {}
     controls = self.request.POST.items()
     form = Form(NewParameterSchema().bind(),
                 formid='add_parameter_form',
                 action=self.request.route_url('parameter_save'),
                 use_ajax=True,
                 ajax_options='{"success": function (rText, sText, xhr, form) { add_parameter(rText);}}',
                 buttons=('Save',))
     try:
         vals = form.validate(controls)
         ret_dict['error'] = False
     except ValidationFailure as e:
         ret_dict['error'] = True
         ret_dict['form'] = e.render()
         return ret_dict
     parameter_type = DBSession.query(ParameterType).filter_by(_id=vals['parameter_type']).one()
     new_parameter = Parameter(vals['name'], parameter_type, None, vals['description'])
     DBSession.add(new_parameter)
     DBSession.flush()
     ret_dict['form'] = form.render()
     ret_dict['parameter_panel'] = self.request.layout_manager.render_panel('parameter_panel', context=new_parameter)
     self.request.redis.publish('parameter_changes', 'added '+str(new_parameter.id))
     return ret_dict
Пример #18
0
 def regulator_update(self):
     ret_dict = {}
     controls = self.request.POST.items()
     reg_id = self.request.matchdict['reg_id']
     reg = DBSession.query(Regulator).filter_by(_id=reg_id).one()
     form = Form(EditRegulatorSchema().bind(regulator=reg),
                 formid='edit_regulator_form_' + reg_id,
                 action=self.request.route_url('regulator_update', reg_id=reg_id),
                 use_ajax=True,
                 ajax_options='{"success": function (rText, sText, xhr, form) {edit_regulator(rText);}}',
                 buttons=('Save',))
     try:
         vals = form.validate(controls)
         ret_dict['error'] = False
     except ValidationFailure as e:
         ret_dict['error'] = True
         ret_dict['regulator'] = reg.serialize
         ret_dict['form'] = e.render()
         return ret_dict
     reg.algorithm_name = vals['algorithm']
     real_reg = regulator_factory(reg.algorithm_name)
     real_reg.initialize_db(reg)
     DBSession.flush()
     ret_dict['form'] = form.render(regulator=reg)
     ret_dict['regulator'] = reg.serialize
     ret_dict['regulator_panel'] = self.request.layout_manager.render_panel('regulator_panel', context=reg)
     self.request.redis.publish('regulator_changes', 'changed '+str(reg.id))
     return ret_dict
 def device_link_save(self):
     ret_dict = {}
     controls = self.request.POST.items()
     dis_id = self.request.matchdict['dis_id']
     form = Form(DeviceLinkSchema().bind(),
                 formid='add_device_link_form_' + dis_id,
                 action=self.request.route_url('device_link_save', dis_id=dis_id),
                 use_ajax=True,
                 ajax_options='{"success": function (rt, st, xhr, form) { add_device_link(rt);}}',
                 buttons=('Save',))
     try:
         vals = form.validate(controls)
         ret_dict['error'] = False
     except ValidationFailure as e:
         ret_dict['error'] = True
         ret_dict['form'] = e.render()
         return ret_dict
     display = DBSession.query(Display).filter_by(_id=dis_id).one()
     device = DBSession.query(Device).filter_by(_id=vals['device']).one()
     new_device_link = DeviceLink(display, device, vals['target'], vals['color'])
     DBSession.add(new_device_link)
     DBSession.flush()
     ret_dict['form'] = form.render()
     ret_dict['device_link_panel'] = self.request.layout_manager.render_panel('device_link_panel',
                                                                              context=new_device_link)
     ret_dict['device_link'] = new_device_link.serialize
     return ret_dict
Пример #20
0
def device_link_panel(context, request):
    form = Form(DeviceLinkSchema().bind(device_link=context),
                action=request.route_url('device_link_update', dl_id=context.id),
                formid='edit_device_link_form_' + str(context.id),
                use_ajax=True,
                ajax_options='{"success": function (rText, sText, xhr, form) { edit_device_link(rText);}}',
                buttons=('Save',))
    return {'device_link': context,
            'device_link_name': context.device.name + '-->' + context.target,
            'edit_device_link_form': form.render()}
def field_setting_panel(context, request):
    schema = FieldSettingSchema().bind(field_setting=context)
    edit_form = Form(schema,
                     action=request.route_url('field_setting_update', name=context.name),
                     formid='edit_field_setting_form_'+context.name,
                     use_ajax=True,
                     ajax_options='{"success": function (rText, sText, xhr, form) { edit_field_setting(rText);}}',
                     buttons=('Save',))
    return {'field_setting': context,
            'edit_form': edit_form.render()}
Пример #22
0
def field_setting_panel(context, request):
    schema = FieldSettingSchema().bind(field_setting=context)
    edit_form = Form(
        schema,
        action=request.route_url('field_setting_update', name=context.name),
        formid='edit_field_setting_form_' + context.name,
        use_ajax=True,
        ajax_options=
        '{"success": function (rText, sText, xhr, form) { edit_field_setting(rText);}}',
        buttons=('Save', ))
    return {'field_setting': context, 'edit_form': edit_form.render()}
Пример #23
0
def component_property_panel(context, request):
    schema = ComponentPropertySchema().bind(component_property=context)
    edit_form = Form(
        schema,
        action=request.route_url('component_property_update',
                                 comp_prop_id=context.id),
        formid='edit_component_property_form_' + str(context.id),
        use_ajax=True,
        ajax_options=
        '{"success": function (rText, sText, xhr, form) {edit_component_property(rText);}}',
        buttons=('Save', ))
    return {'component_property': context, 'edit_form': edit_form.render()}
Пример #24
0
 def calendar_dev_home(self):
     layout = self.request.layout_manager.layout
     layout.add_javascript(self.request.static_url('deform:static/scripts/deform.js'))
     layout.add_javascript(self.request.static_url('deform:static/scripts/jquery.form.js'))
     layout.add_javascript(self.request.static_url('farmgui:static/js/jquery.flot.js'))
     layout.add_javascript(self.request.static_url('farmgui:static/js/jquery.flot.time.js'))
     dev = DBSession.query(Device).filter_by(_id=self.request.matchdict['dev_id']).one()
     interpolations = DBSession.query(SetpointInterpolation).all()
     calendar_schema = CalendarEntrySchema().bind()
     add_calendar_form = Form(calendar_schema,
                              action=self.request.route_url('calendar_dev_entry_save', dev_id=dev.id),
                              formid='add_calendar_entry_form',
                              buttons=('Save',))
     interpolation_schema = SetpointInterpolationSchema().bind()
     add_interpolation_form = Form(interpolation_schema,
                                   action=self.request.route_url('interpolation_save'),
                                   formid='add_interpolation_form',
                                   buttons=('Save',))
     return {"page_title": dev.name + " Calendar",
             'calendar': dev.calendar,
             'interpolations': interpolations,
             'add_calendar_entry_form': add_calendar_form.render(),
             'add_interpolation_form': add_interpolation_form.render()}
Пример #25
0
def log_diagram_panel(context, request):
    add_parameter_link_form = Form(ParameterLinkSchema().bind(),
                                   action=request.route_url('parameter_link_save', dis_id=context.id),
                                   formid='add_parameter_link_form_' + str(context.id),
                                   use_ajax=True,
                                   ajax_options='{"success": function (rt, st, xhr, form) { add_parameter_link(rt);}}',
                                   buttons=('Save',))
    add_device_link_form = Form(DeviceLinkSchema().bind(),
                                action=request.route_url('device_link_save', dis_id=context.id),
                                formid='add_device_link_form_' + str(context.id),
                                use_ajax=True,
                                ajax_options='{"success": function (rt, st, xhr, form) { add_device_link(rt);}}',
                                buttons=('Save',))
    edit_log_diagram_form = Form(LogDiagramSchema().bind(log_diagram=context),
                                 action=request.route_url('log_diagram_update', ld_id=context.id),
                                 formid='edit_log_diagram_form_' + str(context.id),
                                 use_ajax=True,
                                 ajax_options='{"success": function (rt, st, xhr, form) { edit_log_diagram(rt);}}',
                                 buttons=('Save',))
    return {'log_diagram': context,
            'add_parameter_link_form': add_parameter_link_form.render(),
            'add_device_link_form': add_device_link_form.render(),
            'edit_log_diagram_form': edit_log_diagram_form.render()}
 def plant_settings_new(self):
     response_dict = dict()
     addForm = Form(PlantSettingsSchema(), formid='addForm', buttons=('Save',), use_ajax=True)
     form = addForm.render()
     if 'Save' in self.request.POST:
         controls = self.request.POST.items()
         try:
             values = addForm.validate(controls)
             new_setting = PlantSetting(values['Plant'], values['Variety'], values['Method'], values['Description'])
             PlantSettings_Session.add(new_setting)
             return HTTPFound(location=self.request.route_url('plant_settings_list'))
         except ValidationFailure as e:
             form = e.render()
     return {'addForm': form}
Пример #27
0
    def component_views_home(self):
        layout = self.request.layout_manager.layout
        # layout.add_css(self.request.static_url('deform_bootstrap:static/deform_bootstrap.css'))
        layout.add_javascript(self.request.static_url('farmgui:static/js/component_functions.js'))
        layout.add_javascript(self.request.static_url('deform:static/scripts/deform.js'))
        layout.add_javascript(self.request.static_url('deform:static/scripts/jquery.form.js'))

        add_parameter_form = Form(NewParameterSchema().bind(),
                                  action=self.request.route_url('parameter_save'),
                                  formid='add_parameter_form',
                                  use_ajax=True,
                                  ajax_options='{"success": function (rText, sText, xhr, form) {'
                                               'add_parameter(rText);}}',
                                  buttons=('Save',))
        add_device_form = Form(NewDeviceSchema().bind(),
                               action=self.request.route_url('device_save'),
                               formid='add_device_form',
                               use_ajax=True,
                               ajax_options='{"success": function (rText, sText, xhr, form) {'
                                            'add_device(rText);}}',
                               buttons=('Save',))
        add_regulator_form = Form(NewRegulatorSchema().bind(),
                                  action=self.request.route_url('regulator_save'),
                                  formid='add_regulator_form',
                                  use_ajax=True,
                                  ajax_options='{"success": function (rText, sText, xhr, form) {'
                                               'add_regulator(rText);}}',
                                  buttons=('Save',))
        parameters = DBSession.query(Parameter).all()
        devices = DBSession.query(Device).all()
        regulators = DBSession.query(Regulator).all()
        return {'parameters': parameters,
                'devices': devices,
                'regulators': regulators,
                'add_parameter_form': add_parameter_form.render(),
                'add_device_form': add_device_form.render(),
                'add_regulator_form': add_regulator_form.render()}
Пример #28
0
def regulator_panel(context, request):
    schema = EditRegulatorSchema().bind(regulator=context)
    edit_regulator_form = Form(
        schema,
        action=request.route_url('regulator_update', reg_id=context.id),
        formid='edit_regulator_form_' + str(context.id),
        use_ajax=True,
        ajax_options='{"success": function (rText, sText, xhr, form) {'
        '  edit_regulator(rText);}}',
        buttons=('Save', ))
    return {
        'regulator': context,
        'edit_regulator_form': edit_regulator_form.render(),
        'delete_href': request.route_url('regulator_delete', reg_id=context.id)
    }
Пример #29
0
def periphery_controller_panel(context, request):
    schema = PeripheryControllerSchema().bind(periphery_controller=context)
    form = Form(
        schema,
        action=request.route_url("periphery_controller_update", pc_id=context.id),
        formid="edit_periphery_controller_form_" + str(context.id),
        use_ajax=True,
        ajax_options='{"success": function (rText, sText, xhr, form) { edit_periphery_controller(rText);}}',
        buttons=("Save",),
    )
    return {
        "periphery_controller": context,
        "delete_href": request.route_url("periphery_controller_delete", pc_id=context.id),
        "edit_periphery_controller_form": form.render(),
    }
Пример #30
0
 def stage_new(self):
     response_dict = dict()
     addForm = Form(StageSchema(), formid='addForm', buttons=('Save',), use_ajax=True)
     form = addForm.render()
     if 'Save' in self.request.POST:
         controls = self.request.POST.items()
         try:
             plant_setting = PlantSettings_Session.query(PlantSetting).filter(PlantSetting._id==self.request.matchdict['_id']).first()
         except DBAPIError:
             return Response('database error.', content_type='text/plain', status_int=500)
         try:
             values = addForm.validate(controls)
             new_stage = Stage(plant_setting, values['Number'], values['Duration'], values['Name'], values['Description'])
             PlantSettings_Session.add(new_stage)
             return HTTPFound(location=self.request.route_url('plant_settings_view', _id=plant_setting._id))
         except ValidationFailure as e:
             form = e.render()
     return {'addForm': form}
Пример #31
0
def component_input_panel(context, request):
    schema = ComponentInputSchema().bind(component_input=context)
    edit_form = Form(
        schema,
        action=request.route_url('component_input_update',
                                 comp_in_id=context.id),
        formid='edit_component_input_form_' + str(context.id),
        use_ajax=True,
        ajax_options='{"success": function (rText, sText, xhr, form) {'
        '  edit_component_input(rText);}}',
        buttons=('Save', ))
    connected_output_name = 'not connected'
    if context.connected_output is not None:
        connected_output_name = context.connected_output.component.name + ': ' + context.connected_output.name
    return {
        'component_input': context,
        'connected_output_name': connected_output_name,
        'edit_component_input_form': edit_form.render()
    }
Пример #32
0
def periphery_controller_panel(context, request):
    schema = PeripheryControllerSchema().bind(periphery_controller=context)
    form = Form(
        schema,
        action=request.route_url('periphery_controller_update',
                                 pc_id=context.id),
        formid='edit_periphery_controller_form_' + str(context.id),
        use_ajax=True,
        ajax_options=
        '{"success": function (rText, sText, xhr, form) { edit_periphery_controller(rText);}}',
        buttons=('Save', ))
    return {
        'periphery_controller':
        context,
        'delete_href':
        request.route_url('periphery_controller_delete', pc_id=context.id),
        'edit_periphery_controller_form':
        form.render()
    }
    def display_views_home(self):
        layout = self.request.layout_manager.layout
        layout.add_javascript(self.request.static_url('farmgui:static/js/jquery.flot.js'))
        layout.add_javascript(self.request.static_url('farmgui:static/js/jquery.flot.time.js'))
        layout.add_javascript(self.request.static_url('deform:static/scripts/deform.js'))
        layout.add_javascript(self.request.static_url('deform:static/scripts/jquery.form.js'))
        layout.add_javascript(self.request.static_url('farmgui:static/js/display_functions.js'))
        layout.add_css(self.request.static_url('farmgui:static/css/plot_parameter.css'))

        add_log_diagram_form = Form(LogDiagramSchema().bind(),
                                    action=self.request.route_url('log_diagram_save'),
                                    formid='add_log_diagram_form',
                                    use_ajax=True,
                                    ajax_options='{"success": function (rText, sText, xhr, form) {'
                                                 'add_log_diagram(rText);}}',
                                    buttons=('Save',))
        log_diagrams = DBSession.query(LogDiagram).all()
        return {'log_diagrams': log_diagrams,
                'add_log_diagram_form': add_log_diagram_form.render()}
Пример #34
0
 def plant_settings_new(self):
     response_dict = dict()
     addForm = Form(PlantSettingsSchema(),
                    formid='addForm',
                    buttons=('Save', ),
                    use_ajax=True)
     form = addForm.render()
     if 'Save' in self.request.POST:
         controls = self.request.POST.items()
         try:
             values = addForm.validate(controls)
             new_setting = PlantSetting(values['Plant'], values['Variety'],
                                        values['Method'],
                                        values['Description'])
             PlantSettings_Session.add(new_setting)
             return HTTPFound(
                 location=self.request.route_url('plant_settings_list'))
         except ValidationFailure as e:
             form = e.render()
     return {'addForm': form}
Пример #35
0
 def parameters_new(self):
     response_dict = dict()
     addForm = Form(ParameterSchema(),
                    formid='addForm',
                    buttons=('Save', ),
                    use_ajax=True)
     form = addForm.render()
     if 'Save' in self.request.POST:
         controls = self.request.POST.items()
         try:
             values = addForm.validate(controls)
             new_parameter = Parameter(values['Name'], values['Unit'],
                                       values['Minimum'], values['Maximum'],
                                       values['Description'])
             PlantSettings_Session.add(new_parameter)
             return HTTPFound(
                 location=self.request.route_url('parameters_list'))
         except ValidationFailure as e:
             form = e.render()
     return {'addForm': form}
Пример #36
0
def device_panel(context, request):
    schema = EditDeviceSchema().bind(device=context)
    edit_device_form = Form(
        schema,
        action=request.route_url('device_update', dev_id=context.id),
        formid='edit_device_form_' + str(context.id),
        use_ajax=True,
        ajax_options='{"success": function (rText, sText, xhr, form) {'
        '  edit_device(rText);}}',
        buttons=('Save', ))
    actuator_name = 'No actuator selected'
    if context.actuator is not None:
        actuator_name = context.actuator.periphery_controller.name + '-->' + context.actuator.name
    return {
        'device': context,
        'actuator_name': actuator_name,
        'edit_device_form': edit_device_form.render(),
        'delete_href': request.route_url('device_delete', dev_id=context.id),
        'calendar_href': request.route_url('calendar_dev_home',
                                           dev_id=context.id)
    }
 def interpolation_knot_update(self):
     ret_dict = {}
     try:
         knot = DBSession.query(InterpolationKnot).filter_by(_id=self.request.matchdict['knot_id']).first()
         inter = DBSession.query(SetpointInterpolation).filter_by(
             _id=self.request.matchdict['inter_id']).first()
     except DBAPIError:
         return Response('database error (query InterpolationKnot)', content_type='text/plain', status_int=500)
     form = Form(InterpolationKnotSchema().bind(knot=knot), buttons=('Save',))
     controls = self.request.POST
     controls['interpolation_id'] = inter.id
     try:
         values = form.validate(controls.items())
     except ValidationFailure as e:
         return {'error_form': e.render()}
     knot.time = values['time']
     knot.value = values['value']
     filename = self.request.registry.settings['plot_directory'] + '/interpolation_' + str(inter.id) + '.png'
     inter.plot('', filename)
     self.request.redis.publish('parameter_changes', 'interpolation changed')
     ret_dict['form'] = form.render()
     ret_dict['knot_panel'] = self.request.layout_manager.render_panel('interpolation_knot_panel', context=knot)
     return ret_dict
Пример #38
0
 def setting_views_update(self):
     ret_dict = {}
     controls = self.request.POST.items()
     fs = DBSession.query(FieldSetting).filter_by(name=self.request.matchdict['name']).one()
     form = Form(FieldSettingSchema().bind(),
                 formid='edit_field_setting_form_' + fs.name,
                 action=self.request.route_url('field_setting_update', name=fs.name),
                 use_ajax=True,
                 ajax_options='{"success": function (rText, sText, xhr, form) { edit_field_setting(rText);}}',
                 buttons=('Save',))
     try:
         vals = form.validate(controls)
         ret_dict['error'] = False
     except ValidationFailure as e:
         ret_dict['error'] = True
         ret_dict['field_setting'] = fs.serialize
         ret_dict['form'] = e.render()
         return ret_dict
     fs.value = vals['value']
     ret_dict['form'] = form.render(field_setting=fs)
     ret_dict['field_setting'] = fs.serialize
     self.request.redis.publish('field_setting_changes', fs.name)
     return ret_dict
 def log_diagram_save(self):
     ret_dict = {}
     controls = self.request.POST.items()
     form = Form(LogDiagramSchema().bind(),
                 formid='add_log_diagram_form',
                 action=self.request.route_url('log_diagram_save'),
                 use_ajax=True,
                 ajax_options='{"success": function (rText, sText, xhr, form) { add_log_diagram(rText);}}',
                 buttons=('Save',))
     try:
         vals = form.validate(controls)
         ret_dict['error'] = False
     except ValidationFailure as e:
         ret_dict['error'] = True
         ret_dict['form'] = e.render()
         return ret_dict
     new_log_diagram = LogDiagram(vals['name'], vals['description'], vals['period'])
     DBSession.add(new_log_diagram)
     DBSession.flush()
     ret_dict['form'] = form.render()
     ret_dict['log_diagram_panel'] = self.request.layout_manager.render_panel('log_diagram_panel',
                                                                              context=new_log_diagram)
     return ret_dict
 def periphery_controller_update(self):
     ret_dict = {}
     controls = self.request.POST.items()
     pc = DBSession.query(PeripheryController).filter_by(_id=self.request.matchdict['pc_id']).one()
     form = Form(PeripheryControllerSchema().bind(),
                 formid='edit_periphery_controller_form_' + str(pc.id),
                 action=self.request.route_url('periphery_controller_update', pc_id=pc.id),
                 use_ajax=True,
                 ajax_options='{"success": function (rText, sText, xhr, form) { edit_periphery_controller(rText);}}',
                 buttons=('Save',))
     try:
         vals = form.validate(controls)
         ret_dict['error'] = False
     except ValidationFailure as e:
         ret_dict['error'] = True
         ret_dict['periphery_controller'] = pc.serialize
         ret_dict['form'] = e.render()
         return ret_dict
     pc.name = vals['name']
     ret_dict['form'] = form.render(periphery_controller=pc)
     ret_dict['periphery_controller'] = pc.serialize
     self.request.redis.publish('periphery_controller_changes', 'changed '+str(pc.id))
     return ret_dict
 def component_property_update(self):
     ret_dict = {}
     prop_id = self.request.matchdict['comp_prop_id']
     ret_dict['component_property_id'] = prop_id
     controls = self.request.POST.items()
     prop = DBSession.query(ComponentProperty).filter_by(_id=prop_id).one()
     form = Form(ComponentPropertySchema().bind(),
                 formid='edit_component_property_' + prop_id,
                 action=self.request.route_url('component_property_update', comp_prop_id=prop_id),
                 use_ajax=True,
                 ajax_options='{"success": function (rText, sText, xhr, form) {edit_component_property(rText);}}',
                 buttons=('Save',))
     try:
         vals = form.validate(controls)
         ret_dict['form'] = form.render()
         ret_dict['error'] = False
     except ValidationFailure as e:
         ret_dict['form'] = e.render()
         ret_dict['error'] = True
         return ret_dict
     prop.value = vals['value']
     ret_dict['component_property'] = prop.serialize
     self.request.redis.publish('component_property_changes', str(prop.id))
     return ret_dict