def get(self, request, cid): type = request.GET.get('t') if type and 'all' in type and self.privileged: submissions = self.contest.submission_set else: submissions = self.contest.submission_set.filter( author=request.user) if type and 'accepted' in type: submissions = submissions.filter(status=SubmissionStatus.ACCEPTED) submissions = submissions.select_related("author") self.contest.add_contest_problem_to_submissions(submissions) participants = dict( self.contest.contestparticipant_set.values_list( 'user_id', 'comment')) file_path = path.join(settings.GENERATE_DIR, random_string()) lang_ext_dict = dict(LANG_EXT) with zipfile.ZipFile(file_path, "w", zipfile.ZIP_DEFLATED) as zip: zip.writestr('/contest.nfo', '') for submission in submissions: user = submission.author.username if participants[submission.author_id]: user = participants[submission.author_id] user = self.__class__.slugify_filename(user) if getattr(submission, 'contest_problem') and submission.contest_problem: zip.writestr( "/%s_%s/%s_#%d_%s.%s" % (user, submission.author_id, submission.contest_problem.identifier, submission.pk, submission.get_status_display().replace(' ', '_'), lang_ext_dict.get(submission.lang, 'txt')), submission.code) return respond_generate_file( request, file_path, "ContestCode - %s.zip" % self.contest.title)
class CasePackAsZipView(ProblemRevisionMixin, View): def get_redirect_url(self): return reverse('polygon:revision_case', kwargs={'pk': self.problem.id, 'rpk': self.revision.id}) def get(self, request, *args, **kwargs): input_only = False if 'input' in request.GET: input_only = True cases = list(self.revision.cases.all().order_by("case_number")) if len(cases) == 0: messages.error(request, "There are no cases to pack.") return redirect(self.get_redirect_url()) for idx, case in enumerate(cases): if idx > 0 and case.case_number == cases[idx - 1].case_number: messages.error(request, "Cases refuse to pack because there are two cases with the same case number.") return redirect(self.get_redirect_url()) file_path = path.join(settings.GENERATE_DIR, random_string()) case_config = {} with zipfile.ZipFile(file_path, "w", zipfile.ZIP_DEFLATED) as zip: for case in cases: zip.write(case.input_file.path, arcname="%d" % case.case_number) if not input_only: zip.write(case.output_file.path, arcname="%d.a" % case.case_number) case_config[str(case.case_number)] = { "in_samples": case.in_samples, "activated": case.activated, "group": case.group, "description": case.description, "points": case.points } if not input_only: zip.writestr("data.json", json.dumps(case_config, sort_keys=True, indent=2)) return respond_generate_file(request, file_path, "TestData_%s#%d.zip" % (self.problem.alias, self.revision.revision))
def get(self, request, pk): data = [[user.comment, user.code] for user in self.contest.contestinvitation_set.all()] filename = write_csv(data) return respond_generate_file( request, filename, file_name_serve_as="InvitationCode - %s.csv" % self.contest.title)
def get(self, request, pk): data = [[user.comment, user.user.username, user.hidden_comment] for user in self.contest.contestparticipant_set.select_related( "user").all()] filename = write_csv(data) return respond_generate_file( request, filename, file_name_serve_as="ContestParticipant - %s.csv" % self.contest.title)
def get(self, request, cid): if not self.privileged: raise PermissionDenied rank_list = get_contest_rank(self.contest) contest_participants = { user.user_id: user for user in ContestParticipant.objects.filter( contest=self.contest).select_related('user', 'contest').all() } header = ["Rank", "Username", "Info", "E-mail", "Name", "Score"] if self.contest.contest_type == 0 and self.contest.penalty_counts: header.append("Penalty") for problem in self.contest.contest_problem_list: header.append(problem.identifier) data = [header] for rank in rank_list: d = [] d.append( str(rank["actual_rank"]) if rank.get("actual_rank") else "") participant = contest_participants[rank['user']] d.append(participant.user.username) d.append(participant.comment) d.append(participant.user.email) d.append(participant.user.name) d.append(str(rank["score"])) if self.contest.contest_type == 0 and self.contest.penalty_counts: d.append(str(rank["penalty"] // 60)) for problem in self.contest.contest_problem_list: detail = rank["detail"].get(problem.problem_id) text = '' if detail and not detail.get("waiting", False) and detail.get("attempt"): if self.contest.scoring_method != "acm": text = str(detail["score"]) elif detail["solved"]: text = "+" + str(detail["attempt"] - 1) if self.contest.contest_type == 1: text += '(%s)' % (detail["pass_time"]) elif self.contest.penalty_counts: text += "(%d)" % (detail["time"] // 60) else: text = "-" + str(detail["attempt"]) d.append(text) data.append(d) file_name = write_csv(data) return respond_generate_file( request, file_name, file_name_serve_as="ContestStandings - %s.csv" % self.contest.title)