Write some unit tests for excel stuff
This commit is contained in:
@@ -14,6 +14,7 @@ import html
|
||||
from members.views.utils import *
|
||||
from members.tables import RequestTable
|
||||
from members.forms import ApplicationForm
|
||||
from members.views import error_view
|
||||
|
||||
|
||||
@ensure_csrf_cookie
|
||||
@@ -47,8 +48,7 @@ def application_edit(request, *args, **kwargs):
|
||||
"""Edit member request information."""
|
||||
i = kwargs.pop('index', None)
|
||||
if i is None:
|
||||
return render(
|
||||
request, 'error.html', {'error': _('No application id specified')})
|
||||
return error_view(request, _('No application id specified'))
|
||||
else:
|
||||
application = Request.objects.get(id=i)
|
||||
form = ApplicationForm(instance=application)
|
||||
@@ -68,9 +68,7 @@ def application_accept(request, *args, **kwargs):
|
||||
if id is not None:
|
||||
application = Request.objects.get(id=id)
|
||||
else:
|
||||
return render(request,
|
||||
'error.html',
|
||||
{'error': _("Application missing 'id' field.")})
|
||||
return error_view(request, _("Application missing 'id' field."))
|
||||
|
||||
form = ApplicationForm(request.POST, instance=application)
|
||||
if form.is_valid():
|
||||
@@ -78,9 +76,9 @@ def application_accept(request, *args, **kwargs):
|
||||
application = form.save()
|
||||
|
||||
if Member.objects.filter(email=application.email).exists():
|
||||
return render(request,
|
||||
'error.html',
|
||||
{'error': _('Email {} is already in use by a member. Application cannot be accepted.').format(application.email)})
|
||||
return error_view(request, _(
|
||||
'Email {} is already in use by a member. Application cannot be accepted.'
|
||||
).format(application.email))
|
||||
|
||||
member = application.to_member()
|
||||
member.save()
|
||||
@@ -96,14 +94,10 @@ def application_accept(request, *args, **kwargs):
|
||||
'/members/list?notification={}'.format(html.escape(notification)))
|
||||
except Exception as ex:
|
||||
logging.exception('Exception while accepting application')
|
||||
return render(request,
|
||||
'error.html',
|
||||
{'error': str(ex)})
|
||||
return error_view(request, str(ex))
|
||||
else:
|
||||
logging.info(form)
|
||||
return render(request,
|
||||
'error.html',
|
||||
{'error': form.errors})
|
||||
return error_view(request, form.errors)
|
||||
|
||||
|
||||
@ensure_csrf_cookie
|
||||
@@ -115,8 +109,7 @@ def application_delete(request, *args, **kwargs):
|
||||
try:
|
||||
id = request.POST['id']
|
||||
except KeyError:
|
||||
return render(
|
||||
request, 'error.html', {'error': _('No application id specified')})
|
||||
return error_view(request, _('No application id specified'))
|
||||
|
||||
try:
|
||||
application = Request.objects.get(id=id)
|
||||
@@ -130,9 +123,7 @@ def application_delete(request, *args, **kwargs):
|
||||
'/members/applications?notification={}'
|
||||
.format(html.escape(notification)))
|
||||
except:
|
||||
return render(request,
|
||||
'error.html',
|
||||
{'error': _('Could not delete application object')})
|
||||
return error_view(request, _('Could not delete application object'))
|
||||
|
||||
|
||||
@ensure_csrf_cookie
|
||||
@@ -143,9 +134,7 @@ def application_delete_confirm(request, *args, **kwargs):
|
||||
"""Confirm application deletion."""
|
||||
i = kwargs.pop('index', None)
|
||||
if i is None:
|
||||
return render(request,
|
||||
'error.html',
|
||||
{'error': _('No application id specified')})
|
||||
return error_view(request, _('No application id specified'))
|
||||
else:
|
||||
application = Request.objects.get(id=i)
|
||||
form = ApplicationForm(instance=application)
|
||||
@@ -172,6 +161,4 @@ def application_submit(request, *args, **kwargs):
|
||||
form.save()
|
||||
return render(request, 'application_success.html', {})
|
||||
else:
|
||||
return render(request,
|
||||
'error.html',
|
||||
{'error': form.errors})
|
||||
return error_view(request, form.errors)
|
||||
|
||||
Reference in New Issue
Block a user