diff --git a/src/home/templates/home/home.html b/src/home/templates/home/home.html index a1be62d..a8b825a 100644 --- a/src/home/templates/home/home.html +++ b/src/home/templates/home/home.html @@ -4,7 +4,30 @@ {% get_current_language as lang %} {% load is_member %}
-
+ +
{% if news %} {% for n in news %}
@@ -33,30 +56,42 @@

{% trans "No article available." %}

{% endif %}
- diff --git a/src/home/views.py b/src/home/views.py index 8960df3..32c2444 100644 --- a/src/home/views.py +++ b/src/home/views.py @@ -8,6 +8,9 @@ from django.urls import translate_url from django.utils.translation import ( LANGUAGE_SESSION_KEY, check_for_language, get_language, ) +import datetime +from collections import defaultdict +import operator def get_content_by_lang(news): lang = get_language() @@ -22,6 +25,19 @@ def get_content_by_lang(news): ret = news.content_ru return ret +def get_weekly_top(): + week_ago = datetime.datetime.now() - datetime.timedelta(days=7) + weekly_flags = CTF_flags.objects.filter(flag_date__gt=week_ago) + scores = defaultdict(int) + + for sol in weekly_flags: + scores[sol.user] += sol.ctf.points + + users = sorted(scores.items(), key=operator.itemgetter(1), reverse=True) + users = [(u[0].userprofileinfo, u[1]) for u in users] + + return(users[:5]) + def home(request): lang_code = get_language() if hasattr(request, 'session') and LANGUAGE_SESSION_KEY in request.session: @@ -36,7 +52,11 @@ def home(request): top10 = UserProfileInfo.objects.select_related().order_by('-score', 'last_submission_date', 'user__username')[:10] nb_flags = CTF_flags.objects.count() nb_users = UserProfileInfo.objects.count() - return render(request, 'home/home.html', {'news' : news, 'ctfs' : latest_ctfs, 'top' : top10, 'flags' : nb_flags}) + latest_flags = CTF_flags.objects.order_by('-flag_date')[:5] + top_weekly = get_weekly_top() + + return render(request, 'home/home.html', {'news' : news, 'ctfs' : latest_ctfs, 'top' : top10, 'flags' : nb_flags, + 'latest_flags':latest_flags, 'top_weekly': top_weekly, 'nb_users': nb_users}) def cgu(request): return render(request, 'cgu.html') diff --git a/src/statics/css/style.css b/src/statics/css/style.css index f8df0ab..ca69b8d 100644 --- a/src/statics/css/style.css +++ b/src/statics/css/style.css @@ -361,4 +361,15 @@ footer { } .is-member { color: #2b908f; +} + +@media only screen and (min-width : 1200px) { + .container { max-width: 1400px; } +} + +@media screen and (max-width: 991px) { + .container { display: flex; flex-flow: column; } + .top-sm { order: 1; } + .middle-sm { order: 2; } + .bottom-sm { order: 3 } } \ No newline at end of file