screens/views.py
def load_widget_config(request):
    """
    Load the configuration for a given screen widget
    :param request: http request
    :return: html template
    """
    logger.info("__ screens load_widget_config __")
    required_fields = set(["widget_id", "widget_layout_id"])
    if not required_fields.issubset(request.POST):
        logger.error("Did no find all required fields in request")
        return render(request, "overlay_basic.html", {"message": "Invalid Parameters in POST"})

    widget_id = request.POST["widget_id"]
    widget_layout_id = request.POST["widget_layout_id"]

    widgets = settings.SCREEN_WIDGETS
    widget_name = ""
    widget_configuration_template = ""
    widget_consumes_input_form = ""

    found = False
    for w in widgets:
        if w["id"] == widget_id:
            widget_name = w["label"]
            widget_configuration_template = w["configuration_template"]
            if "consumes_input_form" in w:
                widget_consumes_input_form = w["consumes_input_form"]

            logger.debug(widget_configuration_template)
            found = True
            break

    if not found:
        return render(request, "screens/widgets/overlay_error.html",
                      {"error": "Could not find widget configuration"})

    context = {"widget_id": widget_id, "widget_name": widget_name, "widget_layout_id": widget_layout_id}

    # grab the widget global configuration if it exists and set on the context
    # FIXME - widget_type and widget_id are used interchangeably, this should just be widget_id basically everywhere
    if ScreenWidgetConfig.objects.filter(widget_type=widget_id).exists():
        widget_config = ScreenWidgetConfig.objects.get(widget_type=widget_id)
        # context.update
        context.update({"widget_global_config": widget_config.data})

    if widget_consumes_input_form != "":
        # this widget will consume the output of a configured automation!
        try:
            input_form = InputForm.objects.get(name=widget_consumes_input_form)

            logger.debug(input_form.json)
            json_object = json.loads(input_form.json)
            for jo in json_object:
                if "widget" not in jo:
                    jo["widget"] = "text_input"

            config_template = input_form.script
            action_options = json.loads(config_template.action_provider_options)

            input_form_context = {"input_form": input_form, "json_object": json_object,
                                  "action_options": action_options, "consumes_input_form": widget_consumes_input_form}

            context.update(input_form_context)

        except ObjectDoesNotExist:
            logger.error("Configured automation for widget does not exist!")

    try:
        return render(request, "screens/widgets/%s" % widget_configuration_template, context)
    except TemplateDoesNotExist:
        return render(request, "screens/widgets/overlay_error.html",
                      {"error": "Could not load widget configuration"})

    Load the configuration for a given screen widget
    :param request: http request
    :return: html template
    
Load the configuration for a given screen widget
Load the configuration for a given screen widget
def load_widget_config(request):
    logger.info("__ screens load_widget_config __")
    required_fields = set(["widget_id", "widget_layout_id"])
    if not required_fields.issubset(request.POST):
        logger.error("Did no find all required fields in request")
        return render(request, "overlay_basic.html", {"message": "Invalid Parameters in POST"})
    widget_id = request.POST["widget_id"]
    widget_layout_id = request.POST["widget_layout_id"]
    widgets = settings.SCREEN_WIDGETS
    widget_name = ""
    widget_configuration_template = ""
    widget_consumes_input_form = ""
    found = False
    for w in widgets:
        if w["id"] == widget_id:
            widget_name = w["label"]
            widget_configuration_template = w["configuration_template"]
            if "consumes_input_form" in w:
                widget_consumes_input_form = w["consumes_input_form"]
            logger.debug(widget_configuration_template)
            found = True
            break
    if not found:
        return render(request, "screens/widgets/overlay_error.html",
                      {"error": "Could not find widget configuration"})
    context = {"widget_id": widget_id, "widget_name": widget_name, "widget_layout_id": widget_layout_id}
    if ScreenWidgetConfig.objects.filter(widget_type=widget_id).exists():
        widget_config = ScreenWidgetConfig.objects.get(widget_type=widget_id)
        context.update({"widget_global_config": widget_config.data})
    if widget_consumes_input_form != "":
        try:
            input_form = InputForm.objects.get(name=widget_consumes_input_form)
            logger.debug(input_form.json)
            json_object = json.loads(input_form.json)
            for jo in json_object:
                if "widget" not in jo:
                    jo["widget"] = "text_input"
            config_template = input_form.script
            action_options = json.loads(config_template.action_provider_options)
            input_form_context = {"input_form": input_form, "json_object": json_object,
                                  "action_options": action_options, "consumes_input_form": widget_consumes_input_form}
            context.update(input_form_context)
        except ObjectDoesNotExist:
            logger.error("Configured automation for widget does not exist!")
    try:
        return render(request, "screens/widgets/%s" % widget_configuration_template, context)
    except TemplateDoesNotExist:
        return render(request, "screens/widgets/overlay_error.html",
                      {"error": "Could not load widget configuration"})
def load_widget_config ( request ) : logger . info ( "__ screens load_widget_config __" ) required_fields = set ( [ "widget_id" , "widget_layout_id" ] ) if not required_fields . issubset ( request . POST ) : logger . error ( "Did no find all required fields in request" ) return render ( request , "overlay_basic.html" , { "message" : "Invalid Parameters in POST" } ) widget_id = request . POST [ "widget_id" ] widget_layout_id = request . POST [ "widget_layout_id" ] widgets = settings . SCREEN_WIDGETS widget_name = "" widget_configuration_template = "" widget_consumes_input_form = "" found = False for w in widgets : if w [ "id" ] == widget_id : widget_name = w [ "label" ] widget_configuration_template = w [ "configuration_template" ] if "consumes_input_form" in w : widget_consumes_input_form = w [ "consumes_input_form" ] logger . debug ( widget_configuration_template ) found = True break if not found : return render ( request , "screens/widgets/overlay_error.html" , { "error" : "Could not find widget configuration" } ) context = { "widget_id" : widget_id , "widget_name" : widget_name , "widget_layout_id" : widget_layout_id } if ScreenWidgetConfig . objects . filter ( widget_type = widget_id ) . exists ( ) : widget_config = ScreenWidgetConfig . objects . get ( widget_type = widget_id ) context . update ( { "widget_global_config" : widget_config . data } ) if widget_consumes_input_form != "" : try : input_form = InputForm . objects . get ( name = widget_consumes_input_form ) logger . debug ( input_form . json ) json_object = json . loads ( input_form . json ) for jo in json_object : if "widget" not in jo : jo [ "widget" ] = "text_input" config_template = input_form . script action_options = json . loads ( config_template . action_provider_options ) input_form_context = { "input_form" : input_form , "json_object" : json_object , "action_options" : action_options , "consumes_input_form" : widget_consumes_input_form } context . update ( input_form_context ) except ObjectDoesNotExist : logger . error ( "Configured automation for widget does not exist!" ) try : return render ( request , "screens/widgets/%s" % widget_configuration_template , context ) except TemplateDoesNotExist : return render ( request , "screens/widgets/overlay_error.html" , { "error" : "Could not load widget configuration" } )
Load the configuration for a given screen widget
Load the configuration for a given screen widget
"""
    Load the configuration for a given screen widget
    :param request: http request
    :return: html template
    """ # grab the widget global configuration if it exists and set on the context # FIXME - widget_type and widget_id are used interchangeably, this should just be widget_id basically everywhere # context.update # this widget will consume the output of a configured automation!
None
request
None