# Path: harnas/checker/models.py
# class Submit(models.Model):
#     submitter = models.ForeignKey(User)
#     submitted = models.DateTimeField(auto_now_add=True)
#     task = models.ForeignKey('contest.Task')
#     solution = models.BinaryField()
#     status = models.CharField(max_length=3,
#                               choices=TestCase.STATUS_CHOICES)
#     webhook_secret = models.CharField(
#                         max_length=settings.WEBHOOK_SECRET_LENGTH)
# 
#     def __str__(self):
#         return self.id
# 
#     def change_status(self, status):
#         if status not in [choice[0] for choice in TestCase.STATUS_CHOICES]:
#             raise ValueError("Invalid status")
#         else:
#             self.status = status
#             self.save()
# 
# Path: harnas/contest/models.py
# class TestCase(models.Model):
#     QUEUED = "QUE"
#     MEMORY_LIMIT = "MEM"
#     TIME_LIMIT = "TLE"
#     ACCEPTED = "OK"
#     INTERNAL_ERROR = "INT"
#     WRONG_ANSWER = "ANS"
#     COMPILATION_ERROR = "CME"
#     RUNTIME_ERROR = "RTE"
#     STATUS_CHOICES = (
#         (QUEUED, "In checking queue"),
#         (MEMORY_LIMIT, "Memory limit exceeded"),
#         (TIME_LIMIT, "Time limit exceeded"),
#         (ACCEPTED, "Accepted"),
#         (INTERNAL_ERROR, "Internal error"),
#         (WRONG_ANSWER, "Wrong answer"),
#         (COMPILATION_ERROR, "Compilation error"),
#         (RUNTIME_ERROR, "Runtime error"),
#     )
# 
#     task = models.ForeignKey(Task)
#     name = models.CharField(max_length=100, null=True, default=None)
#     max_memory = models.PositiveIntegerField()
#     max_duration = models.PositiveIntegerField()
#     run_order_id = models.PositiveSmallIntegerField(default=0)
#     comparator = models.CharField(max_length=500)
#     executor = models.CharField(max_length=500)
#     in_file_path = models.FilePathField(max_length=500)
#     out_file_path = models.FilePathField(max_length=500)
# 
#     def __str__(self):
#         return self.name


from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST
from harnas.checker.models import Submit
from harnas.contest.models import TestCase


@require_POST
@csrf_exempt
def check(request, submit_id):
    submit = Submit.objects.get(pk=submit_id)
    webhook_secret = request.POST.get('secret')
    if _is_webhook_secret_valid(submit, webhook_secret):
        response = JsonResponse({'status': 'ok'}, status=200)

# Path: harnas/checker/models.py
# class Submit(models.Model):
#     submitter = models.ForeignKey(User)
#     submitted = models.DateTimeField(auto_now_add=True)
#     task = models.ForeignKey('contest.Task')
#     solution = models.BinaryField()
#     status = models.CharField(max_length=3,
#                               choices=TestCase.STATUS_CHOICES)
#     webhook_secret = models.CharField(
#                         max_length=settings.WEBHOOK_SECRET_LENGTH)
# 
#     def __str__(self):
#         return self.id
# 
#     def change_status(self, status):
#         if status not in [choice[0] for choice in TestCase.STATUS_CHOICES]:
#             raise ValueError("Invalid status")
#         else:
#             self.status = status
#             self.save()
# 
# Path: harnas/contest/models.py
# class TestCase(models.Model):
#     QUEUED = "QUE"
#     MEMORY_LIMIT = "MEM"
#     TIME_LIMIT = "TLE"
#     ACCEPTED = "OK"
#     INTERNAL_ERROR = "INT"
#     WRONG_ANSWER = "ANS"
#     COMPILATION_ERROR = "CME"
#     RUNTIME_ERROR = "RTE"
#     STATUS_CHOICES = (
#         (QUEUED, "In checking queue"),
#         (MEMORY_LIMIT, "Memory limit exceeded"),
#         (TIME_LIMIT, "Time limit exceeded"),
#         (ACCEPTED, "Accepted"),
#         (INTERNAL_ERROR, "Internal error"),
#         (WRONG_ANSWER, "Wrong answer"),
#         (COMPILATION_ERROR, "Compilation error"),
#         (RUNTIME_ERROR, "Runtime error"),
#     )
# 
#     task = models.ForeignKey(Task)
#     name = models.CharField(max_length=100, null=True, default=None)
#     max_memory = models.PositiveIntegerField()
#     max_duration = models.PositiveIntegerField()
#     run_order_id = models.PositiveSmallIntegerField(default=0)
#     comparator = models.CharField(max_length=500)
#     executor = models.CharField(max_length=500)
#     in_file_path = models.FilePathField(max_length=500)
#     out_file_path = models.FilePathField(max_length=500)
# 
#     def __str__(self):
#         return self.name


# Path: harnas/checker/views/checker.py
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST
from harnas.checker.models import Submit
from harnas.contest.models import TestCase



@require_POST
@csrf_exempt
def check(request, submit_id):
    submit = Submit.objects.get(pk=submit_id)
    webhook_secret = request.POST.get('secret')
    if _is_webhook_secret_valid(submit, webhook_secret):
        response = JsonResponse({'status': 'ok'}, status=200)

    else: