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 if WTEM_CONTEST_STAGE != 'during':
29 if request.META['REMOTE_ADDR'] != getattr(settings, 'WTEM_CONTEST_IP_ALLOW', 'xxx'):
33 submission = Submission.objects.get(key = key)
34 except Submission.DoesNotExist:
35 if settings.DEBUG and key == '12345':
36 submission = Submission.create(first_name = 'Debug', last_name = 'Debug', email = 'debug@debug.com', key = '12345')
40 ## @@ move this out of the view
41 f = file(os.path.dirname(__file__) + '/fixtures/exercises.json')
42 exercises = simplejson.loads(f.read())
45 if request.method == 'GET':
46 return render(request, 'wtem/main.html', dict(exercises = exercises))
47 elif request.method == 'POST':
48 form = WTEMForm(request.POST, request.FILES, instance = submission)
51 return render(request, 'wtem/thanks.html')