added rank on profile page

This commit is contained in:
Danhia 2021-12-14 21:21:29 +01:00
parent 3d456ea26b
commit be0fc5dd67
2 changed files with 5 additions and 27 deletions

View File

@ -4,32 +4,6 @@
{% load key_value %} {% load key_value %}
<div class="row"> <div class="row">
<div class="col-sm-12 col-md-9"> <div class="col-sm-12 col-md-9">
<div class="d-block d-md-none right-sidebar">
<ul class="list-group">
<li class="list-group-item">{{ user.username }}</li>
<li class="list-group-item">{% trans "Score" %} : {{ user.userprofileinfo.score }}</li>
{% if user.userprofileinfo.portfolio_site %}
<li class="list-group-item">
<a href="{{ user.userprofileinfo.portfolio_site }}" target="_blank">
{{ user.userprofileinfo.portfolio_site }}
</a>
</li>
{% endif %}
<li class="list-group-item">{% trans "Member since" %} {{ user.date_joined|date:"Y-m-d" }}</li>
</ul>
<ul class="list-group">
<li class="list-group-item">{% trans "Categories stats" %}</li>
{% for cat in catsDatas %}
<li class="list-group-item" style="padding-bottom: 3;padding-top: 0;">
<span>{{ cat.0 }}</span>
<div class="progress">
<div class="progress-bar bg-success" role="progressbar" style="width: {{ cat.3 }}%" aria-valuenow="{{ cat.3 }}" aria-valuemin="0" aria-valuemax="100">{{ cat.3 }} %</div>
</div>
</li>
{% endfor %}
</ul>
</div>
<div> <div>
<h4>Challenges Solved by {{ user.username }}</h4> <h4>Challenges Solved by {{ user.username }}</h4>
{% if solves%} {% if solves%}
@ -68,6 +42,7 @@
<ul class="list-group"> <ul class="list-group">
<li class="list-group-item">{{ user.username }}</li> <li class="list-group-item">{{ user.username }}</li>
<li class="list-group-item">{% trans "Score" %} : {{ user.userprofileinfo.score }}</li> <li class="list-group-item">{% trans "Score" %} : {{ user.userprofileinfo.score }}</li>
<li class="list-group-item">{% trans "Rank" %} : {{ rank }}</li>
{% if user.userprofileinfo.portfolio_site %} {% if user.userprofileinfo.portfolio_site %}
<li class="list-group-item"> <li class="list-group-item">
<a href="{{ user.userprofileinfo.portfolio_site }}" target="_blank"> <a href="{{ user.userprofileinfo.portfolio_site }}" target="_blank">

View File

@ -116,6 +116,8 @@ def profile(request, user_name):
catsDatas = [] catsDatas = []
user_obj = get_object_or_404(User, username=user_name) user_obj = get_object_or_404(User, username=user_name)
all_users = list(UserProfileInfo.objects.select_related().order_by('-score', 'last_submission_date', 'user__username'))
rank = all_users.index(get_object_or_404(UserProfileInfo, user=user_obj)) + 1
cats = Category.objects.all() cats = Category.objects.all()
pointDatas = {} pointDatas = {}
@ -141,7 +143,8 @@ def profile(request, user_name):
for s in solves.reverse(): for s in solves.reverse():
somme += s.ctf.points somme += s.ctf.points
solved.append([s.flag_date.timestamp() * 1000,somme]) solved.append([s.flag_date.timestamp() * 1000,somme])
return render(request,'accounts/profile.html', {'user':user_obj, 'solves':solves,'solved':solved,'catsDatas': catsDatas, 'pointDatas': pointDatas})
return render(request,'accounts/profile.html', {'user':user_obj, 'solves':solves,'solved':solved,'catsDatas': catsDatas, 'pointDatas': pointDatas, 'rank': rank})
def rank(request, token): def rank(request, token):
all_users = UserProfileInfo.objects.filter(score__gt=0).select_related().order_by('-score', 'last_submission_date', 'user__username') all_users = UserProfileInfo.objects.filter(score__gt=0).select_related().order_by('-score', 'last_submission_date', 'user__username')