def save(self): for key, value in self.data.iteritems(): if isinstance(value, list): value = ', '.join(value) WidgetInstanceOption.saveKey(instance_id=self.instance.id, key=key, value=value)
def save(self): self.optionsform.save() self.sensorsform.save() self.commandsform.save() self.devicesform.save() # General for key, value in self.generalform.data.iteritems(): if isinstance(value, list): value = ', '.join(value) if value: WidgetInstanceOption.saveKey(instance_id=self.instance.id, key=key, value=value) else: WidgetInstanceOption.delete(instance_id=self.instance.id, key=key) # General for key, value in self.styleform.data.iteritems(): if isinstance(value, list): value = ', '.join(value) if value: WidgetInstanceOption.saveKey(instance_id=self.instance.id, key=key, value=value) else: WidgetInstanceOption.delete(instance_id=self.instance.id, key=key)
def post(self): action = self.get_argument('action', None) id = self.get_argument('id', None) if action=='widget': instance = WidgetInstance.get(id); forms = WidgetInstanceForms(instance=instance, handler=self) if forms.validate(): forms.save(); d = WidgetInstanceOption.getInstanceDict(instance_id=id) jsonoptions = {'instance_id':id, 'options':d} d = WidgetInstanceSensor.getInstanceDict(instance_id=id) jsonsensors = {'instance_id':id, 'sensors':d} d = WidgetInstanceCommand.getInstanceDict(instance_id=id) jsoncommands = {'instance_id':id, 'commands':d} for socket in socket_connections: socket.sendMessage(['widgetinstance-options', jsonoptions]); socket.sendMessage(['widgetinstance-sensors', jsonsensors]); socket.sendMessage(['widgetinstance-commands', jsoncommands]); self.write("{success:true}") else: self.render('widgetConfiguration.html', instance=instance, forms=forms) elif action=='section': Section.update(id, self.get_argument('sectionName'), self.get_argument('sectionDescription', None)) for p, v in self.request.arguments.iteritems(): if p.startswith( 'params' ): SectionParam.saveKey(section_id=id, key=p[6:], value=v[0]) json = to_json(Section.get(id)) json['params'] = dict ((p.key, p.value) for p in SectionParam.getSection(id)) for socket in socket_connections: socket.sendMessage(['section-details', json]) self.write("{success:true}")
def __init__(self, instance, handler=None): self.instance = instance class OptionsForm(WidgetOptionsForm): pass class SensorsForm(WidgetSensorsForm): pass class CommandsForm(WidgetCommandsForm): pass class DevicesForm(WidgetDevicesForm): pass widgetoptions = WidgetOption.getWidget(instance.widget_id) if widgetoptions: self.has_options = True widgetsensors = WidgetSensor.getWidget(instance.widget_id) if widgetsensors: self.has_sensors = True widgetcommands = WidgetCommand.getWidget(instance.widget_id) if widgetcommands: self.has_commands = True widgetdevices = WidgetDevice.getWidget(instance.widget_id) if widgetdevices: self.has_devices = True if not handler: options = WidgetInstanceOption.getInstance(instance.id) dataOptions = dict([(r.key, r.value) for r in options]) sensors = WidgetInstanceSensor.getInstance(instance.id) dataSensors = dict([(r.key, r.sensor_id) for r in sensors]) commands = WidgetInstanceCommand.getInstance(instance.id) dataCommands = dict([(r.key, r.command_id) for r in commands]) devices = WidgetInstanceDevice.getInstance(instance.id) dataDevices = dict([(r.key, r.device_id) for r in devices]) else: dataOptions = None dataSensors = None dataCommands = None dataDevices = None for option in widgetoptions: OptionsForm.addField(option=option) for option in widgetsensors: SensorsForm.addField(option=option) for option in widgetcommands: CommandsForm.addField(option=option) for option in widgetdevices: DevicesForm.addField(option=option) self.optionsform = OptionsForm(instance=instance, handler=handler, data=dataOptions, prefix='optionparam_') self.sensorsform = SensorsForm(instance=instance, handler=handler, data=dataSensors, prefix='sensorparam_') self.commandsform = CommandsForm(instance=instance, handler=handler, data=dataCommands, prefix='commandparam_') self.devicesform = DevicesForm(instance=instance, handler=handler, data=dataDevices, prefix='deviceparam_') self.generalform = WidgetGeneralForm(handler=handler, data=dataOptions, prefix='generalparam_') self.styleform = WidgetStyleForm(handler=handler, data=dataOptions, prefix='styleparam_')
def WSWidgetInstanceGetoptions(self, data): d = WidgetInstanceOption.getInstanceDict(instance_id=data['instance_id']) json = {'instance_id':data['instance_id'], 'options':d} return ['widgetinstance-options', json];
def __init__(self, instance, handler=None): self.instance = instance class OptionsForm(WidgetOptionsForm): pass class SensorsForm(WidgetSensorsForm): pass class CommandsForm(WidgetCommandsForm): pass class DevicesForm(WidgetDevicesForm): pass widgetoptions = WidgetOption.getWidget(instance.widget_id) if widgetoptions: self.has_options = True widgetsensors = WidgetSensor.getWidget(instance.widget_id) if widgetsensors: self.has_sensors = True widgetcommands = WidgetCommand.getWidget(instance.widget_id) if widgetcommands: self.has_commands = True widgetdevices = WidgetDevice.getWidget(instance.widget_id) if widgetdevices: self.has_devices = True if not handler: options = WidgetInstanceOption.getInstance(instance.id) dataOptions = dict([(r.key, r.value) for r in options]) sensors = WidgetInstanceSensor.getInstance(instance.id) dataSensors = dict([(r.key, r.sensor_id) for r in sensors]) # Rebuild array values reg = re.compile(r"(.*)-(\d+)") tmpdict = {} for k, v in dataSensors.iteritems(): res = reg.match(k) if res: if (res.group(1) not in tmpdict): tmpdict[res.group(1)] = [] tmpdict[res.group(1)].append(v) dataSensors = dict(dataSensors.items() + tmpdict.items()) commands = WidgetInstanceCommand.getInstance(instance.id) dataCommands = dict([(r.key, r.command_id) for r in commands]) devices = WidgetInstanceDevice.getInstance(instance.id) dataDevices = dict([(r.key, r.device_id) for r in devices]) else: dataOptions = None dataSensors = None dataCommands = None dataDevices = None for option in widgetoptions: OptionsForm.addField(option=option) for option in widgetsensors: SensorsForm.addField(option=option) for option in widgetcommands: CommandsForm.addField(option=option) for option in widgetdevices: DevicesForm.addField(option=option) self.optionsform = OptionsForm(instance=instance, handler=handler, data=dataOptions, prefix='optionparam_') self.sensorsform = SensorsForm(instance=instance, handler=handler, data=dataSensors, prefix='sensorparam_') self.commandsform = CommandsForm(instance=instance, handler=handler, data=dataCommands, prefix='commandparam_') self.devicesform = DevicesForm(instance=instance, handler=handler, data=dataDevices, prefix='deviceparam_') self.generalform = WidgetGeneralForm(handler=handler, data=dataOptions, prefix='generalparam_') self.styleform = WidgetStyleForm(handler=handler, data=dataOptions, prefix='styleparam_')