def visible_messages(request, author=None, category=None, kind=None): rounds_ids = [round.id for round in visible_rounds(request)] q_expression = Q(round_id__in=rounds_ids) if author: q_expression = q_expression & Q(author=author) if category: # pylint: disable=unpacking-non-sequence category_type, category_id = category if category_type == 'p': q_expression = q_expression & Q(problem_instance__id=category_id) elif category_type == 'r': q_expression = q_expression & Q(round__id=category_id, problem_instance=None) if kind: q_expression = q_expression & Q(kind=kind) messages = Message.objects.filter(q_expression).order_by('-date') if not is_contest_admin(request): q_expression = Q(kind='PUBLIC') if request.user.is_authenticated: q_expression = q_expression \ | (Q(author=request.user) & Q(kind='QUESTION')) \ | Q(top_reference__author=request.user) q_time = Q(date__lte=request.timestamp) \ & ((Q(pub_date__isnull=True) | Q(pub_date__lte=request.timestamp))) \ & ((Q(top_reference__isnull=True)) | Q(top_reference__pub_date__isnull=True) | Q(top_reference__pub_date__lte=request.timestamp)) messages = messages.filter(q_expression, q_time) return messages.select_related('top_reference', 'author', 'problem_instance', 'problem_instance__problem')
def visible_messages(request, author=None, category=None, kind=None): rounds_ids = [round.id for round in visible_rounds(request)] q_expression = Q(round_id__in=rounds_ids) if author: q_expression = q_expression & Q(author=author) if category: # pylint: disable=unpacking-non-sequence category_type, category_id = category if category_type == 'p': q_expression = q_expression & Q(problem_instance__id=category_id) elif category_type == 'r': q_expression = q_expression & Q(round__id=category_id, problem_instance=None) if kind: q_expression = q_expression & Q(kind=kind) messages = Message.objects.filter(q_expression).order_by('-date') if not is_contest_basicadmin(request): q_expression = Q(kind='PUBLIC') if request.user.is_authenticated: q_expression = q_expression \ | (Q(author=request.user) & Q(kind='QUESTION')) \ | Q(top_reference__author=request.user) q_time = Q(date__lte=request.timestamp) \ & ((Q(pub_date__isnull=True) | Q(pub_date__lte=request.timestamp))) \ & ((Q(top_reference__isnull=True)) | Q(top_reference__pub_date__isnull=True) | Q(top_reference__pub_date__lte=request.timestamp)) messages = messages.filter(q_expression, q_time) return messages.select_related('top_reference', 'author', 'problem_instance', 'problem_instance__problem')
def contest_files_view(request): contest_files = ContestAttachment.objects.filter(contest=request.contest) \ .filter(Q(round__isnull=True) | Q(round__in=visible_rounds(request))) \ .select_related('round') round_file_exists = contest_files.filter(round__isnull=False).exists() problem_instances = visible_problem_instances(request) problem_ids = [pi.problem_id for pi in problem_instances] problem_files = ProblemAttachment.objects \ .filter(problem_id__in=problem_ids) \ .select_related('problem') add_category_field = round_file_exists or problem_files.exists() rows = [{ 'category': cf.round if cf.round else '', 'name': cf.filename, 'description': cf.description, 'link': reverse('contest_attachment', kwargs={'contest_id': request.contest.id, 'attachment_id': cf.id}), } for cf in contest_files] rows += [{ 'category': pf.problem, 'name': pf.filename, 'description': pf.description, 'link': reverse('problem_attachment', kwargs={'contest_id': request.contest.id, 'attachment_id': pf.id}), } for pf in problem_files] rows.sort(key=itemgetter('name')) return TemplateResponse(request, 'contests/files.html', {'files': rows, 'files_on_page': getattr(settings, 'FILES_ON_PAGE', 100), 'add_category_field': add_category_field})
def contest_files_view(request): contest_files = ContestAttachment.objects.filter(contest=request.contest) \ .filter(Q(round__isnull=True) | Q(round__in=visible_rounds(request))) \ .select_related('round') if not is_contest_admin(request): contest_files = contest_files.filter(Q(pub_date__isnull=True) | Q(pub_date__lte=request.timestamp)) round_file_exists = contest_files.filter(round__isnull=False).exists() problem_instances = visible_problem_instances(request) problem_ids = [pi.problem_id for pi in problem_instances] problem_files = ProblemAttachment.objects \ .filter(problem_id__in=problem_ids) \ .select_related('problem') add_category_field = round_file_exists or problem_files.exists() rows = [{ 'category': cf.round if cf.round else '', 'name': cf.download_name, 'description': cf.description, 'link': reverse('contest_attachment', kwargs={'contest_id': request.contest.id, 'attachment_id': cf.id}), 'pub_date': cf.pub_date } for cf in contest_files] rows += [{ 'category': pf.problem, 'name': pf.download_name, 'description': pf.description, 'link': reverse('problem_attachment', kwargs={'contest_id': request.contest.id, 'attachment_id': pf.id}), 'pub_date': None } for pf in problem_files] rows.sort(key=itemgetter('name')) return TemplateResponse(request, 'contests/files.html', {'files': rows, 'files_on_page': getattr(settings, 'FILES_ON_PAGE', 100), 'add_category_field': add_category_field, 'show_pub_dates': True})
def contest_attachment_view(request, contest_id, attachment_id): attachment = get_object_or_404(ContestAttachment, contest_id=contest_id, id=attachment_id) if attachment.round and attachment.round not in visible_rounds(request): raise PermissionDenied return stream_file(attachment.content)
def contest_attachment_view(request, attachment_id): attachment = get_object_or_404(ContestAttachment, contest_id=request.contest.id, id=attachment_id) if (attachment.round and attachment.round not in visible_rounds(request)) or \ (not is_contest_basicadmin(request) and attachment.pub_date and attachment.pub_date > request.timestamp): raise PermissionDenied return stream_file(attachment.content, attachment.download_name)
def contest_attachment_view(request, attachment_id): attachment = get_object_or_404(ContestAttachment, contest_id=request.contest.id, id=attachment_id) if (attachment.round and attachment.round not in visible_rounds(request)) or \ (not is_contest_admin(request) and attachment.pub_date and attachment.pub_date > request.timestamp): raise PermissionDenied return stream_file(attachment.content, attachment.download_name)
def visible_messages(request, author=None, category=None): rounds_ids = [round.id for round in visible_rounds(request)] q_expression = Q(round_id__in=rounds_ids) if author: q_expression = q_expression & Q(author=author) if category: category_type, category_id = category if category_type == "p": q_expression = q_expression & Q(problem_instance__id=category_id) elif category_type == "r": q_expression = q_expression & Q(round__id=category_id, problem_instance=None) messages = Message.objects.filter(q_expression).order_by("-date") if not is_contest_admin(request): q_expression = Q(kind="PUBLIC") if request.user.is_authenticated(): q_expression = ( q_expression | (Q(author=request.user) & Q(kind="QUESTION")) | Q(top_reference__author=request.user) ) messages = messages.filter(q_expression, date__lte=request.timestamp) return messages.select_related("top_reference", "author", "problem_instance", "problem_instance__problem")
def visible_messages(request, author=None, category=None): rounds_ids = [round.id for round in visible_rounds(request)] q_expression = Q(round_id__in=rounds_ids) if author: q_expression = q_expression & Q(author=author) if category: category_type, category_id = category if category_type == 'p': q_expression = q_expression & Q(problem_instance__id=category_id) elif category_type == 'r': q_expression = q_expression & Q(round__id=category_id, problem_instance=None) messages = Message.objects.filter(q_expression).order_by('-date') if not is_contest_admin(request): q_expression = Q(kind='PUBLIC') if request.user.is_authenticated(): q_expression = q_expression \ | (Q(author=request.user) & Q(kind='QUESTION')) \ | Q(top_reference__author=request.user) messages = messages.filter(q_expression, date__lte=request.timestamp) return messages.select_related('top_reference', 'author', 'problem_instance', 'problem_instance__problem')
def get_categories(request): categories = [('p_%d' % (pi.id,), _("Problem %s") % (pi.problem.name,)) for pi in visible_problem_instances(request)] categories += [('r_%d' % (round.id,), _("General, %s") % (round.name,)) for round in visible_rounds(request)] return categories
def get_categories(request): categories = [('p_%d' % (pi.id, ), _("Problem %s") % (pi.problem.name, )) for pi in visible_problem_instances(request)] categories += [('r_%d' % (round.id, ), _("General, %s") % (round.name, )) for round in visible_rounds(request)] return categories
def contest_attachment_view(request, attachment_id): attachment = get_object_or_404(ContestAttachment, contest_id=request.contest.id, id=attachment_id) if attachment.round and attachment.round not in visible_rounds(request): raise PermissionDenied return stream_file(attachment.content)