Exemple #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();
                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}")
Exemple #2
0
 def get(self, id):
     if not id:
         id = 1
     section = Section.get(id)
     packs = Widget.getSectionPacks(section_id=id)
     params = Section.getParamsDict(id)
     sections = Section.getTree()
     self.render('base.html',
         section = section,
         params = params,
         packs = packs,
         sections = sections,
         )
Exemple #3
0
 def get(self, id):
     if not id:
         id = 1
     section = Section.get(id)
     packs = Widget.getSectionPacks(section_id=id)
     params = Section.getParamsDict(id)
     sections = Section.getTree()
     self.render(
         'base.html',
         section=section,
         params=params,
         packs=packs,
         sections=sections,
     )
Exemple #4
0
 def get(self):
     action = self.get_argument('action', None)
     id = self.get_argument('id', None)
     # Widget section box
     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)
         options = SectionParam.getSection(section_id=id)
         dataOptions = dict([(r.key, r.value) for r in options])
         widgetForm = WidgetStyleForm(data=dataOptions, prefix='params')
         backgrounds = [f for f in os.listdir('/var/lib/domoweb/backgrounds') if any(f.lower().endswith(x) for x in ('.jpeg', '.jpg','.gif','.png'))]
         self.render('sectionConfiguration.html', section=section, params=params, backgrounds=backgrounds, widgetForm=widgetForm)
Exemple #5
0
 def get(self, id):
     if not id:
         id = 1
     section = Section.get(id)
     widgets = Widget.getSection(section_id=id)
     packs = Widget.getSectionPacks(section_id=id)
     instances = WidgetInstance.getSection(section_id=id)
     for j, i in enumerate(instances):
         i.optionsdict = WidgetInstance.getOptionsDict(id=i.id)
     params = Section.getParamsDict(id)
     self.render('base.html',
         section = section,
         params = params,
         widgets = widgets,
         packs = packs,
         instances = instances,
         )
Exemple #6
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')
Exemple #7
0
    def WSSectionGet(self, data):
        section = Section.get(data['id'])
        widgets = Widget.getSection(section_id=data['id'])
        instances = WidgetInstance.getSection(section_id=data['id'])
        j = to_json(section)
        j['params'] = Section.getParamsDict(data['id'])
        j["widgets"] = to_json(widgets)
        j["instances"] = to_json(instances)
        for index, item in enumerate(instances):
            if item.widget:
                j['instances'][index]["widget"] = to_json(item.widget)
            try:
                optionsdict = WidgetInstance.getOptionsDict(id=item.id)
                j['instances'][index]["options"] = optionsdict
            except:
                logger.error("Error while getting options for a widget instance. Maybe you delete a widget folder but it is still defined in database? Error: {0}".format(traceback.format_exc()))

        return ['section-details', j]
Exemple #8
0
    def WSSectionGet(self, data):
        section = Section.get(data['id'])
        widgets = Widget.getSection(section_id=data['id'])
        instances = WidgetInstance.getSection(section_id=data['id'])
        j = to_json(section)
        j['params'] = Section.getParamsDict(data['id'])
        j["widgets"] = to_json(widgets)
        j["instances"] = to_json(instances)
        for index, item in enumerate(instances):
            if item.widget:
                j['instances'][index]["widget"] = to_json(item.widget)
            try:
                optionsdict = WidgetInstance.getOptionsDict(id=item.id)
                j['instances'][index]["options"] = optionsdict
            except:
                logger.error("Error while getting options for a widget instance. Maybe you delete a widget folder but it is still defined in database? Error: {0}".format(traceback.format_exc()))

        return ['section-details', j]
Exemple #9
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}
                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))

            widgetForm = WidgetStyleForm(handler=self, prefix='params')
            for p, v in self.request.arguments.iteritems():
                if p.startswith( 'params' ):
                    if v[0]:
                        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-details', json])

            self.write("{success:true}")
