Exemple #1
0
def api(request):
	if request.method != 'POST':
		return _return_response({'message': "POST required"}, 400)
	
	form = OCRForm(request.POST, request.FILES)
	if not form.is_valid():
		err_label = form.errors.iterkeys().next()
		err_reason = form.errors[err_label][0]
		return _return_response({'message': "%s: %s" % (err_label, err_reason)}, 400)
	
	result = handle_uploaded_file(request.FILES['file'])
	
	return _return_response({'result': result})
Exemple #2
0
def web(request):
	context = {'tab_name': 'web'}
	
	if request.method == 'POST':
		form = OCRForm(request.POST, request.FILES)
		if form.is_valid():
			context['got_ocr_result'] = True
			context['ocr_result'] = handle_uploaded_file(request.FILES['file'])
	else:
		form = OCRForm()
	
	context['form'] = form
	return render_to_response('ocr.html', context, context_instance=RequestContext(request))