Example #1
0
 def common_startup(self, request, *args, **kwargs):
     try:
         self.widget = WidgetDefinition.objects.get(family__url=kwargs["widget_url"], 
                         label=kwargs["label"])
     except WidgetDefinition.DoesNotExist:
         raise Http404("This Widget Definition does not exist")
     if not user_has_edit_permission(request.user, self.widget):
         raise PermissionDenied("You do not have permission to edit the data for this widget")
     try:
         self.graph = GraphDefinition.objects.get(tile__widget=self.widget, tile__url=kwargs["tile_url"])
     except GraphDefinition.DoesNotExist:
         raise Http404("This Graph does not exist")
     if not self.widget.parametisation:
         self.pval = None
     else:
         try:
             self.pval = ParametisationValue.objects.get(pk=kwargs["pval_id"])
         except ParametisationValue.DoesNotExist:
             raise PermissionDenied("This parameter value set does not exist")
     self.form_class = get_form_class_for_graph(self.graph, pval=self.pval)
     self.form_class = forms.formsets.formset_factory(self.form_class, can_delete=True, extra=10)
     self.overrides_form_class = get_override_form_class_for_graph(self.graph)
     if self.graph.dynamic_clusters:
         self.dyncluster_form_class = forms.modelformset_factory(DynamicGraphCluster, form=DynamicGraphClusterForm, can_delete=True, extra=3)
     else:
         self.dyncluster_form_class = None
     self.overrides_form = None
     self.dyncluster_form = None
     self.return_redirect = False
Example #2
0
def view_widget(request, widget_url, label, pval_id=None):
    try:
        w = WidgetDefinition.objects.get(family__url=widget_url, 
                    label=label)
    except WidgetDefinition.DoesNotExist:
        return HttpResponseNotFound("This Widget Definition does not exist")
    if not user_has_edit_permission(request.user, w):
        return HttpResponseForbidden("You do not have permission to edit the data for this widget")
    if w.parametisation and not pval_id:
        return HttpResponseNotFound("This Widget Definition is parametised")
    if not w.parametisation:
        pval = None
    else:
        try:
            pval = ParametisationValue.objects.get(pk=pval_id)
        except ParametisationValue.DoesNotExist:
            return HttpResponseNotFound("This parameter value set does not exist")
    edit_all = user_has_edit_all_permission(request.user, w)
    if edit_all:
        statistics = Statistic.objects.filter(tile__widget=w)
    else:
        statistics = Statistic.objects.filter(editable=True,tile__widget=w)
    stats = []
    for s in statistics:
        try:
            data = StatisticData.objects.get(statistic=s, param_value=pval)
        except StatisticData.DoesNotExist:
            data = None
        listdata = StatisticListItem.objects.filter(statistic=s, param_value=pval)
        stats.append({
                "statistic": s,
                "data_last_updated": s.data_last_updated(pval=pval),
                "data": data,
                "listdata": listdata,
            })
    graphs = []
    for graph in GraphDefinition.objects.filter(tile__widget=w):
        data = graph.get_data(pval=pval)
        graphs.append({
                "graph": graph,
                "data_last_updated": graph.data_last_updated(pval=pval),
                "data": data
                })
    if request.method == "POST":
        form = WidgetDataForm(request.POST)
        if form.is_valid():
            set_actual_frequency_display_text(w.url(), w.label,
                        form.cleaned_data["actual_frequency_display_text"], pval=pval)
    else:
        form = WidgetDataForm(initial={
                "actual_frequency_display_text": w.actual_frequency_display(pval=pval),
                })
    return render(request, "widget_data/view_widget.html", {
            "pval": pval,
            "widget": w,
            "stats": stats,
            "graphs": graphs,
            "form": form,
            })
Example #3
0
 def get_queryset(self):
     try:
         self.widget = WidgetDefinition.objects.get(family__url=self.kwargs["widget_url"], 
                     label=self.kwargs["label"])
     except WidgetDefinition.DoesNotExist:
         raise Http404("This Widget Definition does not exist")
     if not user_has_edit_permission(self.request.user, self.widget):
         raise PermissionDenied("You do not have permission to edit the data for this widget")
     if not self.widget.parametisation:
         raise PermissionDenied("This widget is not a parametised widget")
     return self.widget.parametisation.keys()
