def filter(request, id, type, page="1"): user = get_object_or_404(User, id=id) actions = Activity.objects.filter(actor=user, type=type).order_by("-timestamp") if not request.user.is_superuser: actions = actions.exclude(admin_only=True) pagination = setup_paginator(actions, page, "newsfeed-filter", {'id': id, 'type': type}) return render(request, "newsfeed.html", {"pagination": pagination})
def by_user(request, id, page="1"): user = get_object_or_404(User, id=id) actions = Activity.objects.filter(actor=user).order_by("-timestamp") return render(request, "newsfeed.html", {"pagination": setup_paginator(actions, page, "newsfeed-byuser", {'id': id})})
def stream(request, page="1"): actions = Activity.objects.exclude(category='solved').order_by("-timestamp") if not request.user.is_superuser: actions = actions.exclude(admin_only=True) return render(request, "newsfeed.html", {"pagination": setup_paginator(actions, page, "newsfeed", {})})
def stat(request, slug, page=1): problem = get_object_or_404(Problem, slug=slug) checker = ObjectPermissionChecker(request.user) if (problem.state != Problem.PUBLISHED and not checker.has_perm('read_problem', problem) and problem.user != request.user): raise Http404 submissions = Submission.objects.filter(problem=problem) verdict_chart = Submission.get_verdict_distribution_graph(submissions) incorrect_tries_chart = Solver.get_incorrect_tries_chart(problem) solvers = Solver.objects.filter(problem=problem, solved=True) order_by = request.GET.get('order_by', 'shortest') if order_by.endswith('fastest'): solvers = solvers.order_by(order_by + '_submission__time') elif order_by.endswith('shortest'): solvers = solvers.order_by(order_by + '_submission__length') else: solvers = solvers.order_by(order_by) pagination = setup_paginator(solvers, page, 'judge-problem-stat', {'slug': slug}, request.GET) title = problem.slug + u': 해결한 사람들' return render( request, "problem/stat.html", { 'title': title, 'problem': problem, 'editable': checker.has_perm('edit_problem', problem), 'verdict_chart': verdict_chart, 'incorrects_chart': incorrect_tries_chart, 'pagination': pagination, })
def stat(request, slug, page=1): problem = get_object_or_404(Problem, slug=slug) submissions = Submission.objects.filter(problem=problem) verdict_chart = Submission.get_verdict_distribution_graph(submissions) incorrect_tries_chart = Solver.get_incorrect_tries_chart(problem) solvers = Solver.objects.filter(problem=problem, solved=True) order_by = request.GET.get("order_by", "shortest") if order_by.endswith("fastest"): solvers = solvers.order_by(order_by + "_submission__time") elif order_by.endswith("shortest"): solvers = solvers.order_by(order_by + "_submission__length") else: solvers = solvers.order_by(order_by) pagination = setup_paginator(solvers, page, "judge-problem-stat", {"slug": slug}, request.GET) title = problem.slug + u": 해결한 사람들" return render( request, "problem/stat.html", { "title": title, "problem": problem, "verdict_chart": verdict_chart, "incorrects_chart": incorrect_tries_chart, "pagination": pagination, }, )
def recent(request, page=1): checker = ObjectPermissionChecker(request.user) submissions = Submission.objects.all().order_by("-id") filters = {} empty_message = u"제출된 답안이 없습니다." title_add = [] # only superuser can see all nonpublic submissions. # as an exception, if we are filtering by a problem, the author can see # nonpublic submissions. also, everybody can see their nonpublic # submissions. only_public = not request.user.is_superuser if request.GET.get("problem"): slug = request.GET["problem"] problem = get_object_or_404(Problem, slug=slug) if request.user == problem.user or checker.has_perm('read_problem', problem): only_public = False if (problem.state != Problem.PUBLISHED and request.user != problem.user and not checker.has_perm('read_problem', problem)): raise Http404 submissions = submissions.filter(problem=problem) title_add.append(slug) filters["problem"] = slug if "state" in request.GET: state = request.GET["state"] submissions = submissions.filter(state=state) filters["state"] = state title_add.append(Submission.STATES_KOR[int(state)]) if request.GET.get("user"): username = request.GET["user"] user = get_or_none(User, username=username) if not user: empty_message = u"해당 사용자가 없습니다." submissions = submissions.none() else: submissions = submissions.filter(user=user) filters["user"] = username title_add.append(username) if user == request.user: only_public = False if only_public: submissions = submissions.filter(is_public=True) return render(request, "submission/recent.html", {"title": u"답안 목록" + (": " if title_add else "") + ",".join(title_add), "filters": filters, "empty_message": empty_message, "pagination": setup_paginator(submissions, page, "judge-submission-recent", {}, filters)})
def stat(request, slug, page=1): problem = get_object_or_404(Problem, slug=slug) checker = ObjectPermissionChecker(request.user) if (problem.state != Problem.PUBLISHED and not checker.has_perm('read_problem', problem) and problem.user != request.user): raise Http404 submissions = Submission.objects.filter(problem=problem) verdict_chart = Submission.get_verdict_distribution_graph(submissions) incorrect_tries_chart = Solver.get_incorrect_tries_chart(problem) solvers = Solver.objects.filter(problem=problem, solved=True) order_by = request.GET.get('order_by', 'shortest') if order_by.endswith('fastest'): solvers = solvers.order_by(order_by + '_submission__time') elif order_by.endswith('shortest'): solvers = solvers.order_by(order_by + '_submission__length') else: solvers = solvers.order_by(order_by) pagination = setup_paginator(solvers, page, 'judge-problem-stat', {'slug': slug}, request.GET) title = problem.slug + u': 해결한 사람들' return render(request, "problem/stat.html", {'title': title, 'problem': problem, 'editable': checker.has_perm('edit_problem', problem), 'verdict_chart': verdict_chart, 'incorrects_chart': incorrect_tries_chart, 'pagination': pagination, })
def all(request, page=1): posts = get_posts_for_user(request.user, 'forum.read_post').order_by("-id") write_category = get_object_or_404(Category, slug='free') return render(request, "list.html", {"show_category": True, 'write_at': write_category.slug, "title": u"모든 글 보기", "pagination": setup_paginator(posts, page, "forum-all", {})})
def stream(request, page="1"): actions = get_activities_for_user( request.user).exclude(category='solved').order_by("-timestamp") print actions.query return render( request, "newsfeed.html", {"pagination": setup_paginator(actions, page, "newsfeed", {})})
def all(request, page=1): category = get_object_or_404(Category, slug='free') posts = Post.objects.order_by("-id") return render(request, "list.html", {"show_category": True, 'write_at': category.slug, "title": u"모든 글 보기", "pagination": setup_paginator(posts, page, "forum-all", {})})
def filter(request, id, type, page="1"): user = get_object_or_404(User, id=id) actions = get_activities_for_user(request.user).filter( actor=user, type=type).order_by("-timestamp") pagination = setup_paginator(actions, page, "newsfeed-filter", { 'id': id, 'type': type }) return render(request, "newsfeed.html", {"pagination": pagination})
def list(request, slug, page=1): category = get_object_or_404(Category, slug=slug) posts = Post.objects.filter(category=category).order_by("-id") return render(request, "list.html", {"write_at": category.slug, "title": category.name, "category": category, "pagination": setup_paginator(posts, page, "forum-list", {"slug": category.slug})})
def by_user(request, id, page="1"): user = get_object_or_404(User, id=id) actions = get_activities_for_user( request.user).filter(actor=user).order_by("-timestamp") return render( request, "newsfeed.html", { "pagination": setup_paginator(actions, page, "newsfeed-byuser", {'id': id}) })
def all(request, page=1): posts = get_posts_for_user(request.user, 'forum.read_post').order_by("-id") write_category = get_object_or_404(Category, slug='free') return render( request, "list.html", { "show_category": True, 'write_at': write_category.slug, "title": u"모든 글 보기", "pagination": setup_paginator(posts, page, "forum-all", {}) })
def by_user(request, id, page=1): user = get_object_or_404(User, id=id) posts = get_posts_for_user( request.user, 'forum.read_post').filter(user=user).order_by("-id") return render( request, "by_user.html", { "filter_user": user, "pagination": setup_paginator(posts, page, "forum-byuser", {"id": user.id}) })
def list(request, slug, page=1): checker = ObjectPermissionChecker(request.user) category = get_object_or_404(Category, slug=slug) if not checker.has_perm('read_post', category): return HttpResponseForbidden("Restricted category") posts = Post.objects.filter(category=category).order_by("-id") return render(request, "list.html", {"write_at": category.slug if checker.has_perm('write_post', category) else None, "title": category.name, "category": category, "pagination": setup_paginator(posts, page, "forum-list", {"slug": category.slug})})
def ranking(request, page=1): profiles = UserProfile.objects.filter(submissions__gt=0) profiles = profiles.annotate(Count("user__problem")) profiles = profiles.extra(select={"ratio": "accepted / submissions"}) order_by = request.GET.get("order_by", "solved") order_by_translate = {"solved": "-solved_problems", "authored": "-user__problem__count", "ratio": "-ratio"} profiles = profiles.order_by(order_by_translate[order_by]) return render( request, "ranking.html", {"title": u"사용자 랭킹", "pagination": setup_paginator(profiles, page, "judge-ranking", {}, request.GET)}, )
def ranking(request, page=1): profiles = UserProfile.objects.filter(submissions__gt=0) profiles = profiles.annotate(Count('user__problem')) profiles = profiles.extra(select={'ratio': '1.0 * accepted / submissions'}) order_by = request.GET.get('order_by', 'solved') order_by_translate = {'solved': '-solved_problems', 'authored': '-user__problem__count', 'ratio': '-ratio'} profiles = profiles.order_by(order_by_translate[order_by]) return render(request, "ranking.html", {"title": u'사용자 랭킹', "pagination": setup_paginator(profiles, page, "judge-ranking", {}, request.GET)})
def my_problems(request, page=1): readable_problems = get_objects_for_user(request.user, 'read_problem', Problem) my_problems = Problem.objects.filter(user=request.user) problems = (readable_problems | my_problems).exclude(state=Problem.PUBLISHED) title = u'준비 중인 문제들' order_by = request.GET.get("order_by", 'slug') problems = problems.annotate(Count('solver')) if order_by.lstrip('-') in ('slug', 'name', 'state'): problems = problems.order_by(order_by) else: assert order_by.endswith('user') problems = problems.order_by(order_by + '__username') return render(request, 'problem/mine.html', {'title': title, 'pagination': setup_paginator(problems, page, 'judge-problem-mine', {})})
def list(request, slug, page=1): checker = ObjectPermissionChecker(request.user) category = get_object_or_404(Category, slug=slug) if not checker.has_perm('read_post', category): return HttpResponseForbidden("Restricted category") posts = Post.objects.filter(category=category).order_by("-id") return render( request, "list.html", { "write_at": category.slug if checker.has_perm('write_post', category) else None, "title": category.name, "category": category, "pagination": setup_paginator(posts, page, "forum-list", {"slug": category.slug}) })
def my_problems(request, page=1): problems = Problem.objects.exclude(state=Problem.PUBLISHED) if not request.user.is_superuser: title = u"내가 낸 문제들" problems = problems.filter(user=request.user) else: title = u"준비 중인 문제들" order_by = request.GET.get("order_by", "slug") problems = problems.annotate(Count("solver")) if order_by.lstrip("-") in ("slug", "name", "state"): problems = problems.order_by(order_by) else: assert order_by.endswith("user") problems = problems.order_by(order_by + "__username") return render( request, "problem/mine.html", {"title": title, "pagination": setup_paginator(problems, page, "judge-problem-mine", {})}, )
def my_problems(request, page=1): readable_problems = get_objects_for_user(request.user, 'read_problem', Problem) my_problems = Problem.objects.filter(user=request.user) problems = (readable_problems | my_problems).exclude(state=Problem.PUBLISHED) title = u'준비 중인 문제들' order_by = request.GET.get("order_by", 'slug') problems = problems.annotate(Count('solver')) if order_by.lstrip('-') in ('slug', 'name', 'state'): problems = problems.order_by(order_by) else: assert order_by.endswith('user') problems = problems.order_by(order_by + '__username') return render( request, 'problem/mine.html', { 'title': title, 'pagination': setup_paginator(problems, page, 'judge-problem-mine', {}) })
def stat(request, slug, page=1): problem = get_object_or_404(Problem, slug=slug) submissions = Submission.objects.filter(problem=problem) verdict_chart = Submission.get_verdict_distribution_graph(submissions) incorrect_tries_chart = Solver.get_incorrect_tries_chart(problem) solvers = Solver.objects.filter(problem=problem, solved=True) order_by = request.GET.get('order_by', 'shortest') if order_by.endswith('fastest'): solvers = solvers.order_by(order_by + '_submission__time') elif order_by.endswith('shortest'): solvers = solvers.order_by(order_by + '_submission__length') else: solvers = solvers.order_by(order_by) pagination = setup_paginator(solvers, page, 'judge-problem-stat', {'slug': slug}, request.GET) title = problem.slug + u': 해결한 사람들' return render(request, "problem/stat.html", {'title': title, 'problem': problem, 'verdict_chart': verdict_chart, 'incorrects_chart': incorrect_tries_chart, 'pagination': pagination, })
def stream(request, page="1"): actions = get_activities_for_user(request.user).exclude(category='solved').order_by("-timestamp") print actions.query return render(request, "newsfeed.html", {"pagination": setup_paginator(actions, page, "newsfeed", {})})
def list(request, page=1): use_filter = True filters = {} title_options = [] problems = Problem.objects.filter(state=Problem.PUBLISHED) if request.GET.get("tag"): tag = filters["tag"] = request.GET["tag"] problems = Problem.tagged.with_all([tag]) title_options.append(tag) if request.GET.get("source"): source = filters["source"] = request.GET["source"] problems = problems.filter(source=source) title_options.append(source) if request.GET.get("author"): filters["author"] = request.GET["author"] author = get_object_or_404(User, username=filters["author"]) problems = problems.filter(user=author) title_options.append(author.username) if title_options: title = u"문제 목록: " + u", ".join(title_options) else: title = u"문제 목록 보기" if request.GET.get('user_tried'): use_filter = False id = request.GET.get('user_tried') user = get_object_or_404(User, id=id) verdict = request.GET.get('verdict') if verdict == 'solved': title = user.username + u': 해결한 문제들' problems = problems.filter(solver__user=user, solver__solved=True) elif verdict == 'failed': title = user.username + u': 실패한 문제들' problems = problems.filter(solver__user=user, solver__solved=False) elif verdict == 'notyet': title = user.username + u': 시도하지 않은 문제들' problems = problems.exclude(solver__user=user) else: title = user.username + u': 시도한 문제들' problems = problems.filter(solver__user=user) order_by = request.GET.get('order_by', 'slug') if order_by.endswith('ratio'): ratio_def = ('cast("judge_problem"."accepted_count" as float) / ' 'greatest(1, "judge_problem"."submissions_count")') problems = problems.extra(select={'ratio': ratio_def}) if order_by.endswith('user'): problems = problems.order_by(order_by + '__username') else: problems = problems.order_by(order_by) # options = {} # TODO: 카테고리별 문제 보기 # TODO: 난이도 순으로 정렬하기 sources = sorted([ entry["source"] for entry in Problem.objects.values("source").distinct() ]) authors = sorted([ User.objects.get(id=entry["user"]).username for entry in Problem.objects.values("user").distinct() ]) tags = sorted([tag.name for tag in Problem.tags.all()]) get_params = '&'.join(k + '=' + v for k, v in request.GET.items()) return render( request, "problem/list.html", { "title": title, "sources": sources, "authors": authors, "tags": tags, "use_filter": use_filter, "filters": filters, "get_params": get_params, "pagination": setup_paginator(problems, page, "judge-problem-list", {}, request.GET) })
def stream(request, page="1"): actions = Activity.objects.order_by("-timestamp") return render(request, "newsfeed.html", {"pagination": setup_paginator(actions, page, "newsfeed", {})})
def by_user(request, id, page=1): user = get_object_or_404(User, id=id) posts = get_posts_for_user(request.user, 'forum.read_post').filter(user=user).order_by("-id") return render(request, "by_user.html", {"filter_user": user, "pagination": setup_paginator(posts, page, "forum-byuser", {"id": user.id})})
def list(request, page=1): use_filter = True filters = {} title_options = [] problems = Problem.objects.filter(state=Problem.PUBLISHED) if request.GET.get("tag"): tag = filters["tag"] = request.GET["tag"] problems = Problem.tagged.with_all([tag]) title_options.append(tag) if request.GET.get("source"): source = filters["source"] = request.GET["source"] problems = problems.filter(source=source) title_options.append(source) if request.GET.get("author"): filters["author"] = request.GET["author"] author = get_object_or_404(User, username=filters["author"]) problems = problems.filter(user=author) title_options.append(author.username) if title_options: title = u"문제 목록: " + u", ".join(title_options) else: title = u"문제 목록 보기" if request.GET.get('user_tried'): use_filter = False id = request.GET.get('user_tried') user = get_object_or_404(User, id=id) verdict = request.GET.get('verdict') if verdict == 'solved': title = user.username + u': 해결한 문제들' problems = problems.filter(solver__user=user, solver__solved=True) elif verdict == 'failed': title = user.username + u': 실패한 문제들' problems = problems.filter(solver__user=user, solver__solved=False) elif verdict == 'notyet': title = user.username + u': 시도하지 않은 문제들' problems = problems.exclude(solver__user=user) else: title = user.username + u': 시도한 문제들' problems = problems.filter(solver__user=user) order_by = request.GET.get('order_by', 'slug') if order_by.endswith('ratio'): ratio_def = ('cast("judge_problem"."accepted_count" as float) / ' 'greatest(1, "judge_problem"."submissions_count")') problems = problems.extra(select={'ratio': ratio_def}) if order_by.endswith('user'): problems = problems.order_by(order_by + '__username') else: problems = problems.order_by(order_by) # options = {} # TODO: 카테고리별 문제 보기 # TODO: 난이도 순으로 정렬하기 sources = sorted([entry["source"] for entry in Problem.objects.values("source").distinct()]) authors = sorted([User.objects.get(id=entry["user"]).username for entry in Problem.objects.values("user").distinct()]) tags = sorted([tag.name for tag in Problem.tags.all()]) get_params = '&'.join(k + '=' + v for k, v in request.GET.items()) return render(request, "problem/list.html", {"title": title, "sources": sources, "authors": authors, "tags": tags, "use_filter": use_filter, "filters": filters, "get_params": get_params, "pagination": setup_paginator(problems, page, "judge-problem-list", {}, request.GET)})
def filter(request, id, type, page="1"): user = get_object_or_404(User, id=id) actions = Activity.objects.filter(actor=user, type=type).order_by("-timestamp") pagination = setup_paginator(actions, page, "newsfeed-filter", {'id': id, 'type': type}) return render(request, "newsfeed.html", {"pagination": pagination})
def recent(request, page=1): checker = ObjectPermissionChecker(request.user) submissions = Submission.objects.all().order_by("-id") filters = {} empty_message = u"제출된 답안이 없습니다." title_add = [] # only superuser can see all nonpublic submissions. # as an exception, if we are filtering by a problem, the author can see # nonpublic submissions. also, everybody can see their nonpublic # submissions. only_public = not request.user.is_superuser if request.GET.get("problem"): slug = request.GET["problem"] problem = get_object_or_404(Problem, slug=slug) if request.user == problem.user or checker.has_perm( 'read_problem', problem): only_public = False if (problem.state != Problem.PUBLISHED and request.user != problem.user and not checker.has_perm('read_problem', problem)): raise Http404 submissions = submissions.filter(problem=problem) title_add.append(slug) filters["problem"] = slug if "state" in request.GET: state = request.GET["state"] submissions = submissions.filter(state=state) filters["state"] = state title_add.append(Submission.STATES_KOR[int(state)]) if request.GET.get("user"): username = request.GET["user"] user = get_or_none(User, username=username) if not user: empty_message = u"해당 사용자가 없습니다." submissions = submissions.none() else: submissions = submissions.filter(user=user) filters["user"] = username title_add.append(username) if user == request.user: only_public = False if only_public: submissions = submissions.filter(is_public=True) problems = Problem.objects.filter(state=Problem.PUBLISHED).order_by("slug") users = User.objects.order_by("username") return render( request, "submission/recent.html", { "title": u"답안 목록" + (": " if title_add else "") + ",".join(title_add), "problems": problems, "users": users, "filters": filters, "empty_message": empty_message, "pagination": setup_paginator(submissions, page, "judge-submission-recent", {}, filters) })