Exemple #1
0
def bulk_add_md5_sample(request):
    """
    Bulk add samples via a bulk upload form.

    Args:
        request: The Django context which contains information about the
            session and key/value pairs for the bulk add 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 add. This may include information
            such as items 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(
        UploadFileForm(request.user, request.POST, request.FILES))
    objectformdict = form_to_dict(
        AddObjectForm(request.user, all_obj_type_choices))

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

        return HttpResponse(json.dumps(response, default=json_handler),
                            mimetype='application/json')
    else:
        return render_to_response(
            'bulk_add_default.html', {
                'formdict': formdict,
                'objectformdict': objectformdict,
                'title': "Bulk Add Samples",
                'table_name': 'sample',
                'local_validate_columns': [form_consts.Sample.MD5],
                'is_bulk_add_objects': True
            }, RequestContext(request))
Exemple #2
0
def bulk_add_md5_sample(request):
    """
    Bulk add samples via a bulk upload form.

    Args:
        request: The Django context which contains information about the
            session and key/value pairs for the bulk add 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 add. This may include information
            such as items 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(UploadFileForm(request.user, request.POST, request.FILES))
    objectformdict = form_to_dict(AddObjectForm(request.user, all_obj_type_choices))

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

        return HttpResponse(json.dumps(response,
                            default=json_handler),
                            mimetype='application/json')
    else:
        return render_to_response('bulk_add_default.html',
                                  {'formdict': formdict,
                                  'objectformdict': objectformdict,
                                  'title': "Bulk Add Samples",
                                  'table_name': 'sample',
                                  'local_validate_columns': [form_consts.Sample.MD5],
                                  'is_bulk_add_objects': True},
                                  RequestContext(request));