Exemplo n.º 1
0
    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();
                if (instance.widget.default_style):
                    d = WidgetInstance.getFullOptionsDict(id=id)
                else:
                    d = WidgetInstance.getOptionsDict(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}
                d = WidgetInstanceDevice.getInstanceDict(instance_id=id)
                jsondevices = {'instance_id':id, 'devices':d}
                for socket in socket_connections:
                    socket.sendMessage(['widgetinstance-options', jsonoptions]);
                    socket.sendMessage(['widgetinstance-sensors', jsonsensors]);
                    socket.sendMessage(['widgetinstance-commands', jsoncommands]);
                    socket.sendMessage(['widgetinstance-devices', jsondevices]);
                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))
            section = Section.get(id)
            themeSectionStyle = Theme.getParamsDict(section.theme.id, ["section"])

            widgetForm = WidgetStyleForm(handler=self, prefix='params')

            for p, v in self.request.arguments.iteritems():
                if p.startswith( 'params' ):
                    if v[0] and not (p[0] == 'params-SectionBackgroundImage' and v[0] == themeSectionStyle['SectionBackgroundImage']):
                        SectionParam.saveKey(section_id=id, key=p[7:], value=v[0])
                    else:
                        SectionParam.delete(section_id=id, key=p[7:])

            # Send section updated params
            json = to_json(Section.get(id))
            json['params'] = Section.getParamsDict(id)
            WSHandler.sendAllMessage(['section-params', json])

            self.write("{success:true}")
        elif action=='addsection':
            s = Section.add(id, self.get_argument('sectionName'), self.get_argument('sectionDescription'))
            for p, v in self.request.arguments.iteritems():
                if p.startswith( 'params' ):
                    if v[0]:
                        SectionParam.saveKey(section_id=s.id, key=p[7:], value=v[0])
                        print s.id, p[7:], v[0]

            json = to_json(s)
            WSHandler.sendAllMessage(['section-added', json])
            self.write("{success:true}")
Exemplo n.º 2
0
    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();
                if (instance.widget.default_style):
                    d = WidgetInstance.getFullOptionsDict(id=id)
                else:
                    d = WidgetInstance.getOptionsDict(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}
                d = WidgetInstanceDevice.getInstanceDict(instance_id=id)
                jsondevices = {'instance_id':id, 'devices':d}
                for socket in socket_connections:
                    socket.sendMessage(['widgetinstance-options', jsonoptions]);
                    socket.sendMessage(['widgetinstance-sensors', jsonsensors]);
                    socket.sendMessage(['widgetinstance-commands', jsoncommands]);
                    socket.sendMessage(['widgetinstance-devices', jsondevices]);
                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))
            section = Section.get(id)
            themeSectionStyle = Theme.getParamsDict(section.theme.id, ["section"])

            widgetForm = WidgetStyleForm(handler=self, prefix='params')

            for p, v in self.request.arguments.iteritems():
                if p.startswith( 'params' ):
                    if v[0] and not (p[0] == 'params-SectionBackgroundImage' and v[0] == themeSectionStyle['SectionBackgroundImage']):
                        SectionParam.saveKey(section_id=id, key=p[7:], value=v[0])
                    else:
                        SectionParam.delete(section_id=id, key=p[7:])

            # Send section updated params
            json = to_json(Section.get(id))
            json['params'] = Section.getParamsDict(id)
            WSHandler.sendAllMessage(['section-params', json])

            self.write("{success:true}")
        elif action=='addsection':
            s = Section.add(id, self.get_argument('sectionName'), self.get_argument('sectionDescription'))
            for p, v in self.request.arguments.iteritems():
                if p.startswith( 'params' ):
                    if v[0]:
                        SectionParam.saveKey(section_id=s.id, key=p[7:], value=v[0])
                        print s.id, p[7:], v[0]

            json = to_json(s)
            WSHandler.sendAllMessage(['section-added', json])
            self.write("{success:true}")
Exemplo n.º 3
0
 def WSWidgetInstanceGetdevices(self, data):
     d = WidgetInstanceDevice.getInstanceDict(instance_id=data['instance_id'])
     json = {'instance_id':data['instance_id'], 'devices':d}
     return ['widgetinstance-devices', json];
Exemplo n.º 4
0
 def WSWidgetInstanceGetdevices(self, data):
     d = WidgetInstanceDevice.getInstanceDict(
         instance_id=data['instance_id'])
     json = {'instance_id': data['instance_id'], 'devices': d}
     return ['widgetinstance-devices', json]