+def cache_until_start(view_func):
+ @wraps(view_func)
+ def _wrapped_view_func(request, *args, **kwargs):
+ response = view_func(request, *args, **kwargs)
+ max_age = max(int((CompetitionState.start - timezone.now()).total_seconds()) + 1, 0)
+ if max_age:
+ patch_cache_control(response, max_age=max_age)
+ else:
+ add_never_cache_headers(response)
+ return response
+
+ return _wrapped_view_func
+
+
+@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 = Submission.objects.get(id=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')