Paginate contest summary
This commit is contained in:
parent
77b441eb5e
commit
159b2b4cc0
3 changed files with 68 additions and 46 deletions
|
@ -518,9 +518,8 @@ urlpatterns = [
|
||||||
),
|
),
|
||||||
url(r"^contests/", paged_list_view(contests.ContestList, "contest_list")),
|
url(r"^contests/", paged_list_view(contests.ContestList, "contest_list")),
|
||||||
url(
|
url(
|
||||||
r"^contests/summary/(?P<key>\w+)$",
|
r"^contests/summary/(?P<key>\w+)/",
|
||||||
contests.contests_summary_view,
|
paged_list_view(contests.ContestsSummaryView, "contests_summary"),
|
||||||
name="contests_summary",
|
|
||||||
),
|
),
|
||||||
url(r"^course/", paged_list_view(course.CourseList, "course_list")),
|
url(r"^course/", paged_list_view(course.CourseList, "course_list")),
|
||||||
url(
|
url(
|
||||||
|
|
|
@ -1426,16 +1426,23 @@ ContestsSummaryData = namedtuple(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def contests_summary_view(request, key):
|
class ContestsSummaryView(DiggPaginatorMixin, ListView):
|
||||||
|
paginate_by = 50
|
||||||
|
template_name = "contest/contests_summary.html"
|
||||||
|
|
||||||
|
def get(self, *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
contests_summary = ContestsSummary.objects.get(key=key)
|
self.contests_summary = ContestsSummary.objects.get(key=kwargs["key"])
|
||||||
except:
|
except:
|
||||||
raise Http404()
|
raise Http404()
|
||||||
|
return super().get(*args, **kwargs)
|
||||||
|
|
||||||
cache_key = "csv:" + key
|
def _get_contests_and_ranking(self):
|
||||||
context = cache.get(cache_key)
|
contests_summary = self.contests_summary
|
||||||
if context:
|
cache_key = "csv:" + contests_summary.key
|
||||||
return render(request, "contest/contests_summary.html", context)
|
result = cache.get(cache_key)
|
||||||
|
if result:
|
||||||
|
return result
|
||||||
|
|
||||||
scores_system = contests_summary.scores
|
scores_system = contests_summary.scores
|
||||||
contests = contests_summary.contests.all()
|
contests = contests_summary.contests.all()
|
||||||
|
@ -1445,7 +1452,7 @@ def contests_summary_view(request, key):
|
||||||
|
|
||||||
for i in range(len(contests)):
|
for i in range(len(contests)):
|
||||||
contest = contests[i]
|
contest = contests[i]
|
||||||
users, problems = get_contest_ranking_list(request, contest)
|
users, problems = get_contest_ranking_list(self.request, contest)
|
||||||
for rank, user in users:
|
for rank, user in users:
|
||||||
curr_score = 0
|
curr_score = 0
|
||||||
if rank - 1 < len(scores_system):
|
if rank - 1 < len(scores_system):
|
||||||
|
@ -1467,14 +1474,25 @@ def contests_summary_view(request, key):
|
||||||
sorted_total_points.sort(key=lambda x: x.points, reverse=True)
|
sorted_total_points.sort(key=lambda x: x.points, reverse=True)
|
||||||
total_rank = ranker(sorted_total_points)
|
total_rank = ranker(sorted_total_points)
|
||||||
|
|
||||||
context = {
|
result = {
|
||||||
"total_rank": list(total_rank),
|
"total_rank": list(total_rank),
|
||||||
"title": _("Contests Summary"),
|
|
||||||
"contests": contests,
|
"contests": contests,
|
||||||
}
|
}
|
||||||
cache.set(cache_key, context)
|
cache.set(cache_key, result)
|
||||||
|
return result
|
||||||
|
|
||||||
return render(request, "contest/contests_summary.html", context)
|
def get_queryset(self):
|
||||||
|
rank_and_contests = self._get_contests_and_ranking()
|
||||||
|
total_rank = rank_and_contests["total_rank"]
|
||||||
|
self.contests = rank_and_contests["contests"]
|
||||||
|
return total_rank
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = super().get_context_data(**kwargs)
|
||||||
|
context["contests"] = self.contests
|
||||||
|
context["title"] = _("Contests")
|
||||||
|
context["first_page_href"] = "."
|
||||||
|
return context
|
||||||
|
|
||||||
|
|
||||||
@receiver([post_save, post_delete], sender=ContestsSummary)
|
@receiver([post_save, post_delete], sender=ContestsSummary)
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for rank, item in total_rank %}
|
{% for rank, item in page_obj %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
{{ rank }}
|
{{ rank }}
|
||||||
|
@ -68,4 +68,9 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
{% if page_obj and page_obj.num_pages > 1 %}
|
||||||
|
<div style="margin-top: 10px;">
|
||||||
|
{% include "list-pages.html" %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Loading…
Reference in a new issue