3 from django.shortcuts import render
4 from django.utils import simplejson
5 from django.conf import settings
6 from django.http import Http404
8 from .models import Submission
9 from .forms import WTEMForm
11 WTEM_CONTEST_STAGE = getattr(settings, 'WTEM_CONTEST_STAGE', 'before')
17 def form(request, key):
18 return globals()['form_' + WTEM_CONTEST_STAGE](request, key)
20 def form_before(request, key):
21 return render(request, 'wtem/main_before.html')
23 def form_after(request, key):
24 return render(request, 'wtem/main_after.html')
26 def form_during(request, key):
28 submission = Submission.objects.get(key = key)
29 except Submission.DoesNotExist:
30 if settings.DEBUG and key == '12345':
31 submission = Submission.create(first_name = 'Debug', last_name = 'Debug', email = 'debug@debug.com', key = '12345')
35 ## @@ move this out of the view
36 f = file(os.path.dirname(__file__) + '/fixtures/exercises.json')
37 exercises = simplejson.loads(f.read())
40 if request.method == 'GET':
41 return render(request, 'wtem/main.html', dict(exercises = exercises))
42 elif request.method == 'POST':
43 form = WTEMForm(request.POST, request.FILES, instance = submission)
46 return render(request, 'wtem/thanks.html')