def page_elements(request, id): """ Method called when a ui page widgets is accessed @param request : HTTP request @return an HttpResponse object """ page = Page.objects.get(id=id) page_title = "%s %s" % (page.name, _("Widgets")) iconsets = PageIcon.objects.values('iconset_id', 'iconset_name').distinct() if request.method == 'POST': # If the form has been submitted... widgetinstances = WidgetInstance.objects.filter(page_id=id).delete() features = request.POST["features"].split(',') widgets = request.POST["widgets"].split(',') for i, feature in enumerate(features): if feature: w = WidgetInstance(order=i, page=page, feature_id=feature, widget_id=widgets[i]) w.save() return redirect('page_view', id=id) # Redirect after POST devices = DeviceExtendedPipe().get_list() widgets = Widget.objects.all() widgetinstances = WidgetInstancePipe().get_page_list(id) return go_to_page( request, 'elements.html', page_title, page=page, iconsets=iconsets, devices=devices, widgets=widgets, widgetinstances=widgetinstances, )
def WSWidgetInstanceGetoptions(self, data): i = WidgetInstance.get(data['instance_id']) if (i.widget.default_style): d = WidgetInstance.getFullOptionsDict(id=data['instance_id']) else: d = WidgetInstance.getOptionsDict(id=data['instance_id']) json = {'instance_id': data['instance_id'], 'options': d} return ['widgetinstance-options', json]
def WSWidgetInstanceGetoptions(self, data): i = WidgetInstance.get(data['instance_id']) if (i.widget.default_style): d = WidgetInstance.getFullOptionsDict(id=data['instance_id']) else: d = WidgetInstance.getOptionsDict(id=data['instance_id']) json = {'instance_id':data['instance_id'], 'options':d} return ['widgetinstance-options', json];
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}")
def WSWidgetInstanceGetsection(self, data): r = WidgetInstance.getSection(section_id=data['section_id']) json = {'section_id':data['section_id'], 'instances':to_json(r)} for index, item in enumerate(r): if item.widget: json['instances'][index]["widget"] = to_json(item.widget) else: #remove instance logger.info("Section: Widget '%s' not installed, removing instance" % item.widget_id) WidgetInstance.delete(item.id) del json['instances'][index] return ['widgetinstance-sectionlist', json];
def WSWidgetInstanceLocation(self, data): i = WidgetInstance.updateLocation(id=data['instance_id'], x=data['x'], y=data['y']) json = to_json(i) json["widget"] = to_json(i.widget) return ['widgetinstance-moved', json]
def page(request, id=1): """ Method called when a ui page is accessed @param request : HTTP request @return an HttpResponse object """ page = Page.objects.get(id=id) page_path = Page.objects.get_path(id) page_tree = Page.objects.get_tree() page_title = page.name iconsets = PageIcon.objects.values('iconset_id', 'iconset_name').distinct() widgets = WidgetInstance.objects.filter( page_id=id).values('widget_id').distinct() widgetinstances = WidgetInstance.get_page_list(id) return go_to_page( request, 'page.html', page_title, widgets=widgets, page=page, page_path=page_path, page_tree=page_tree, iconsets=iconsets, widgetinstances=widgetinstances, )
def page(request, id=1): """ Method called when a ui page is accessed @param request : HTTP request @return an HttpResponse object """ page = Page.objects.get(id=id) page_path = Page.objects.get_path(id) page_tree = Page.objects.get_tree() page_title = page.name iconsets = PageIcon.objects.values('iconset_id', 'iconset_name').distinct() widgets = WidgetInstance.objects.filter(page_id=id).values('widget_id').distinct() widgetinstances = WidgetInstance.get_page_list(id) return go_to_page( request, 'page.html', page_title, widgets=widgets, page=page, page_path=page_path, page_tree=page_tree, iconsets=iconsets, widgetinstances=widgetinstances, )
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 WSWidgetInstanceAdd(self, data): i = WidgetInstance.add(section_id=data['section_id'], widget_id=data['widget_id'], x=data['x'], y=data['y']) json = to_json(i) json["widget"] = to_json(i.widget) return ['widgetinstance-added', json]
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, )
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]
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)
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)
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')
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')
def WSWidgetInstanceLocation(self, data): i = WidgetInstance.updateLocation(id=data['instance_id'], x=data['x'], y=data['y']) json = to_json(i) json["widget"] = to_json(i.widget) return ['widgetinstance-moved', json];
def WSWidgetInstanceOrder(self, data): i = WidgetInstance.updateOrder(id=data['instance_id'], order=data['order']) json = to_json(i) json["widget"] = to_json(i.widget) return True;
def WSWidgetInstanceRemove(self, data): i = WidgetInstance.delete(data['instance_id']) json = to_json(i) json["widget"] = to_json(i.widget) return ['widgetinstance-removed', json];
def WSWidgetInstanceAdd(self, data): i = WidgetInstance.add(section_id=data['section_id'], widget_id=data['widget_id']) json = to_json(i) json["widget"] = to_json(i.widget) return ['widgetinstance-added', json];
def page_elements(request, id): """ Method called when a ui page widgets is accessed @param request : HTTP request @return an HttpResponse object """ page = Page.objects.get(id=id) page_title = "%s %s" % (page.name, _("Widgets")) iconsets = PageIcon.objects.values('iconset_id', 'iconset_name').distinct() if request.method == 'POST': # If the form has been submitted... instances = getDictArray(request.POST, 'instance') keys = [] for key in instances.keys(): try: keys.append(int(key)) # Convert to int and remove new instances except ValueError: pass widgetinstances = WidgetInstance.objects.filter(page_id=id).exclude(id__in=keys).delete() for instanceid, instance in instances.items(): if 'widgetid' in instance: w = WidgetInstance(order=0, page=page, widget_id=instance['widgetid']) w.save() if (instance['featuretype'].startswith('sensor')): s = Sensor.objects.get(id=instance['featureid']) ws = WidgetInstanceSensor(instance=w, key="primary", sensor=s) ws.save() else: c = Command.objects.get(id=instance['featureid']) wc = WidgetInstanceCommand(instance=w, key="primary", command=c) wc.save() s = Sensor.objects.get(id=instance['sensor']) ws = WidgetInstanceSensor(instance=w, key="event", sensor=s) ws.save() else: if 'sensor' in instance: # A command with a sensor w = WidgetInstance.objects.get(id=instanceid) s = Sensor.objects.get(id=instance['sensor']) try: ws = WidgetInstanceSensor.objects.get(instance=w, key="event") ws.sensor = s ws.save() except WidgetInstanceSensor.DoesNotExist: ws = WidgetInstanceSensor(instance=w, key="event", sensor=s) ws.save() return redirect('page_view', id=id) # Redirect after POST devices = Device.objects.all() widgets = Widget.objects.all() widgetinstances = WidgetInstance.get_page_list(id) return go_to_page( request, 'elements.html', page_title, page=page, iconsets=iconsets, devices=devices, widgets=widgets, widgetinstances=widgetinstances, )
def get(self, id): instance = WidgetInstance.get(id); self.render('test.html', instance = instance, )
def page_elements(request, id): """ Method called when a ui page widgets is accessed @param request : HTTP request @return an HttpResponse object """ page = Page.objects.get(id=id) page_title = "%s %s" % (page.name, _("Widgets")) iconsets = PageIcon.objects.values('iconset_id', 'iconset_name').distinct() if request.method == 'POST': # If the form has been submitted... instances = getDictArray(request.POST, 'instance') keys = [] for key in instances.keys(): try: keys.append( int(key)) # Convert to int and remove new instances except ValueError: pass widgetinstances = WidgetInstance.objects.filter(page_id=id).exclude( id__in=keys).delete() for instanceid, instance in instances.items(): if 'widgetid' in instance: w = WidgetInstance(order=0, page=page, widget_id=instance['widgetid']) w.save() if (instance['featuretype'].startswith('sensor')): s = Sensor.objects.get(id=instance['featureid']) ws = WidgetInstanceSensor(instance=w, key="primary", sensor=s) ws.save() else: c = Command.objects.get(id=instance['featureid']) wc = WidgetInstanceCommand(instance=w, key="primary", command=c) wc.save() s = Sensor.objects.get(id=instance['sensor']) ws = WidgetInstanceSensor(instance=w, key="event", sensor=s) ws.save() else: if 'sensor' in instance: # A command with a sensor w = WidgetInstance.objects.get(id=instanceid) s = Sensor.objects.get(id=instance['sensor']) try: ws = WidgetInstanceSensor.objects.get(instance=w, key="event") ws.sensor = s ws.save() except WidgetInstanceSensor.DoesNotExist: ws = WidgetInstanceSensor(instance=w, key="event", sensor=s) ws.save() return redirect('page_view', id=id) # Redirect after POST devices = Device.objects.all() widgets = Widget.objects.all() widgetinstances = WidgetInstance.get_page_list(id) return go_to_page( request, 'elements.html', page_title, page=page, iconsets=iconsets, devices=devices, widgets=widgets, widgetinstances=widgetinstances, )
def WSWidgetInstanceRemove(self, data): i = WidgetInstance.delete(data['instance_id']) json = to_json(i) json["widget"] = to_json(i.widget) return ['widgetinstance-removed', json]