+ submission_id = int(submission_id)
+ except ValueError:
+ raise Http404
+ return get_object_or_404(Submission, id=submission_id)
+
+
+@csrf_exempt
+def form(request, submission_id, key):
+ state = CompetitionState.get_state()
+ if state == CompetitionState.DURING:
+ state = 'single'
+ return globals()['form_' + state](request, submission_id, key)
+
+
+@cache_until_start
+def form_before(request, submission_id, key):
+ submission = get_submission(submission_id)
+ if submission.key != key:
+ return render(request, 'wtem/key_not_found_before.html')
+ else:
+ submission.opened_link = True
+ submission.save()
+ return render(request, 'wtem/main_before.html')
+
+
+def form_after(request, submission_id, key):
+ return render(request, 'wtem/main_after.html')
+
+
+@never_cache
+@csrf_exempt
+def form_during(request, key):
+
+ if CompetitionState.get_state() != CompetitionState.DURING:
+ if request.META['REMOTE_ADDR'] not in getattr(settings, 'WTEM_CONTEST_IP_ALLOW', []):
+ return HttpResponseForbidden('Not allowed')
+
+ try:
+ submission = Submission.objects.get(key=key)