Example #4
0
 def get_queryset(self):
     try:
         self.widget = WidgetDefinition.objects.get(
             family__url=self.kwargs["widget_url"],
             label=self.kwargs["label"])
     except WidgetDefinition.DoesNotExist:
         raise Http404("This Widget Definition does not exist")
     if not user_has_edit_permission(self.request.user, self.widget):
         raise PermissionDenied(
             "You do not have permission to edit the data for this widget")
     if not self.widget.parametisation:
         raise PermissionDenied("This widget is not a parametised widget")
     return self.widget.parametisation.keys()
Example #5
0
 def common_startup(self, request, *args, **kwargs):
     try:
         self.widget = WidgetDefinition.objects.get(family__url=kwargs["widget_url"], 
                     label=kwargs["label"])
     except WidgetDefinition.DoesNotExist:
         raise Http404("This Widget Definition does not exist")
     if not user_has_edit_permission(request.user, self.widget):
         raise PermissionDenied("You do not have permission to edit the data for this widget")
     if self.widget.parametisation and not kwargs.get("pval_id"):
         raise Http404("This Widget Definition is parametised")
     if not self.widget.parametisation:
         self.pval = None
     else:
         try:
             self.pval = ParametisationValue.objects.get(pk=kwargs["pval_id"])
         except ParametisationValue.DoesNotExist:
             raise Http404("This parameter value set does not exist")
     return
Example #6
0
 def common_startup(self, request, *args, **kwargs):
     try:
         self.stat = get_statistic(kwargs["widget_url"], kwargs["label"], kwargs["stat_url"])
     except LoaderException:
         raise Http404("This Statistic does not exist")
     if not user_has_edit_permission(request.user, self.stat.tile.widget):
         raise PermissionDenied("You do not have permission to edit the data for this widget")
     if not self.stat.editable and not user_has_edit_all_permission(request.user, self.stat.tile.widget):
         raise PermissionDenied("You do not have permission to edit the data for this widget")
     if self.stat.tile.widget.parametisation and not kwargs.get("pval_id"):
         raise Http404("This Widget Definition is parametised")
     if not self.stat.tile.widget.parametisation:
         self.pval = None
     else:
         try:
             self.pval = ParametisationValue.objects.get(pk=kwargs.get("pval_id"))
         except ParametisationValue.DoesNotExist:
             raise Http404("This parameter value set does not exist")
     return 
Example #7
0
 def common_startup(self, request, *args, **kwargs):
     try:
         self.widget = WidgetDefinition.objects.get(
             family__url=kwargs["widget_url"], label=kwargs["label"])
     except WidgetDefinition.DoesNotExist:
         raise Http404("This Widget Definition does not exist")
     if not user_has_edit_permission(request.user, self.widget):
         raise PermissionDenied(
             "You do not have permission to edit the data for this widget")
     if self.widget.parametisation and not kwargs.get("pval_id"):
         raise Http404("This Widget Definition is parametised")
     if not self.widget.parametisation:
         self.pval = None
     else:
         try:
             self.pval = ParametisationValue.objects.get(
                 pk=kwargs["pval_id"])
         except ParametisationValue.DoesNotExist:
             raise Http404("This parameter value set does not exist")
     return
Example #8
0
 def common_startup(self, request, *args, **kwargs):
     try:
         self.widget = WidgetDefinition.objects.get(
             family__url=kwargs["widget_url"], label=kwargs["label"])
     except WidgetDefinition.DoesNotExist:
         raise Http404("This Widget Definition does not exist")
     if not user_has_edit_permission(request.user, self.widget):
         raise PermissionDenied(
             "You do not have permission to edit the data for this widget")
     try:
         self.graph = GraphDefinition.objects.get(
             tile__widget=self.widget, tile__url=kwargs["tile_url"])
     except GraphDefinition.DoesNotExist:
         raise Http404("This Graph does not exist")
     if not self.widget.parametisation:
         self.pval = None
     else:
         try:
             self.pval = ParametisationValue.objects.get(
                 pk=kwargs["pval_id"])
         except ParametisationValue.DoesNotExist:
             raise PermissionDenied(
                 "This parameter value set does not exist")
     self.form_class = get_form_class_for_graph(self.graph, pval=self.pval)
     self.form_class = forms.formsets.formset_factory(self.form_class,
                                                      can_delete=True,
                                                      extra=10)
     self.overrides_form_class = get_override_form_class_for_graph(
         self.graph)
     if self.graph.dynamic_clusters:
         self.dyncluster_form_class = forms.modelformset_factory(
             DynamicGraphCluster,
             form=DynamicGraphClusterForm,
             can_delete=True,
             extra=3)
     else:
         self.dyncluster_form_class = None
     self.overrides_form = None
     self.dyncluster_form = None
     self.return_redirect = False
