def image_chart_settings_update(request, name, id):

    if request.method != 'POST':
        raise PermissionDenied

    try:
        instance = ImageChartUser.objects.get(user=request.user,
                                              image_chart__id=id)
    except ImageChartUser.DoesNotExist:
        # Create new.
        instance = ImageChartUser()
        instance.image_chart_id = id
        instance.user = request.user

    # Update the chart test/test case user table with hidden test ids.
    try:
        chart = ImageReportChart.objects.get(id=id)
        if chart.chart_type == "pass/fail":

            chart_test = ImageChartTest.objects.get(
                id=request.POST["visible_chart_test_id"])

            chart_test_user = ImageChartTestUser.objects.get_or_create(
                user=request.user,
                image_chart_test=chart_test)[0]

            chart_test_user.is_visible = not chart_test_user.is_visible
            chart_test_user.save()

        else:
            chart_test_case = ImageChartTestCase.objects.get(
                id=request.POST["visible_chart_test_id"])

            chart_test_user = ImageChartTestCaseUser.objects.get_or_create(
                user=request.user,
                image_chart_test_case=chart_test_case)[0]

            chart_test_user.is_visible = not chart_test_user.is_visible
            chart_test_user.save()

    except Exception as e:
        # Don't update the chart test/test case user table.
        pass

    form = ImageChartUserForm(request.user, request.POST,
                              instance=instance)
    if form.is_valid():
        instance = form.save()
        data = serializers.serialize('json', [instance])
        return HttpResponse(data, content_type='application/json')
Exemple #2
0
def image_chart_settings_update(request, name, id):

    if request.method != 'POST':
        raise PermissionDenied

    try:
        instance = ImageChartUser.objects.get(user=request.user,
                                              image_chart__id=id)
    except ImageChartUser.DoesNotExist:
        # Create new.
        instance = ImageChartUser()
        instance.image_chart_id = id
        instance.user = request.user

    form = ImageChartUserForm(request.user, request.POST,
                              instance=instance)
    if form.is_valid():
        instance = form.save()
        data = serializers.serialize('json', [instance])
        return HttpResponse(data, mimetype='application/json')
Exemple #3
0
def image_chart_settings_update(request, name, id):

    if request.method != 'POST':
        raise PermissionDenied

    try:
        instance = ImageChartUser.objects.get(user=request.user,
                                              image_chart__id=id)
    except ImageChartUser.DoesNotExist:
        # Create new.
        instance = ImageChartUser()
        instance.image_chart_id = id
        instance.user = request.user

    # Update the chart test/test case user table with hidden test ids.
    try:
        chart = ImageReportChart.objects.get(id=id)
        if chart.chart_type == "pass/fail":

            chart_test = ImageChartTest.objects.get(
                id=request.POST["visible_chart_test_id"])

            chart_test_user = ImageChartTestUser.objects.get_or_create(
                user=request.user,
                image_chart_test=chart_test)[0]

            chart_test_user.is_visible = not chart_test_user.is_visible
            chart_test_user.save()

        elif chart.chart_type == "measurement":
            chart_test_case = ImageChartTestCase.objects.get(
                id=request.POST["visible_chart_test_id"])

            chart_test_user = ImageChartTestCaseUser.objects.get_or_create(
                user=request.user,
                image_chart_test_case=chart_test_case)[0]

            chart_test_user.is_visible = not chart_test_user.is_visible
            chart_test_user.save()

        elif chart.chart_type == "attributes":

            chart_test = ImageChartTest.objects.get(
                id=request.POST["visible_chart_test_id"])

            chart_test_attribute = ImageChartTestAttribute.objects.get(
                image_chart_test=chart_test,
                name=request.POST["visible_attribute_name"]
            )

            attribute_user = ImageChartTestAttributeUser.objects.get_or_create(
                user=request.user,
                image_chart_test_attribute=chart_test_attribute)[0]

            attribute_user.is_visible = not attribute_user.is_visible
            attribute_user.save()

    except Exception as e:
        # Don't update the chart test/test case user table.
        pass

    form = ImageChartUserForm(request.user, request.POST,
                              instance=instance)
    if form.is_valid():
        instance = form.save()
        data = serializers.serialize('json', [instance])
        return HttpResponse(data, content_type='application/json')
    else:
        return HttpResponseBadRequest()