예제 #1
0
def verify_preview(request, pk=None):
	try:
		in_progress = models.UploadProgress.objects.get(pk=pk)
	except:
		raise Http404
	progress = Progress(in_progress)
	context = {}
	if request.method == 'POST':
		progress.write_database()
		return redirect('../../')
	else:
		if not progress.dates_verified():
			return redirect('../')
		if not progress.locations_verified():
			return redirect('../locations/')
		if not progress.varieties_verified():
			return redirect('../varieties/')
		if not progress.measures_verified():
			return redirect('../measures/')
		if not progress.statistics_verified():
			return redirect('../statistics/')
		year, table, summary, statnames, colnames, rownames = progress.prepare_table()
		preview_table = zip(rownames, table)
		preview_summary = zip(statnames, summary)
		context['year'] = year
		context['preview_table'] = preview_table
		context['preview_summary'] = preview_summary
		context['column_headers'] = ['', ] + colnames
	return render(request, 'verify-preview.html', context)
예제 #2
0
def verify_preview(request, pk=None):
    try:
        in_progress = models.UploadProgress.objects.get(pk=pk)
    except:
        raise Http404
    progress = Progress(in_progress)
    context = {}
    if request.method == 'POST':
        progress.write_database()
        return redirect('../../')
    else:
        if not progress.dates_verified():
            return redirect('../')
        if not progress.locations_verified():
            return redirect('../locations/')
        if not progress.varieties_verified():
            return redirect('../varieties/')
        if not progress.measures_verified():
            return redirect('../measures/')
        if not progress.statistics_verified():
            return redirect('../statistics/')
        year, table, summary, statnames, colnames, rownames = progress.prepare_table(
        )
        preview_table = zip(rownames, table)
        preview_summary = zip(statnames, summary)
        context['year'] = year
        context['preview_table'] = preview_table
        context['preview_summary'] = preview_summary
        context['column_headers'] = [
            '',
        ] + colnames
    return render(request, 'verify-preview.html', context)
예제 #3
0
def verify(request, pk=None):
    try:
        in_progress = models.UploadProgress.objects.get(pk=pk)
    except:
        raise Http404
    context = {}
    progress = Progress(in_progress)
    if request.method == 'POST':
        row_form = forms.VerifyHeaders(request.POST,
                                       prefix=HeaderGuess.ROW_PREFIX)
        col_form = forms.VerifyHeaders(request.POST,
                                       prefix=HeaderGuess.COLUMN_PREFIX)
        dateform = forms.DateForm(request.POST)
        if not dateform.is_valid():
            return redirect('.')  # TODO: Let user know dateform was invalid
        if row_form.is_bound and row_form.is_valid():
            row_type = row_form.cleaned_data['header_type']
        else:
            row_type = HeaderTypes.Data
        if col_form.is_bound and col_form.is_valid():
            col_type = col_form.cleaned_data['header_type']
        else:
            col_type = HeaderTypes.Data
        progress.store_date(dateform, save=False)
        progress.store_headers(row_type, col_type)
        if progress.dates_verified():
            return redirect('locations/')
        else:
            return redirect('.')  # TODO: Let user know date was unverified
    else:
        col_guess, row_guess = progress.header_guesses()
        verify_dicts = []
        for guess in (col_guess, row_guess):
            if guess.our_guess() is None or not any(guess.users_input()):
                continue
            form = forms.VerifyHeaders(
                initial={'header_type': guess.our_guess()},
                prefix=guess.prefix)
            verify_dicts.append({'headers': guess.users_input(), 'form': form})
        context['verify_dicts'] = verify_dicts
        now_year = datetime.datetime.now().year
        context['dateform'] = forms.DateForm(initial={'year': now_year})
    return render(request, 'verify.html', context)
예제 #4
0
def verify(request, pk=None):
	try:
		in_progress = models.UploadProgress.objects.get(pk=pk)
	except:
		raise Http404
	context = {}
	progress = Progress(in_progress)
	if request.method == 'POST':
		row_form = forms.VerifyHeaders(request.POST, prefix=HeaderGuess.ROW_PREFIX)
		col_form = forms.VerifyHeaders(request.POST, prefix=HeaderGuess.COLUMN_PREFIX)
		dateform = forms.DateForm(request.POST)
		if not dateform.is_valid():
			return redirect('.') # TODO: Let user know dateform was invalid
		if row_form.is_bound and row_form.is_valid():
			row_type = row_form.cleaned_data['header_type']
		else:
			row_type = HeaderTypes.Data
		if col_form.is_bound and col_form.is_valid():
			col_type = col_form.cleaned_data['header_type']
		else:
			col_type = HeaderTypes.Data
		progress.store_date(dateform, save=False)
		progress.store_headers(row_type, col_type)
		if progress.dates_verified():
			return redirect('locations/')
		else:
			return redirect('.') # TODO: Let user know date was unverified
	else:
		col_guess, row_guess = progress.header_guesses()
		verify_dicts = []
		for guess in (col_guess, row_guess):
			if guess.our_guess() is None or not any(guess.users_input()):
				continue
			form = forms.VerifyHeaders(
					initial={'header_type': guess.our_guess()},
					prefix=guess.prefix
				)
			verify_dicts.append({'headers': guess.users_input(), 'form': form})
		context['verify_dicts'] = verify_dicts
		now_year = datetime.datetime.now().year
		context['dateform'] = forms.DateForm(initial={'year': now_year})
	return render(request, 'verify.html', context)