Example #1
0
 def loadThemes(cls, pack_path, develop):
     session = Session()
     # Load all Themes
     logger.info(u"PACKS: Loading themes")
     themes_path = os.path.join(pack_path, 'themes')
     session.query(Theme).delete()
     if os.path.isdir(themes_path):
         for file in os.listdir(themes_path):
             if not file.startswith('.'):  # not hidden file
                 info = os.path.join(themes_path, file, "info.json")
                 if os.path.isfile(info):
                     theme_file = open(info, "r")
                     theme_json = json.load(theme_file)
                     theme_id = theme_json["identity"]["id"]
                     theme_name = unicode(theme_json["identity"]["name"])
                     theme_version = theme_json["identity"]["version"]
                     t = Theme(id=theme_id,
                               name=theme_name,
                               version=theme_version,
                               style=unicode(json.dumps(
                                   theme_json['style'])))
                     if 'description' in theme_json["identity"]:
                         t.description = theme_json["identity"][
                             "description"]
                     session.add(t)
     session.commit()
     session.close()
Example #2
0
 def get(self):
     action = self.get_argument('action', None)
     id = self.get_argument('id', None)
     if action == 'widget':
         instance = WidgetInstance.get(id)
         forms = WidgetInstanceForms(instance=instance)
         self.render('widgetConfiguration.html',
                     instance=instance,
                     forms=forms)
     elif action == 'section':
         section = Section.get(id)
         params = Section.getParamsDict(id)
         themeWidgetsStyle = Theme.getParamsDict(section.theme.id,
                                                 ["widget"])
         options = SectionParam.getSection(section_id=id)
         dataOptions = dict([(r.key, r.value) for r in options])
         widgetForm = WidgetStyleForm(data=dataOptions, prefix='params')
         backgrounds = [{
             'type': 'uploaded',
             'href': 'backgrounds/thumbnails/%s' % f,
             'value': 'backgrounds/%s' % f
         } for f in os.listdir('/var/lib/domoweb/backgrounds')
                        if any(f.lower().endswith(x)
                               for x in ('.jpeg', '.jpg', '.gif', '.png'))]
         themeSectionStyle = Theme.getParamsDict(section.theme.id,
                                                 ["section"])
         if 'SectionBackgroundImage' in themeSectionStyle:
             href = "%s/thumbnails/%s" % (
                 os.path.dirname(
                     themeSectionStyle['SectionBackgroundImage']),
                 os.path.basename(
                     themeSectionStyle['SectionBackgroundImage']))
             backgrounds.insert(
                 0, {
                     'type': 'theme',
                     'href': href,
                     'value': themeSectionStyle['SectionBackgroundImage']
                 })
         self.render('sectionConfiguration.html',
                     section=section,
                     params=params,
                     backgrounds=backgrounds,
                     widgetForm=widgetForm,
                     themeWidgetsStyle=themeWidgetsStyle)
     elif action == 'addsection':
         self.render('sectionAdd.html')
Example #3
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}")
Example #4
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}")
Example #5
0
 def get(self):
     action = self.get_argument('action', None)
     id = self.get_argument('id', None)
     if action=='widget':
         instance = WidgetInstance.get(id);
         forms = WidgetInstanceForms(instance=instance)
         self.render('widgetConfiguration.html', instance=instance, forms=forms)
     elif action=='section':
         section = Section.get(id)
         params = Section.getParamsDict(id)
         themeWidgetsStyle = Theme.getParamsDict(section.theme.id, ["widget"])
         options = SectionParam.getSection(section_id=id)
         dataOptions = dict([(r.key, r.value) for r in options])
         widgetForm = WidgetStyleForm(data=dataOptions, prefix='params')
         backgrounds = [{'type':'uploaded', 'href': 'backgrounds/thumbnails/%s'%f, 'value': 'backgrounds/%s'%f} for f in os.listdir('/var/lib/domoweb/backgrounds') if any(f.lower().endswith(x) for x in ('.jpeg', '.jpg','.gif','.png'))]
         themeSectionStyle = Theme.getParamsDict(section.theme.id, ["section"])
         if 'SectionBackgroundImage' in themeSectionStyle:
             href = "%s/thumbnails/%s" % (os.path.dirname(themeSectionStyle['SectionBackgroundImage']), os.path.basename(themeSectionStyle['SectionBackgroundImage']))
             backgrounds.insert(0, {'type': 'theme', 'href': href, 'value': themeSectionStyle['SectionBackgroundImage']})
         self.render('sectionConfiguration.html', section=section, params=params, backgrounds=backgrounds, widgetForm=widgetForm, themeWidgetsStyle=themeWidgetsStyle)
     elif action=='addsection':
         self.render('sectionAdd.html')
Example #6
0
 def loadThemes(cls, pack_path, develop):
     session = Session()
     # Load all Themes
     logger.info(u"PACKS: Loading themes")
     themes_path = os.path.join(pack_path, 'themes')
     session.query(Theme).delete()
     if os.path.isdir(themes_path):
         for file in os.listdir(themes_path):
             if not file.startswith('.'): # not hidden file
                 info = os.path.join(themes_path, file, "info.json")
                 if os.path.isfile(info):
                     theme_file = open(info, "r")
                     theme_json = json.load(theme_file)
                     theme_id = theme_json["identity"]["id"]
                     theme_name = unicode(theme_json["identity"]["name"])
                     theme_version = theme_json["identity"]["version"]
                     t = Theme(id=theme_id, name=theme_name, version=theme_version, style=unicode(json.dumps(theme_json['style'])))
                     if 'description' in theme_json["identity"]:
                         t.description = theme_json["identity"]["description"]
                     session.add(t)
     session.commit()
     session.close()