Exemplo n.º 1
0
def update_objects_value(request):
    """
    Update an object's value. Should be an AJAX POST.

    :param request: The Django request.
    :type request: :class:`django.http.HttpRequest`
    :returns: :class:`django.http.HttpResponse`
    """

    if request.method == 'POST' and request.is_ajax():
        type_ = request.POST['coll']
        oid = request.POST['oid']
        object_type = request.POST.get('type')
        value = request.POST['value']
        new_value = request.POST['new_value']
        analyst = "%s" % request.user.username
        results = update_object_value(type_, oid, object_type, value,
                                      new_value, analyst)
        if results['success']:
            message = "Successfully updated object value: %s" % results[
                'message']
            result = {'success': True, 'message': message}
        else:
            message = "Error updating object value: %s" % results['message']
            result = {'success': False, 'message': message}
        return HttpResponse(json.dumps(result), mimetype="application/json")
    else:
        error = "Expected AJAX POST"
        return render_to_response("error.html", {"error": error},
                                  RequestContext(request))
Exemplo n.º 2
0
def update_objects_value(request):
    """
    Update an object's value. Should be an AJAX POST.

    :param request: The Django request.
    :type request: :class:`django.http.HttpRequest`
    :returns: :class:`django.http.HttpResponse`
    """

    if request.method == 'POST' and request.is_ajax():
        type_ = request.POST['coll']
        oid = request.POST['oid']
        object_type = request.POST.get('type')
        value = request.POST['value']
        new_value = request.POST['new_value']
        analyst = "%s" % request.user.username
        results = update_object_value(type_,
                                      oid,
                                      object_type,
                                      value,
                                      new_value,
                                      analyst)
        if results['success']:
            message = "Successfully updated object value: %s" % results['message']
            result = {'success': True, 'message': message}
        else:
            message = "Error updating object value: %s" % results['message']
            result = {'success': False, 'message': message}
        return HttpResponse(json.dumps(result), content_type="application/json")
    else:
        error = "Expected AJAX POST"
        return render_to_response("error.html",
                                  {"error" : error },
                                  RequestContext(request))
Exemplo n.º 3
0
def update_objects_value(request):
    """
    Update an object's value. Should be an AJAX POST.

    :param request: The Django request.
    :type request: :class:`django.http.HttpRequest`
    :returns: :class:`django.http.HttpResponse`
    """

    if request.method == "POST" and request.is_ajax():
        type_ = request.POST["coll"]
        oid = request.POST["oid"]
        name = request.POST.get("name")
        object_type = request.POST.get("type")
        value = request.POST["value"]
        new_value = request.POST["new_value"]
        analyst = "%s" % request.user.username
        results = update_object_value(type_, oid, object_type, name, value, new_value, analyst)
        if results["success"]:
            message = "Successfully updated object value: %s" % results["message"]
            result = {"success": True, "message": message}
        else:
            message = "Error updating object value: %s" % results["message"]
            result = {"success": False, "message": message}
        return HttpResponse(json.dumps(result), mimetype="application/json")
    else:
        error = "Expected AJAX POST"
        return render_to_response("error.html", {"error": error}, RequestContext(request))
Exemplo n.º 4
0
def update_objects_value(request):
    """
    Update an object's value. Should be an AJAX POST.

    :param request: The Django request.
    :type request: :class:`django.http.HttpRequest`
    :returns: :class:`django.http.HttpResponse`
    """

    if request.method == 'POST' and request.is_ajax():
        type_ = request.POST['coll']
        oid = request.POST['oid']
        object_type = request.POST.get('type')
        value = request.POST['value']
        new_value = request.POST['new_value']
        user = request.user
        acl = get_acl_object(type_)
        if user.has_access_to(acl.OBJECTS_EDIT):
            results = update_object_value(type_,
                                          oid,
                                          object_type,
                                          value,
                                          new_value,
                                          user)
        else:
            results = {'success':False,
                       'message':'User does not have permission to modify object.'}
        if results['success']:
            message = "Successfully updated object value: %s" % results['message']
            result = {'success': True, 'message': message}
        else:
            message = "Error updating object value: %s" % results['message']
            result = {'success': False, 'message': message}
        return HttpResponse(json.dumps(result), content_type="application/json")
    else:
        error = "Expected AJAX POST"
        return render_to_response("error.html",
                                  {"error" : error },
                                  RequestContext(request))
Exemplo n.º 5
0
def update_objects_value(request):
    """
    Update an object's value. Should be an AJAX POST.

    :param request: The Django request.
    :type request: :class:`django.http.HttpRequest`
    :returns: :class:`django.http.HttpResponse`
    """

    if request.method == 'POST' and request.is_ajax():
        type_ = request.POST['coll']
        oid = request.POST['oid']
        object_type = request.POST.get('type')
        value = request.POST['value']
        new_value = request.POST['new_value']
        user = request.user
        acl = get_acl_object(type_)
        if user.has_access_to(acl.OBJECTS_EDIT):
            results = update_object_value(type_,
                                          oid,
                                          object_type,
                                          value,
                                          new_value,
                                          user)
        else:
            results = {'success':False,
                       'message':'User does not have permission to modify object.'}
        if results['success']:
            message = "Successfully updated object value: %s" % results['message']
            result = {'success': True, 'message': message}
        else:
            message = "Error updating object value: %s" % results['message']
            result = {'success': False, 'message': message}
        return HttpResponse(json.dumps(result), content_type="application/json")
    else:
        error = "Expected AJAX POST"
        return render_to_response("error.html",
                                  {"error" : error },
                                  RequestContext(request))