Esempio n. 1
0
def model_form_upload(request):
    if request.method == 'POST':
        form = SurveyUploadForm(request.POST, request.FILES)
        if form.is_valid():
            data = form.cleaned_data
            details = SurveyDetails()
            # adding unique index for each survey dataset
            id_obj = repr(datetime.datetime.utcnow())[17:] + " " + str(data['survey_name'])[0:3]
            #details.row_num = data['row_num']
            #details.survey_key = id_obj
            #details.survey_id = data['survey_id']
            details.survey_name = data['survey_name']
            details.num_participants = data['num_participants']
            details.org_conduct = data['org_conduct']
            details.num_questions = data['num_questions']
            details.data_link = data['data_link']
            details.doc_link = data['doc_link']
            details.source_link = data['source_link']
            details.summary = data['summary']
            details.survey_questions_document = data['survey_questions_document']
            details.save()
            #form.save()
            handle_files('documents/' + request.FILES['survey_questions_document'].name, id_obj)
            print()
            return redirect('upload_success.html')
    else:
        form = SurveyUploadForm()
    return render(request, 'search/upload.html', {
        'form': form
    })
Esempio n. 2
0
def model_form_upload(request):
    if request.method == 'POST':
        form = SurveyUploadForm(request.POST, request.FILES)
        if form.is_valid():
            data = form.cleaned_data
            details = SurveyDetails()
            current_objects = list(SurveyDetails.objects.all())
            unique_upload = True
            csv_upload = True
            # initialize error message dictionaries to return unique error messages
            error_dict = {"csv": "", "unique": ""}
            # check for valid csv upload and duplicate survey names
            if request.FILES['survey_questions_document'].name[-3:] != "csv":
                csv_upload = False
                error_dict["csv"] = "Please upload a .csv file."
            for item in current_objects:
                if item.survey_name == data['survey_name']:
                    unique_upload = False
                    error_dict["unique"] = "This survey already exists in the database."
            if unique_upload and csv_upload:
                # adding unique index for each survey dataset
                id_obj = repr(datetime.datetime.utcnow())[17:] + " " + str(data['survey_name'])[0:3]
                details.survey_key = id_obj
                details.survey_name = data['survey_name']
                details.num_participants = data['num_participants']
                details.org_conduct = data['org_conduct']
                details.num_questions = data['num_questions']
                details.data_link = data['data_link']
                details.doc_link = data['doc_link']
                details.source_link = data['source_link']
                details.summary = data['summary']
                details.survey_questions_document = data['survey_questions_document']
                details.save()
                handle_files('documents/' + request.FILES['survey_questions_document'].name, id_obj)
                generate_wordcloud()

                return redirect('upload_success.html')
            else:
                # render error messages to failure page
                return render_to_response('search/upload_failure.html', error_dict)
    else:
        form = SurveyUploadForm()
    return render(request, 'search/upload.html', {
        'form': form
    })
Esempio n. 3
0
def model_form_upload(request):
    if request.method == 'POST':
        form = SurveyUploadForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()
            return redirect('search/index.html')
    else:
        form = SurveyUploadForm()
    return render(request, 'search/upload.html', {
        'form': form
    })
Esempio n. 4
0
def model_form_upload(request):
    if request.method == 'POST':
        form = SurveyUploadForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()
            handle_files('documents/' +
                         request.FILES['survey_questions_document'].name)
            print()
            return redirect('upload_success.html')
    else:
        form = SurveyUploadForm()
    return render(request, 'search/upload.html', {'form': form})
Esempio n. 5
0
def model_form_upload(request):
    if request.method == 'POST':
        form = SurveyUploadForm(request.POST, request.FILES)
        if form.is_valid():
            data = form.cleaned_data
            details = SurveyDetails()
            current_objects = list(SurveyDetails.objects.all())
            unique_upload = True
            for item in current_objects:
                if item.survey_name == data['survey_name']:
                    unique_upload = False
            if unique_upload and request.FILES['survey_questions_document'].name[-3:] == "csv":
                # adding unique index for each survey dataset
                id_obj = repr(datetime.datetime.utcnow())[17:] + " " + str(data['survey_name'])[0:3]
                details.survey_key = id_obj
                details.survey_name = data['survey_name']
                details.num_participants = data['num_participants']
                details.org_conduct = data['org_conduct']
                details.num_questions = data['num_questions']
                details.data_link = data['data_link']
                details.doc_link = data['doc_link']
                details.source_link = data['source_link']
                details.summary = data['summary']
                details.survey_questions_document = data['survey_questions_document']
                details.save()
                handle_files('documents/' + request.FILES['survey_questions_document'].name, id_obj)
                generate_wordcloud()

                return redirect('upload_success.html')
            else:
                return redirect('upload_failure.html')
    else:
        form = SurveyUploadForm()
    return render(request, 'search/upload.html', {
        'form': form
    })