Example #9
0
 def common_startup(self, request, *args, **kwargs):
     try:
         self.stat = get_statistic(kwargs["widget_url"], kwargs["label"],
                                   kwargs["stat_url"])
     except LoaderException:
         raise Http404("This Statistic does not exist")
     if not user_has_edit_permission(request.user, self.stat.tile.widget):
         raise PermissionDenied(
             "You do not have permission to edit the data for this widget")
     if not self.stat.editable and not user_has_edit_all_permission(
             request.user, self.stat.tile.widget):
         raise PermissionDenied(
             "You do not have permission to edit the data for this widget")
     if self.stat.tile.widget.parametisation and not kwargs.get("pval_id"):
         raise Http404("This Widget Definition is parametised")
     if not self.stat.tile.widget.parametisation:
         self.pval = None
     else:
         try:
             self.pval = ParametisationValue.objects.get(
                 pk=kwargs.get("pval_id"))
         except ParametisationValue.DoesNotExist:
             raise Http404("This parameter value set does not exist")
     return
Example #10
0
def list_widget_params(request, widget_url, label):
    try:
        w = WidgetDefinition.objects.get(family__url=widget_url, 
                    label=label)
    except WidgetDefinition.DoesNotExist:
        return HttpResponseNotFound("This Widget Definition does not exist")
    if not user_has_edit_permission(request.user, w):
        return HttpResponseForbidden("You do not have permission to edit the data for this widget")
    if not w.parametisation:
       return redirect("list_widget_data")
    pvals = []
    keys = w.parametisation.keys()
    for pval in w.parametisation.parametisationvalue_set.all():
        parameters = pval.parameters()
        pvals.append({
                "pval": pval,
                "parameters": [ parameters[k] for k in keys ],
                "last_updated": w.data_last_updated(pval=pval),
                }) 
    return render(request, "widget_data/list_parametisations.html", {
            "keys": keys,
            "widget": w,
            "pvals": pvals,
            })
Example #11
0
def edit_graph(request, widget_url, label, tile_url, pval_id=None):
    try:
        w = WidgetDefinition.objects.get(family__url=widget_url, 
                        label=label)
    except WidgetDefinition.DoesNotExist:
        return HttpResponseNotFound("This Widget Definition does not exist")
    if not user_has_edit_permission(request.user, w):
        return HttpResponseForbidden("You do not have permission to edit the data for this widget")
    try:
        g = GraphDefinition.objects.get(tile__widget=w, tile__url=tile_url)
    except GraphDefinition.DoesNotExist:
        return HttpResponseNotFound("This Graph does not exist")
    if not g.widget().parametisation:
        pval = None
    else:
        try:
            pval = ParametisationValue.objects.get(pk=pval_id)
        except ParametisationValue.DoesNotExist:
            return HttpResponseNotFound("This parameter value set does not exist")

    form_class = get_form_class_for_graph(g)
    form_class = forms.formsets.formset_factory(form_class, can_delete=True, extra=10)
    overrides_form_class = get_override_form_class_for_graph(g)
    overrides_form = None
    return_redirect = False
    if request.method == 'POST':
        if request.POST.get("submit") or request.POST.get("submit_stay"):
            form = form_class(request.POST)
            if overrides_form_class:
                overrides_form = overrides_form_class(request.POST)
            if form.is_valid() and (not overrides_form or overrides_form.is_valid()):
                clear_graph_data(g, pval=pval)
                for subform in form:
                    fd = subform.cleaned_data
                    if fd and not fd.get("DELETE"):
                        gd = GraphData(graph=g, param_value=pval)
                        gd.value = fd["value"]
                        if g.use_clusters():
                            # Lookup?
                            gd.cluster = fd["cluster"]
                        # Lookup?
                        gd.dataset = fd["dataset"]
                        if g.graph_type == g.LINE:
                            if g.horiz_axis_type == g.NUMERIC:
                                gd.horiz_numericval = fd["horiz_value"]
                            elif g.horiz_axis_type == g.DATE:
                                gd.horiz_dateval = fd["horiz_value"]
                            elif g.horiz_axis_type == g.TIME:
                                gd.horiz_timeval = fd["horiz_value"]
                            elif g.horiz_axis_type == g.TIME:
                                gd.horiz_dateval = fd["horiz_value"].date()
                                gd.horiz_timeval = fd["horiz_value"].time()
                        gd.save()
                if overrides_form:
                    fod = overrides_form.cleaned_data
                    for fldname, fldval in fod.items():
                        ov_type, ov_url = fldname.split("_", 1)
                        if ov_type == 'cluster':
                            set_cluster_override(g, ov_url, fldval, pval=pval)
                        else:
                            set_dataset_override(g, ov_url, fldval, pval=pval)
                if request.POST.get("submit"):
                    return_redirect=True
                else:
                    form = form_class(initial=g.initial_form_data(pval))
                    if overrides_form_class:
                        overrides_form = overrides_form_class(initial=g.initial_override_form_data(pval))
        elif request.POST.get("cancel"):
            return_redirect=True
        else:
            form = form_class(initial=g.initial_form_data(pval))
            if overrides_form_class:
                overrides_form = overrides_form_class(initial=g.initial_override_form_data(pval))
    else:
        form = form_class(initial=g.initial_form_data(pval))
        if overrides_form_class:
            overrides_form = overrides_form_class(initial=g.initial_override_form_data(pval))
    if return_redirect:
        if pval:
            return redirect("view_parametised_widget_data", 
                        widget_url=w.family.url, 
                        label=label, pval_id=pval_id)
        else: 
            return redirect("view_widget_data", 
                        widget_url=w.family.url, 
                        label=label)
    return render(request, "widget_data/edit_graph.html", {
                "widget": w,
                "pval": pval,
                "graph": g,
                "form": form,
                "overrides_form": overrides_form
                })
