Exemplo n.º 1
0
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,
    )
Exemplo n.º 2
0
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,
    )
Exemplo n.º 3
0
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,
    )
Exemplo n.º 4
0
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,
    )