# 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()


from django.contrib.auth.decorators import login_required
from django.shortcuts import render
from django.views.decorators.http import require_http_methods, require_safe
from harnas.checker.models import Submit


@login_required
@require_safe
def details(request, id):
    submit = Submit.objects.get(pk=id)
    solution = bytes(submit.solution).decode("utf-8")
    return render(request, 'contest/submit_details.html', {
        'submit': submit,
        'solution': solution,

# 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/views/submit.py
from django.contrib.auth.decorators import login_required
from django.shortcuts import render
from django.views.decorators.http import require_http_methods, require_safe
from harnas.checker.models import Submit



@login_required
@require_safe
def details(request, id):
    submit = Submit.objects.get(pk=id)
    solution = bytes(submit.solution).decode("utf-8")
    return render(request, 'contest/submit_details.html', {
        'submit': submit,
        'solution': solution,

    })