def get_context_data(self, **kwargs): context = super(ContestMixin, self).get_context_data(**kwargs) if self.request.user.is_authenticated: profile = self.request.user.profile in_contest = context['in_contest'] = ( profile.current_contest is not None and profile.current_contest.contest == self.object) if in_contest: context['participation'] = profile.current_contest context['participating'] = True else: try: context['participation'] = profile.contest_history.get( contest=self.object, virtual=0) except ContestParticipation.DoesNotExist: context['participating'] = False context['participation'] = None else: context['participating'] = True else: context['participating'] = False context['participation'] = None context['in_contest'] = False context['now'] = timezone.now() context['is_organizer'] = self.is_organizer if not self.object.og_image or not self.object.summary: metadata = generate_opengraph( 'generated-meta-contest:%d' % self.object.id, self.object.description) context['meta_description'] = self.object.summary or metadata[0] context['og_image'] = self.object.og_image or metadata[1] return context
def get_context_data(self, **kwargs): context = super(ContestMixin, self).get_context_data(**kwargs) if self.request.user.is_authenticated: profile = self.request.user.profile in_contest = context['in_contest'] = (profile.current_contest is not None and profile.current_contest.contest == self.object) if in_contest: context['participation'] = profile.current_contest context['participating'] = True else: try: context['participation'] = profile.contest_history.get(contest=self.object, virtual=0) except ContestParticipation.DoesNotExist: context['participating'] = False context['participation'] = None else: context['participating'] = True else: context['participating'] = False context['participation'] = None context['in_contest'] = False context['now'] = timezone.now() context['is_organizer'] = self.is_organizer if not self.object.og_image or not self.object.summary: metadata = generate_opengraph('generated-meta-contest:%d' % self.object.id, self.object.description, 'contest') context['meta_description'] = self.object.summary or metadata[0] context['og_image'] = self.object.og_image or metadata[1] return context
def get_context_data(self, **kwargs): context = super(ContestMixin, self).get_context_data(**kwargs) if self.request.user.is_authenticated: profile = self.request.profile in_contest = context['in_contest'] = (profile.current_contest is not None and profile.current_contest.contest == self.object) if in_contest: context['participation'] = profile.current_contest context['participating'] = True else: try: context['participation'] = profile.contest_history.get(contest=self.object, virtual=0) except ContestParticipation.DoesNotExist: context['participating'] = False context['participation'] = None else: context['participating'] = True else: context['participating'] = False context['participation'] = None context['in_contest'] = False context['now'] = timezone.now() context['is_organizer'] = self.is_organizer if not self.object.og_image or not self.object.summary: metadata = generate_opengraph('generated-meta-contest:%d' % self.object.id, self.object.description, 'contest') context['meta_description'] = self.object.summary or metadata[0] context['og_image'] = self.object.og_image or metadata[1] context['has_moss_api_key'] = settings.MOSS_API_KEY is not None context['logo_override_image'] = self.object.logo_override_image if not context['logo_override_image'] and self.object.organizations.count() == 1: context['logo_override_image'] = self.object.organizations.first().logo_override_image return context
def get_context_data(self, **kwargs): context = super(ProblemDetail, self).get_context_data(**kwargs) user = self.request.user authed = user.is_authenticated print(kwargs) if 'course' in kwargs: context['course'] = kwargs.get('course') context['has_submissions'] = authed and Submission.objects.filter(user=user.profile, problem=self.object).exists() contest_problem = (None if not authed or user.profile.current_contest is None else get_contest_problem(self.object, user.profile)) context['contest_problem'] = contest_problem if contest_problem: clarifications = self.object.clarifications context['has_clarifications'] = clarifications.count() > 0 context['clarifications'] = clarifications.order_by('-date') context['submission_limit'] = contest_problem.max_submissions if contest_problem.max_submissions: context['submissions_left'] = max(contest_problem.max_submissions - get_contest_submission_count(self.object, user.profile, user.profile.current_contest.virtual), 0) context['available_judges'] = Judge.objects.filter(online=True, problems=self.object) context['show_languages'] = self.object.allowed_languages.count() != Language.objects.count() context['has_pdf_render'] = HAS_PDF context['completed_problem_ids'] = self.get_completed_problems() context['attempted_problems'] = self.get_attempted_problems() can_edit = self.object.is_editable_by(user) context['can_edit_problem'] = can_edit if user.is_authenticated: tickets = self.object.tickets if not can_edit: tickets = tickets.filter(own_ticket_filter(user.profile.id)) context['has_tickets'] = tickets.exists() context['num_open_tickets'] = tickets.filter(is_open=True).values('id').distinct().count() try: context['editorial'] = Solution.objects.get(problem=self.object) except ObjectDoesNotExist: pass try: translation = self.object.translations.get(language=self.request.LANGUAGE_CODE) except ProblemTranslation.DoesNotExist: context['title'] = self.object.name context['language'] = settings.LANGUAGE_CODE context['description'] = self.object.description context['translated'] = False else: context['title'] = translation.name context['language'] = self.request.LANGUAGE_CODE context['description'] = translation.description context['translated'] = True if not self.object.og_image or not self.object.summary: metadata = generate_opengraph('generated-meta-problem:%s:%d' % (context['language'], self.object.id), context['description'], 'problem') context['meta_description'] = self.object.summary or metadata[0] context['og_image'] = self.object.og_image or metadata[1] return context
def get_context_data(self, **kwargs): context = super(ProblemDetail, self).get_context_data(**kwargs) user = self.request.user authed = user.is_authenticated context['has_submissions'] = authed and Submission.objects.filter(user=user.profile, problem=self.object).exists() contest_problem = (None if not authed or user.profile.current_contest is None else get_contest_problem(self.object, user.profile)) context['contest_problem'] = contest_problem if contest_problem: clarifications = self.object.clarifications context['has_clarifications'] = clarifications.count() > 0 context['clarifications'] = clarifications.order_by('-date') context['submission_limit'] = contest_problem.max_submissions if contest_problem.max_submissions: context['submissions_left'] = max(contest_problem.max_submissions - get_contest_submission_count(self.object.code, user.profile), 0) context['available_judges'] = Judge.objects.filter(online=True, problems=self.object) context['show_languages'] = self.object.allowed_languages.count() != Language.objects.count() context['has_pdf_render'] = HAS_PDF context['completed_problem_ids'] = self.get_completed_problems() context['attempted_problems'] = self.get_attempted_problems() can_edit = self.object.is_editable_by(user) context['can_edit_problem'] = can_edit if user.is_authenticated: tickets = self.object.tickets if not can_edit: tickets = tickets.filter(own_ticket_filter(user.profile.id)) context['has_tickets'] = tickets.exists() context['num_open_tickets'] = tickets.filter(is_open=True).values('id').distinct().count() try: context['editorial'] = Solution.objects.get(problem=self.object) except ObjectDoesNotExist: pass try: translation = self.object.translations.get(language=self.request.LANGUAGE_CODE) except ProblemTranslation.DoesNotExist: context['title'] = self.object.name context['language'] = settings.LANGUAGE_CODE context['description'] = self.object.description context['translated'] = False else: context['title'] = translation.name context['language'] = self.request.LANGUAGE_CODE context['description'] = translation.description context['translated'] = True if not self.object.og_image or not self.object.summary: metadata = generate_opengraph('generated-meta-problem:%s:%d' % (context['language'], self.object.id), context['description'], 'problem') context['meta_description'] = self.object.summary or metadata[0] context['og_image'] = self.object.og_image or metadata[1] return context
def get_context_data(self, **kwargs): context = super(CourseMixin, self).get_context_data(**kwargs) if self.request.user.is_authenticated: context['has_joined'] = self.has_joined context['now'] = timezone.now() context['is_organizer'] = self.is_organizer context['can_edit'] = self.can_edit if not self.object.og_image or not self.object.summary: metadata = generate_opengraph( 'generated-meta-contest:%d' % self.object.id, self.object.description, 'contest') context['meta_description'] = self.object.summary or metadata[0] context['og_image'] = self.object.og_image or metadata[1] context['has_moss_api_key'] = settings.MOSS_API_KEY is not None context['logo_override_image'] = self.object.logo_override_image if not context[ 'logo_override_image'] and self.object.organizations.count( ) == 1: context['logo_override_image'] = self.object.organizations.first( ).logo_override_image return context
def get_context_data(self, **kwargs): context = super(ProblemDetail, self).get_context_data(**kwargs) user = self.request.user authed = user.is_authenticated context['has_submissions'] = authed and Submission.objects.filter(user=user.profile, problem=self.object).exists() contest_problem = (None if not authed or user.profile.current_contest is None else get_contest_problem(self.object, user.profile)) context['contest_problem'] = contest_problem if contest_problem: clarifications = self.object.clarifications context['has_clarifications'] = clarifications.count() > 0 context['clarifications'] = clarifications.order_by('-date') context['submission_limit'] = contest_problem.max_submissions if contest_problem.max_submissions: context['submissions_left'] = max(contest_problem.max_submissions - get_contest_submission_count(self.object, user.profile, user.profile.current_contest.virtual), 0) context['available_judges'] = Judge.objects.filter(online=True, problems=self.object) context['show_languages'] = self.object.allowed_languages.count() != Language.objects.count() context['has_pdf_render'] = HAS_PDF context['completed_problem_ids'] = self.get_completed_problems() context['attempted_problems'] = self.get_attempted_problems() can_edit = self.object.is_editable_by(user) context['can_edit_problem'] = can_edit if user.is_authenticated: tickets = self.object.tickets if not can_edit: tickets = tickets.filter(own_ticket_filter(user.profile.id)) context['has_tickets'] = tickets.exists() context['num_open_tickets'] = tickets.filter(is_open=True).values('id').distinct().count() try: context['editorial'] = Solution.objects.get(problem=self.object) except ObjectDoesNotExist: pass try: translation = self.object.translations.get(language=self.request.LANGUAGE_CODE) except ProblemTranslation.DoesNotExist: context['title'] = self.object.name context['language'] = settings.LANGUAGE_CODE context['description'] = self.object.description context['translated'] = False else: context['title'] = translation.name context['language'] = self.request.LANGUAGE_CODE context['description'] = translation.description context['translated'] = True if not self.object.og_image or not self.object.summary: metadata = generate_opengraph('generated-meta-problem:%s:%d' % (context['language'], self.object.id), context['description'], 'problem') context['meta_description'] = self.object.summary or metadata[0] context['og_image'] = self.object.og_image or metadata[1] context['can_vote'] = self.object.can_vote(user) # if this problem is votable by this user # the vote this user has already cast on this problem if context['can_vote']: vote = ProblemPointsVote.objects.filter(voter=user.profile, problem=self.object) # whether or not they've already voted context['has_voted'] = context['can_vote'] and vote.exists() if context['has_voted']: context['voted_points'] = vote.first().points # the previous vote's points context['voted_note'] = vote.first().note if 'problem_points_vote_form' not in context: context['problem_points_vote_form'] = ProblemPointsVoteForm({}) if 'has_errors' not in context: context['has_errors'] = False if 'points_placeholder' not in context: # placeholder for the points if context['has_voted']: # if voted, the vote context['points_placeholder'] = context['voted_points'] else: context['points_placeholder'] = 10 if 'note_placeholder' not in context: if context['has_voted']: context['note_placeholder'] = context['voted_note'] else: context['note_placeholder'] = _("A short justification for this problem's points value.") all_votes = list(self.object.problem_points_votes.order_by('points').values_list('points', flat=True)) # testing # all_votes = list(self.object.problem_points_votes.order_by('points').values_list('points', flat=True)) context['has_votes'] = len(all_votes) > 0 if context['has_votes']: context['mean_vote'] = sum(all_votes) / len(all_votes) context['num_votes'] = len(all_votes) context['min_vote'] = all_votes[0] context['max_vote'] = all_votes[-1] # provides index and value of the median of some range of the data def median(left_index, right_index, data): size = right_index - left_index + 1 index = left_index + (size - 1) / 2 value = (data[math.floor(index)] + data[math.ceil(index)]) / 2 return index, value median_data = median(0, len(all_votes) - 1, all_votes) context['median_vote'] = median_data[1] median_index = median_data[0] context['enough_data_for_plot'] = len(all_votes) > 1 if context['enough_data_for_plot']: # box and whisker plot data q1 = median(0, math.ceil(median_index - 1), all_votes) # first quartile q3 = median(math.floor(median_index + 1), len(all_votes) - 1, all_votes) # third quartile context['first_quartile'] = q1[1] context['third_quartile'] = q3[1] context['in_contest'] = user.profile.current_contest is not None if context['can_vote']: context['all_votes'] = all_votes context['max_possible_vote'] = settings.DMOJ_PROBLEM_MAX_USER_POINTS_VOTE context['min_possible_vote'] = settings.DMOJ_PROBLEM_MIN_USER_POINTS_VOTE return context