Esempio n. 1
0
 def get_context_data(self, **kwargs):
     data = super(ProblemSubmissionView, self).get_context_data(**kwargs)
     data['submission'] = submission = get_object_or_404(
         Submission,
         pk=self.kwargs.get('sid'),
         problem_id=self.kwargs.get('pk'),
         contest__isnull=True)
     if submission.author == self.request.user and \
             submission.is_judged and is_case_download_available(self.request.user, self.kwargs.get('pk')):
         submission.allow_case_download = True
     if self.request.user.is_authenticated and (
             submission.author == self.request.user
             or is_problem_manager(self.request.user, submission.problem)
             or self.request.user.submission_set.filter(
                 problem_id=self.kwargs.get('pk'),
                 status=SubmissionStatus.ACCEPTED).exists()):
         permission = get_permission_for_submission(self.request.user,
                                                    submission,
                                                    special_permission=True)
         data['submission_block'] = render_submission(submission,
                                                      permission=permission)
         if permission == 2 or (self.request.user == submission.author
                                and submission.report_paid):
             data['report_block'] = render_submission_report(submission.pk)
         else:
             data['report_block'] = ''
     else:
         raise PermissionDenied(
             "Code is not public for users who have not got accepted yet.")
     data['problem'] = submission.problem
     return data
Esempio n. 2
0
 def get_context_data(self, **kwargs):
     data = super(ContestSubmissionView, self).get_context_data(**kwargs)
     data['submission'] = submission = get_contest_submission(self.kwargs.get('sid'), self.kwargs.get('cid'))
     submission.contest_problem = self.contest.get_contest_problem(submission.problem_id)
     if submission.author == self.request.user and self.contest.case_public and submission.is_judged and \
             is_case_download_available(self.request.user, submission.problem_id, submission.contest_id):
         submission.allow_case_download = True
     authorized = False
     if self.request.user.is_authenticated:  # Check author or managers (no share)
         if is_contest_manager(self.request.user,
                               self.contest) or self.request.user == submission.author:
             authorized = True
         if not authorized and self.contest.allow_code_share > 0:  # start to share
             if self.participate_contest_status > 0 and self.contest.allow_code_share >= 2:
                 authorized = True
             if self.request.user.submission_set.filter(problem_id=submission.problem_id,
                                                        status=SubmissionStatus.ACCEPTED).exists() and (
                             self.participate_contest_status > 0 or self.contest.allow_code_share >= 3):
                 authorized = True
     if self.participate_contest_status > 0 and self.request.user.is_authenticated and self.request.user.has_coach_access():
         authorized = True
     if authorized:
         permission = get_permission_for_submission(self.request.user, submission, special_permission=True)
         # it is already authorized thus requires special permission to open it
         data['submission_block'] = render_submission(submission,
                                                      permission=permission,
                                                      show_percent=data['show_percent'])
         if permission == 2 or (self.request.user == submission.author and submission.report_paid) or \
                 (self.participate_contest_status > 0 and self.request.user.has_coach_access()) or self.contest.case_public >= 2:
             data['report_block'] = render_submission_report(submission.pk)
         else:
             data['report_block'] = ''
     else:
         raise PermissionDenied
     return data