Ejemplo n.º 1
0
 def loadWidgets(self):
     from domoweb.models import Widget
     root = self.project['packs']['widgets']['root']
     # List available widgets
     Widget.objects.all().delete()
     if os.path.isdir(root):
         for file in os.listdir(root):
             if not file.startswith('.'):  # not hidden file
                 main = os.path.join(root, file, "main.js")
                 if os.path.isfile(main):
                     w = Widget(id=file)
                     w.save()
Ejemplo n.º 2
0
 def loadWidgets(self):
     from domoweb.models import Widget
     root = self.project['packs']['widgets']['root']
     # List available widgets
     Widget.objects.all().delete()
     if os.path.isdir(root):
         for file in os.listdir(root):
             if not file.startswith('.'): # not hidden file
                 main = os.path.join(root, file, "main.js")
                 if os.path.isfile(main):
                     w = Widget(id=file)
                     w.save()
Ejemplo n.º 3
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,
         )
Ejemplo n.º 4
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,
         )
Ejemplo n.º 5
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,
         )
Ejemplo n.º 6
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,
     )
Ejemplo n.º 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]
Ejemplo n.º 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]
Ejemplo n.º 9
0
    def loadWidgets(cls, pack_path):
        session = Session()

        # Load all Widgets
        logger.info("PACKS: Loading widgets")
        widgets_path = os.path.join(pack_path, 'widgets')
        session.query(Widget).delete()
        session.query(WidgetOption).delete()
        session.query(WidgetCommand).delete()
        session.query(WidgetSensor).delete()
        session.query(WidgetDevice).delete()
        if os.path.isdir(widgets_path):
            for file in os.listdir(widgets_path):
                if not file.startswith('.'): # not hidden file
                    info = os.path.join(widgets_path, file, "info.json")
                    if os.path.isfile(info):
                        widgetset_file = open(info, "r")
                        try:
                            widgetset_json = json.load(widgetset_file, object_pairs_hook=OrderedDict)
                        except Exception, e:
                            logger.error("Parsing error : %s: %s" % (info, str(e)) );
#                            raise e
                        else: 
                            widgetset_id = widgetset_json["identity"]["id"]
                            widgetset_name = widgetset_json["identity"]["name"]
                            widgetset_version = widgetset_json["identity"]["version"]
                            widgetset_widgets = widgetset_json["widgets"]
                            for wid, widget in widgetset_widgets.items():
                                widget_id = "%s-%s" %(widgetset_id, wid)
                                w = Widget(id=widget_id, set_id=widgetset_id, set_name=unicode(widgetset_name), set_ref=wid, version=widgetset_version, name=unicode(widget['name']), height=widget['height'], width=widget['width'])
                                session.add(w)
                                if 'default_style' in widget:
                                    w.default_style = (widget['default_style'] == True)
                                else:
                                    w.default_style = True

                                # Options
                                for pid, param in widget['options'].items():
                                    id = "%s-%s" % (widget_id, pid)
                                    try:
                                        description = unicode(param['description'])
                                    except KeyError:
                                        description = None
                                    p = WidgetOption(id=id, widget_id=widget_id, key=pid, name=unicode(param['name']), type=param['type'])
                                    if 'description' in param:
                                        p.description = unicode(param['description'])
                                    if 'default' in param:
                                        p.default = param['default']
                                    if 'required' in param:
                                        p.required = param['required']
                                    else:
                                        p.required = True
                                    parameters={}
                                    if 'min_length' in param:
                                        parameters['min_length'] = param['min_length']
                                    if 'max_length' in param:
                                        parameters['max_length'] = param['max_length']
                                    if 'min_value' in param:
                                        parameters['min_value'] = param['min_value']
                                    if 'multilignes' in param:
                                        parameters['multilignes'] = param['multilignes']
                                    if 'max_value' in param:
                                        parameters['max_value'] = param['max_value']
                                    if 'mask' in param:
                                        parameters['mask'] = param['mask']
                                    if 'choices' in param:
                                        parameters['choices'] = param['choices']
                                    p.parameters=unicode(json.dumps(parameters))
                                    session.add(p)
                                # Sensors parameters
                                for pid, param in widget['sensors'].items():
                                    id = "%s-%s" % (widget_id, pid)
                                    p = WidgetSensor(id=id, widget_id=widget_id, key=pid, name=unicode(param['name']), types=json.dumps(list(param['types'])))
                                    if 'description' in param:
                                        p.description = unicode(param['description'])
                                    if 'filters' in param:
                                        p.filters = ', '.join(param['filters'])
                                    if 'required' in param:
                                        p.required = param['required']
                                    else:
                                        p.required = True
                                    session.add(p)
                                # Commands parameters
                                for pid, param in widget['commands'].items():
                                    id = "%s-%s" % (widget_id, pid)
                                    p = WidgetCommand(id=id, widget_id=widget_id, key=pid, name=unicode(param['name']), types=json.dumps(param['types']))
                                    if 'description' in param:
                                        p.description = unicode(param['description'])
                                    if 'filters' in param:
                                        p.filters = ', '.join(param['filters'])
                                    if 'required' in param:
                                        p.required = param['required']
                                    else:
                                        p.required = True
                                    session.add(p)
                                # Devices parameters
                                for pid, param in widget['devices'].items():
                                    id = "%s-%s" % (widget_id, pid)
                                    p = WidgetDevice(id=id, widget_id=widget_id, key=pid, name=unicode(param['name']), description=unicode(param['description']), types=json.dumps(param['types']))
                                    if 'required' in param:
                                        p.required = param['required']
                                    else:
                                        p.required = True
                                    session.add(p)
