예제 #1
0
def bulk_add_domain(request):
    """
    Bulk add domains via a bulk upload form.

    Args:
        request: The Django context which contains information about the
            session and key/value pairs for the bulk add domains request

    Returns:
        If the request is not a POST and not a Ajax call then:
            Returns a rendered HTML form for a bulk add of domains
        If the request is a POST and a Ajax call then:
            Returns a response that contains information about the
            status of the bulk uploaded domains. This may include information
            such as domains that failed or successfully added. This may
            also contain helpful status messages about each operation.
    """

    formdict = form_to_dict(AddDomainForm(request.user))
    user = request.user

    if request.method == "POST" and request.is_ajax():
        if user.has_access_to(DomainACL.WRITE):
            response = process_bulk_add_domain(request, formdict)
        else:
            response = {
                "success": False,
                "message": "User does not have permission to add domains."
            }

        return HttpResponse(json.dumps(response, default=json_handler),
                            content_type="application/json")
    else:
        if user.has_access_to(DomainACL.WRITE):
            objectformdict = form_to_dict(AddObjectForm(request.user))
            return render_to_response(
                'bulk_add_default.html', {
                    'formdict': formdict,
                    'objectformdict': objectformdict,
                    'title': "Bulk Add Domains",
                    'table_name': 'domain',
                    'local_validate_columns': [form_consts.Domain.DOMAIN_NAME],
                    'custom_js': "domain_handsontable.js",
                    'is_bulk_add_objects': True
                }, RequestContext(request))
        else:
            response = {
                "success": False,
                "message": "User does not have permission to add domains."
            }
            return HttpResponse(json.dumps(response, default=json_handler),
                                content_type="application/json")
예제 #2
0
파일: views.py 프로젝트: brlogan/crits
def bulk_add_domain(request):
    """
    Bulk add domains via a bulk upload form.

    Args:
        request: The Django context which contains information about the
            session and key/value pairs for the bulk add domains request

    Returns:
        If the request is not a POST and not a Ajax call then:
            Returns a rendered HTML form for a bulk add of domains
        If the request is a POST and a Ajax call then:
            Returns a response that contains information about the
            status of the bulk uploaded domains. This may include information
            such as domains that failed or successfully added. This may
            also contain helpful status messages about each operation.
    """

    formdict = form_to_dict(AddDomainForm(request.user))
    user = request.user

    if request.method == "POST" and request.is_ajax():
        if user.has_access_to(DomainACL.WRITE):
            response = process_bulk_add_domain(request, formdict)
        else:
            response = {"success":False,
                        "message":"User does not have permission to add domains."}


        return HttpResponse(json.dumps(response,
                            default=json_handler),
                            content_type="application/json")
    else:
        if user.has_access_to(DomainACL.WRITE):
            objectformdict = form_to_dict(AddObjectForm(request.user))
            return render_to_response('bulk_add_default.html',
                                     {'formdict': formdict,
                                      'objectformdict': objectformdict,
                                      'title': "Bulk Add Domains",
                                      'table_name': 'domain',
                                      'local_validate_columns': [form_consts.Domain.DOMAIN_NAME],
                                      'custom_js': "domain_handsontable.js",
                                      'is_bulk_add_objects': True},
                                      RequestContext(request));
        else:
            response = {"success":False,
                        "message":"User does not have permission to add domains."}
            return HttpResponse(json.dumps(response,
                                default=json_handler),
                                content_type="application/json")
예제 #3
0
파일: views.py 프로젝트: plouzek/crits-1
def bulk_add_domain(request):
    """
    Bulk add domains via a bulk upload form.

    Args:
        request: The Django context which contains information about the
            session and key/value pairs for the bulk add domains request

    Returns:
        If the request is not a POST and not a Ajax call then:
            Returns a rendered HTML form for a bulk add of domains
        If the request is a POST and a Ajax call then:
            Returns a response that contains information about the
            status of the bulk uploaded domains. This may include information
            such as domains that failed or successfully added. This may
            also contain helpful status messages about each operation.
    """

    all_obj_type_choices = [(c[0],
                            c[0],
                            {'datatype':c[1].keys()[0],
                            'datatype_value':c[1].values()[0]}
                            ) for c in get_object_types(False)]

    formdict = form_to_dict(AddDomainForm(request.user))

    if request.method == "POST" and request.is_ajax():
        response = process_bulk_add_domain(request, formdict);

        return HttpResponse(json.dumps(response,
                            default=json_handler),
                            mimetype='application/json')
    else:
        objectformdict = form_to_dict(AddObjectForm(request.user, all_obj_type_choices))

        return render_to_response('bulk_add_default.html',
                                 {'formdict': formdict,
                                  'objectformdict': objectformdict,
                                  'title': "Bulk Add Domains",
                                  'table_name': 'domain',
                                  'local_validate_columns': [form_consts.Domain.DOMAIN_NAME],
                                  'custom_js': "domain_handsontable.js",
                                  'is_bulk_add_objects': True},
                                  RequestContext(request));
예제 #4
0
def bulk_add_domain(request):
    """
    Bulk add domains via a bulk upload form.

    Args:
        request: The Django context which contains information about the
            session and key/value pairs for the bulk add domains request

    Returns:
        If the request is not a POST and not a Ajax call then:
            Returns a rendered HTML form for a bulk add of domains
        If the request is a POST and a Ajax call then:
            Returns a response that contains information about the
            status of the bulk uploaded domains. This may include information
            such as domains that failed or successfully added. This may
            also contain helpful status messages about each operation.
    """

    all_obj_type_choices = [
        (c[0], c[0], {"datatype": c[1].keys()[0], "datatype_value": c[1].values()[0]}) for c in get_object_types(False)
    ]

    formdict = form_to_dict(AddDomainForm(request.user))

    if request.method == "POST" and request.is_ajax():
        response = process_bulk_add_domain(request, formdict)

        return HttpResponse(json.dumps(response, default=json_handler), mimetype="application/json")
    else:
        objectformdict = form_to_dict(AddObjectForm(request.user, all_obj_type_choices))

        return render_to_response(
            "bulk_add_default.html",
            {
                "formdict": formdict,
                "objectformdict": objectformdict,
                "title": "Bulk Add Domains",
                "table_name": "domain",
                "local_validate_columns": [form_consts.Domain.DOMAIN_NAME],
                "custom_js": "domain_handsontable.js",
                "is_bulk_add_objects": True,
            },
            RequestContext(request),
        )