(request, type_, id_)
Attribute a location to a top-level object. Should be an AJAX POST.

    :param request: Django request object (Required)
    :type request: :class:`django.http.HttpRequest`
    :param type_: CRITs type for the top-level object.
    :type type_: str
    :param id_: The ObjectId of the top-level object.
    :type id_: str
    :returns: :class:`django.http.HttpResponse`
Attribute a location to a top-level object. Should be an AJAX POST.
Attribute a location to a top - level object . Should be an AJAX POST .
def add_location(request, type_, id_):
    """
    Attribute a location to a top-level object. Should be an AJAX POST.

    :param request: Django request object (Required)
    :type request: :class:`django.http.HttpRequest`
    :param type_: CRITs type for the top-level object.
    :type type_: str
    :param id_: The ObjectId of the top-level object.
    :type id_: str
    :returns: :class:`django.http.HttpResponse`
    """

    if request.method == "POST" and request.is_ajax():
        form = AddLocationForm(request.POST)
        result = {}
        if form.is_valid():
            data = form.cleaned_data
            location_type = data['location_type']
            location_name = data['country']
            description = data['description']
            latitude = data['latitude']
            longitude = data['longitude']
            user = request.user
            acl = get_acl_object(type_)

            if user.has_access_to(acl.LOCATIONS_ADD):
                result = location_add(id_,
                                      type_,
                                      location_type,
                                      location_name,
                                      user,
                                      description=description,
                                      latitude=latitude,
                                      longitude=longitude)
            else:
                result = {"success":False,
                          "message":"User does not have permission to add locations."}

            if result['success']:
                return HttpResponse(json.dumps(result),
                                    content_type="application/json")
        result['form'] = form.as_table()
        result['success'] = False
        return HttpResponse(json.dumps(result),
                            content_type="application/json")
    else:
        return HttpResponse(json.dumps({'success': False,
                                        'message': "Expected AJAX request."}),
                            content_type="application/json")
def add_location ( request , type_ , id_ ) : if request . method == "POST" and request . is_ajax ( ) : form = AddLocationForm ( request . POST ) result = { } if form . is_valid ( ) : data = form . cleaned_data location_type = data [ 'location_type' ] location_name = data [ 'country' ] description = data [ 'description' ] latitude = data [ 'latitude' ] longitude = data [ 'longitude' ] user = request . user acl = get_acl_object ( type_ ) if user . has_access_to ( acl . LOCATIONS_ADD ) : result = location_add ( id_ , type_ , location_type , location_name , user , description = description , latitude = latitude , longitude = longitude ) else : result = { "success" : False , "message" : "User does not have permission to add locations." } if result [ 'success' ] : return HttpResponse ( json . dumps ( result ) , content_type = "application/json" ) result [ 'form' ] = form . as_table ( ) result [ 'success' ] = False return HttpResponse ( json . dumps ( result ) , content_type = "application/json" ) else : return HttpResponse ( json . dumps ( { 'success' : False , 'message' : "Expected AJAX request." } ) , content_type = "application/json" )