Ejemplo n.º 10
0
 def WSWidgetsGetall(self, data):
     widgets = Widget.getAll()
     return ['widget-list', to_json(widgets)]
Ejemplo n.º 11
0
 def WSWidgetsGetall(self, data):
     widgets = Widget.getAll()
     return ['widget-list', to_json(widgets)]
Ejemplo n.º 12
0
    def loadWidgets(cls, pack_path, develop):
        session = Session()

        # Load all Widgets
        logger.info(u"PACKS: Loading widgets")
        widgets_path = os.path.join(pack_path, 'widgets')
        session.query(Widget).delete()
        session.query(WidgetOption).delete()
        session.query(WidgetCommand).delete()
        session.query(WidgetSensor).delete()
        session.query(WidgetDevice).delete()
        if os.path.isdir(widgets_path):
            for file in os.listdir(widgets_path):
                if not file.startswith('.'):  # not hidden file
                    info = os.path.join(widgets_path, file, "info.json")
                    if os.path.isfile(info):
                        widgetset_file = open(info, "r")
                        try:
                            widgetset_json = json.load(
                                widgetset_file, object_pairs_hook=OrderedDict)
                        except Exception, e:
                            logger.error(u"Parsing error : %s: %s" %
                                         (info, str(e)))


#                            raise e
                        else:
                            widgetset_id = widgetset_json["identity"]["id"]
                            widgetset_name = widgetset_json["identity"]["name"]
                            widgetset_version = widgetset_json["identity"][
                                "version"]
                            widgetset_widgets = widgetset_json["widgets"]
                            for wid, widget in widgetset_widgets.items():
                                if develop or (not develop
                                               and not 'dev' in widget):
                                    widget_id = "%s-%s" % (widgetset_id, wid)
                                    w = Widget(
                                        id=widget_id,
                                        set_id=widgetset_id,
                                        set_name=unicode(widgetset_name),
                                        set_ref=wid,
                                        version=widgetset_version,
                                        name=unicode(widget['name']),
                                        height=widget['height'],
                                        width=widget['width'])
                                    session.add(w)

                                    if 'default_style' in widget:
                                        w.default_style = (
                                            widget['default_style'] == True)
                                    else:
                                        w.default_style = True
                                    # Specific Style
                                    if 'style' in widget:
                                        w.style = unicode(
                                            json.dumps(widget['style']))

                                    # Options
                                    if 'options' in widget:
                                        for pid, param in widget[
                                                'options'].items():
                                            id = "%s-%s" % (widget_id, pid)
                                            try:
                                                description = unicode(
                                                    param['description'])
                                            except KeyError:
                                                description = None
                                            p = WidgetOption(
                                                id=id,
                                                widget_id=widget_id,
                                                key=pid,
                                                name=unicode(param['name']),
                                                type=param['type'])
                                            if 'description' in param:
                                                p.description = unicode(
                                                    param['description'])
                                            if 'default' in param:
                                                p.default = param['default']
                                            if 'required' in param:
                                                p.required = param['required']
                                            else:
                                                p.required = True
                                            parameters = {}
                                            if 'min_length' in param:
                                                parameters[
                                                    'min_length'] = param[
                                                        'min_length']
                                            if 'max_length' in param:
                                                parameters[
                                                    'max_length'] = param[
                                                        'max_length']
                                            if 'min_value' in param:
                                                parameters[
                                                    'min_value'] = param[
                                                        'min_value']
                                            if 'multilignes' in param:
                                                parameters[
                                                    'multilignes'] = param[
                                                        'multilignes']
                                            if 'max_value' in param:
                                                parameters[
                                                    'max_value'] = param[
                                                        'max_value']
                                            if 'mask' in param:
                                                parameters['mask'] = param[
                                                    'mask']
                                            if 'choices' in param:
                                                parameters['choices'] = param[
                                                    'choices']
                                            p.parameters = unicode(
                                                json.dumps(parameters))
                                            session.add(p)
                                    if 'sensors' in widget:
                                        # Sensors parameters
                                        for pid, param in widget[
                                                'sensors'].items():
                                            id = "%s-%s" % (widget_id, pid)
                                            p = WidgetSensor(
                                                id=id,
                                                widget_id=widget_id,
                                                key=pid,
                                                name=unicode(param['name']),
                                                types=json.dumps(
                                                    list(param['types'])))
                                            if 'description' in param:
                                                p.description = unicode(
                                                    param['description'])
                                            if 'filters' in param:
                                                p.filters = ', '.join(
                                                    param['filters'])
                                            if 'required' in param:
                                                p.required = param['required']
                                            else:
                                                p.required = True
                                            if 'group' in param:
                                                p.group = param['group']
                                            if 'groupmin' in param:
                                                p.groupmin = param['groupmin']
                                            if 'groupmax' in param:
                                                p.groupmax = param['groupmax']
                                            session.add(p)
                                    if 'commands' in widget:
                                        # Commands parameters
                                        for pid, param in widget[
                                                'commands'].items():
                                            id = "%s-%s" % (widget_id, pid)
                                            p = WidgetCommand(
                                                id=id,
                                                widget_id=widget_id,
                                                key=pid,
                                                name=unicode(param['name']),
                                                types=json.dumps(
                                                    param['types']))
                                            if 'description' in param:
                                                p.description = unicode(
                                                    param['description'])
                                            if 'filters' in param:
                                                p.filters = ', '.join(
                                                    param['filters'])
                                            if 'required' in param:
                                                p.required = param['required']
                                            else:
                                                p.required = True
                                            session.add(p)
                                    if 'devices' in widget:
                                        # Devices parameters
                                        for pid, param in widget[
                                                'devices'].items():
                                            id = "%s-%s" % (widget_id, pid)
                                            p = WidgetDevice(
                                                id=id,
                                                widget_id=widget_id,
                                                key=pid,
                                                name=unicode(param['name']),
                                                description=unicode(
                                                    param['description']),
                                                types=json.dumps(
                                                    param['types']))
                                            if 'required' in param:
                                                p.required = param['required']
                                            else:
                                                p.required = True
                                            session.add(p)