Example #12
0
def edit_stat(request, widget_url, label, stat_url, pval_id=None):
    try:
        s = get_statistic(widget_url, label, stat_url)
    except LoaderException:
        return HttpResponseNotFound("This Statistic does not exist")
    if not user_has_edit_permission(request.user, s.tile.widget):
        return HttpResponseForbidden("You do not have permission to edit the data for this widget")
    if not s.editable and not user_has_edit_all_permission(request.user, s.tile.widget):
        return HttpResponseForbidden("You do not have permission to edit the data for this widget")
    if s.tile.widget.parametisation and not pval_id:
        return HttpResponseNotFound("This Widget Definition is parametised")
    if not s.tile.widget.parametisation:
        pval = None
    else:
        try:
            pval = ParametisationValue.objects.get(pk=pval_id)
        except ParametisationValue.DoesNotExist:
            return HttpResponseNotFound("This parameter value set does not exist")
    form_class = get_form_class_for_statistic(s)
    if s.is_data_list():
        form_class = forms.formsets.formset_factory(form_class, can_delete=True, extra=4)
    redirect_out = False
    if request.method == 'POST':
        if request.POST.get("submit") or request.POST.get("submit_stay"):
            form = form_class(request.POST)
            if form.is_valid():
                if s.is_data_list():
                    clear_statistic_list(s, pval=pval)
                    for subform in form:
                        fd = subform.cleaned_data
                        if fd and not fd.get("DELETE"):
                            add_stat_list_item(s, fd["value"], fd["sort_order"], pval,
                                        fd.get("datetime"), fd.get("level"), fd.get("date"), fd.get("label"),
                                        fd.get("traffic_light_code"), fd.get("icon_code"),
                                        fd.get("trend"), fd.get("url"))
                    if request.POST.get("submit"):
                        redirect_out=True
                    else:
                        form = form_class(initial=s.initial_form_data(pval))
                else:
                    fd = form.cleaned_data
                    set_stat_data(s, fd["value"], pval,
                                    fd.get("traffic_light_code"), fd.get("icon_code"), 
                                    fd.get("trend"), fd.get("label"))
                    redirect_out=True
        elif request.POST.get("cancel"):
            redirect_out=True
        elif not s.is_data_list() and request.POST.get("delete"):
            clear_statistic_data(s)
            redirect_out=True
        else:
            form = form_class(initial=s.initial_form_data(pval))
    else:
        form = form_class(initial=s.initial_form_data(pval))

    if redirect_out:
        if pval:
            return redirect("view_parametised_widget_data", 
                    widget_url=s.tile.widget.family.url, 
                    label=s.tile.widget.label,
                    pval_id=pval_id)
        else:
            return redirect("view_widget_data", 
                widget_url=s.tile.widget.family.url, 
                label=s.tile.widget.label)

    return render(request, "widget_data/edit_widget.html", {
                "pval": pval,
                "widget": s.tile.widget,
                "statistic": s,
                "form": form
                })