Exemple #10
0
def updateDb(user, db):
    from domoweb.models import metadata, engine, Session, Section, SectionParam
    from sqlalchemy import create_engine, func
    from alembic.config import Config
    from alembic import command

    alembic_cfg = Config("alembic.ini")
    if not os.path.isfile(db):
        ok("Creating new database: %s" % db)
        metadata.create_all(engine)
        command.stamp(alembic_cfg, "head")
        uid = pwd.getpwnam(user).pw_uid
        os.chown(db, uid, -1)

        ok("Adding initial data")
        session = Session()
        s = Section(name=unicode('Root'),
                    description=unicode('Root dashboard'),
                    left=1,
                    right=2)
        session.add(s)
        p = SectionParam(section_id=1, key='GridWidgetSize', value='100')
        session.add(p)
        p = SectionParam(section_id=1, key='GridWidgetSpace', value='20')
        session.add(p)
        p = SectionParam(section_id=1, key='GridMode', value='3')
        session.add(p)
        session.commit()
    else:
        ok("Upgrading existing database")
        session = Session()
        sections = session.query(Section).all()
        for s in sections:
            p = session.query(SectionParam).filter_by(section_id=s.id).filter(
                SectionParam.key.in_([
                    'GridWidgetSize', 'GridWidgetSpace', 'GridColumns',
                    'GridRows'
                ])).count()
            if p == 0:
                ok("Updating section '%s'" % s.name)
                p = SectionParam(section_id=s.id,
                                 key='GridWidgetSize',
                                 value='100')
                session.add(p)
                p = SectionParam(section_id=s.id,
                                 key='GridWidgetSpace',
                                 value='20')
                session.add(p)
                p = SectionParam(section_id=s.id, key='GridMode', value='3')
                session.add(p)
                session.commit()

        command.upgrade(alembic_cfg, "head")
Exemple #11
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')
Exemple #12
0
 def get(self, id):
     if not id:
         id = 1
     section = Section.get(id)
     params = dict ((p.key, p.value) for p in SectionParam.getSection(id))
     widgets = Widget.getSection(section_id=id)
     packs = Widget.getSectionPacks(section_id=id)
     self.render('base.html',
         section = section,
         params = params,
         widgets = widgets,
         packs = packs,
         )
Exemple #13
0
 def get(self):
     action = self.get_argument('action', None)
     id = self.get_argument('id', None)
     # Widget section box
     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 = dict ((p.key, p.value) for p in SectionParam.getSection(id))
         backgrounds = [f for f in os.listdir('/var/lib/domoweb/backgrounds') if any(f.lower().endswith(x) for x in ('.jpeg', '.jpg','.gif','.png'))]
         self.render('sectionConfiguration.html', section=section, params=params, backgrounds=backgrounds)
Exemple #14
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}")
Exemple #15
0
 def WSSectionGetall(self, data):
     root = Section.getAll()
     j = to_json(sections)
     return ['section-list', j]
Exemple #16
0
 def WSSectionGettree(self, data):
     root = Section.getTree()
     j = to_json(root)
     j["childs"] = self.json_childs(root, 1)
     j["level"] = 0
     return ['section-tree', j]
Exemple #17
0
 def WSSectionGettree(self, data):
     root = Section.getTree()
     j = to_json(root)
     j["childs"] = self.json_childs(root, 1)
     j["level"] = 0
     return ['section-tree', j]
Exemple #18
0
 def WSSectionGet(self, data):
     section = Section.get(data['id'])
     j = to_json(section)
     j['params'] = dict ((p.key, p.value) for p in SectionParam.getSection(data['id']))
     return ['section-details', j]
Exemple #19
0
 def WSSectionRemove(self, data):
     i = Section.delete(data['section_id'])
     json = to_json(i)
     return ['section-removed', json];
Exemple #20
0
 def WSSectionGetall(self, data):
     root = Section.getAll()
     j = to_json(sections)
     return ['section-list', j]
Exemple #21
0
 def WSSectionRemove(self, data):
     i = Section.delete(data['section_id'])
     json = to_json(i)
     return ['section-removed', json]