Skip to content

Commit

Permalink
feat: move ranked displays to table for easier reading
Browse files Browse the repository at this point in the history
  • Loading branch information
BrennanB committed Oct 24, 2024
1 parent 7018667 commit 78afa17
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 81 deletions.
158 changes: 79 additions & 79 deletions home/templates/home/user_profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,36 @@ <h5>{{user.username}}#{{user.discriminator}}</h5>
</div>
</div>

{% if elos|length > 0 %}

<div class="row">
<div
class="position-relative overflow-hidden p-md-3 m-md-3 shadowy text-center bg-secondary"
>
<h2>Ranked</h2>
</div>

{% for elo in elos %}
<div class="col-4">
<div
class="position-relative overflow-hidden p-3 p-md-3 shadowy m-md-3 text-center bg-dark"
>
<h3>
<a
href="/ranked/{{elo.game_mode.short_code}}/"
style="color: #fff; text-decoration: none"
>{{elo.game_mode}}</a
>
</h3>
<h5>{{elo.elo|floatformat:1}}</h5>
<h5>
{{elo.matches_won}}-{{elo.matches_lost}}-{{elo.matches_drawn}}
</h5>
{% if elos_by_game %}
<div class="row">
<div class="col-12">
<h2>Ranked Games</h2>
<table class="table table-dark table-striped table-hover table-sm">
<thead>
<tr>
<th>Game</th>
<th>Mode</th>
<th>ELO</th>
<th>W-L-T</th>
</tr>
</thead>
<tbody>
{% for game_mode, elo in elos_by_game.items %}
<tr>
<td>{{ game_mode.game }}</td>
<td>{{ game_mode.name }}</td>
{% if elo %}
<td>{{ elo.elo|floatformat:1 }}</td>
<td>{{ elo.matches_won }}-{{ elo.matches_lost }}-{{ elo.matches_drawn }}</td>
{% else %}
<td colspan="2">Not Played</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endfor %}
</div>
{% endif %}

<div class="row">
Expand All @@ -56,59 +57,58 @@ <h2>Highscores</h2>
</div>
</div>

{% if games|length > 0 %} {% for game_name, game in games.items %}

<div class="row">
<div
class="position-relative overflow-hidden p-3 shadowy p-md-3 m-md-3 text-center bg-dark"
>
<h3>
<a
href="/highscores/{{game.slug}}/combined/"
style="color: #fff; text-decoration: none"
>{{game_name}}</a
{% if games|length > 0 %}
{% for game_name, game in games.items %}
<div class="row">
<div
class="position-relative overflow-hidden p-3 shadowy p-md-3 m-md-3 text-center bg-dark"
>
</h3>
<h4>{{game.overall}}</h4>
</div>

{% for score in game.scores %}
<h3>
<a
href="/highscores/{{game.slug}}/combined/"
style="color: #fff; text-decoration: none"
>{{game_name}}</a
>
</h3>
<h4>{{game.overall}}</h4>
</div>

<div class="col-4">
<div
class="position-relative overflow-hidden p-3 p-md-3 shadowy m-md-3 text-center bg-dark"
>
<h3>
<a
href="/highscores/{{game.slug}}/{{score.leaderboard.name}}/"
style="color: #fff; text-decoration: none"
>{{score.leaderboard.name}}</a
>
</h3>
<h4>{{score.score}}</h4>
{% if score.score > 0 %}
<!---->
{% if "youtube" in score.source or "streamable" in sources.source %}
<iframe
class="img-fluid rounded"
src="{{score.source}}"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen
></iframe>
{% else %}
{% if "https://i.imgur.com/bUUfB8c.png" not in score.source %}
<img
src="{{score.source}}"
class="img-fluid rounded"
alt="{{score.leaderboard.name}} score screenshot"
width="300"
/>
{% endif %}
{% endif %} {% endif %}
{% for score in game.scores %}
<div class="col-4">
<div
class="position-relative overflow-hidden p-3 p-md-3 shadowy m-md-3 text-center bg-dark"
>
<h3>
<a
href="/highscores/{{game.slug}}/{{score.leaderboard.name}}/"
style="color: #fff; text-decoration: none"
>{{score.leaderboard.name}}</a
>
</h3>
<h4>{{score.score}}</h4>
{% if score.score > 0 %}
{% if "youtube" in score.source or "streamable" in score.source %}
<iframe
class="img-fluid rounded"
src="{{score.source}}"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen
></iframe>
{% else %}
{% if "https://i.imgur.com/bUUfB8c.png" not in score.source %}
<img
src="{{score.source}}"
class="img-fluid rounded"
alt="{{score.leaderboard.name}} score screenshot"
width="300"
/>
{% endif %}
{% endif %}
{% endif %}
</div>
</div>
{% endfor %}
</div>
</div>

{% endfor %}
</div>

{% endfor %} {% endif %} {% endblock %}
{% endif %}
{% endblock %}
9 changes: 7 additions & 2 deletions home/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ranked.models import PlayerElo
from ranked.models import PlayerElo, GameMode
from .models import HistoricEvent, Staff
from django.http.response import HttpResponseRedirect
from discordoauth2.models import User
Expand Down Expand Up @@ -113,9 +113,14 @@ def user_profile(request, user_id: int):
games[score.leaderboard.game]["scores"] += [score]
games[score.leaderboard.game]["overall"] += score.score

all_game_modes = GameMode.objects.all()
player_elos = PlayerElo.objects.filter(player=user)

elos_by_game = {}
for game_mode in all_game_modes:
elos_by_game[game_mode] = player_elos.filter(game_mode=game_mode).first()

context = {"games": games, "user": user, "elos": player_elos}
context = {"games": games, "user": user, "elos_by_game": elos_by_game}
return render(request, "home/user_profile.html", context)


Expand Down

0 comments on commit 78afa17

Please sign in to comment.