dashboard
This commit is contained in:
parent
b59410c90c
commit
3b58e98815
@ -1,3 +1,9 @@
|
|||||||
|
from random import sample
|
||||||
|
|
||||||
|
from django.db.models import Count, Max
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
|
from Main.models import Task, UserInfo, Solution
|
||||||
from SprintLib.BaseView import BaseView
|
from SprintLib.BaseView import BaseView
|
||||||
|
|
||||||
|
|
||||||
@ -5,3 +11,21 @@ class MainView(BaseView):
|
|||||||
view_file = "main.html"
|
view_file = "main.html"
|
||||||
required_login = True
|
required_login = True
|
||||||
endpoint = ""
|
endpoint = ""
|
||||||
|
|
||||||
|
def get(self):
|
||||||
|
self.context['top_tasks_today'] = Task.objects.filter(public=True, solution__time_sent__date=timezone.now().date()).annotate(count=Count('solution__task_id')).order_by('-count')[:5]
|
||||||
|
if len(self.context['top_tasks_today']) < 5:
|
||||||
|
self.context['top_tasks_today'] = Task.objects.filter(public=True, solution__time_sent__isnull=False).annotate(time_sent=Max('solution__time_sent'), count=Count('solution__task_id')).order_by('-count', '-time_sent')[:5]
|
||||||
|
if len(self.context['top_tasks_today']) < 5:
|
||||||
|
self.context['top_tasks_today'] = Task.objects.filter(public=True).order_by('name')[:5]
|
||||||
|
for task in self.context['top_tasks_today']:
|
||||||
|
setattr(task, 'solution', Solution.objects.filter(user=self.request.user, task=task).first())
|
||||||
|
self.context['top_users'] = UserInfo.objects.filter(verified=True).order_by('-rating')[:5]
|
||||||
|
all_tasks = Task.objects.filter(solution__user=self.request.user).distinct()
|
||||||
|
ok_tasks = all_tasks.filter(solution__result="OK").distinct()
|
||||||
|
undone_tasks = set(all_tasks) - set(ok_tasks)
|
||||||
|
self.context['undone_tasks'] = sample(undone_tasks, k=min(5, len(undone_tasks)))
|
||||||
|
for task in self.context['undone_tasks']:
|
||||||
|
setattr(task, 'solution', Solution.objects.filter(user=self.request.user, task=task).first())
|
||||||
|
new_tasks = set(Task.objects.filter(public=True)) - set(all_tasks)
|
||||||
|
self.context['new_tasks'] = sample(new_tasks, k=min(5, len(new_tasks)))
|
||||||
|
@ -4,4 +4,24 @@
|
|||||||
|
|
||||||
{% block main %}
|
{% block main %}
|
||||||
<h2>Мои группы</h2>
|
<h2>Мои группы</h2>
|
||||||
|
<hr><hr>
|
||||||
|
<h2>Топ задач сегодня</h2>
|
||||||
|
{% for task in top_tasks_today %}
|
||||||
|
<a href="/task?task_id={{ task.id }}">{{ task.name }} ({{ task.count }})</a> <span class="badge badge-{{ task.solution.badge_style }}">{{ task.solution.number_result }}</span><br>
|
||||||
|
{% endfor %}
|
||||||
|
<hr><hr>
|
||||||
|
<h2>У тебя были попытки, попробуй решить задачи еще раз</h2>
|
||||||
|
{% for task in undone_tasks %}
|
||||||
|
<a href="/task?task_id={{ task.id }}">{{ task.name }}</a> <span class="badge badge-{{ task.solution.badge_style }}">{{ task.solution.number_result }}</span><br>
|
||||||
|
{% endfor %}
|
||||||
|
<hr><hr>
|
||||||
|
<h2>Новые задачи</h2>
|
||||||
|
{% for task in new_tasks %}
|
||||||
|
<a href="/task?task_id={{ task.id }}">{{ task.name }}</a><br>
|
||||||
|
{% endfor %}
|
||||||
|
<hr><hr>
|
||||||
|
<h2>Топ пользователей</h2>
|
||||||
|
{% for u in top_users %}
|
||||||
|
<a href="/account?username={{ u.user.username }}">{{ u.place }}. <img src="{{ u.profile_pic_url }}" width="50px" height="50px" style="border-radius: 50%; margin-right: 10px;">{{ u.user.username }} ({{ u.rating }})</a><br><br>
|
||||||
|
{% endfor %}
|
||||||
{% endblock %}
|
{% endblock %}
|
Loading…
Reference in New Issue
Block a user