Skip to content

Commit

Permalink
Merge pull request #365 from uchicago-cs/users/hist-info
Browse files Browse the repository at this point in the history
Displaying Historical Information on a user view
  • Loading branch information
elizabethli31 authored Dec 5, 2023
2 parents 49c8778 + 8ffb781 commit 3b03340
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 15 deletions.
23 changes: 22 additions & 1 deletion src/chigame/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
from django.http import HttpResponseNotFound
from django.shortcuts import get_object_or_404, redirect, render
from django.urls import reverse
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
from django.views.generic import DetailView, RedirectView, UpdateView
from rest_framework import status
from rest_framework.response import Response

from chigame.games.models import Lobby, Player, Tournament

from .models import FriendInvitation, Notification, UserProfile
from .tables import FriendsTable, UserTable

Expand Down Expand Up @@ -76,7 +79,25 @@ def user_history(request, pk):
try:
user = User.objects.get(pk=pk)

return render(request, "users/user_history.html", {"user": user})
match_count = Lobby.objects.filter(match_status=3, members__in=[user]).count()
match_wins = Player.objects.filter(Q(user=user, outcome=Player.WIN) | Q(team=user, outcome=Player.WIN)).count()

tournament_count = Tournament.objects.filter(
tournament_end_date__lt=timezone.now(), players__in=[user]
).count()
tournament_wins = Tournament.objects.filter(winners__in=[user]).count()

return render(
request,
"users/user_history.html",
{
"user": user,
"match_count": match_count,
"match_wins": match_wins,
"tournament_count": tournament_count,
"tournament_wins": tournament_wins,
},
)
except User.DoesNotExist:
return Response(status=status.HTTP_404_NOT_FOUND)

Expand Down
57 changes: 43 additions & 14 deletions src/templates/users/user_history.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,47 @@
{% extends "base.html" %}

{% block content %}
<h2>User Historical Information</h2>
<ul>
<li>Name: {{ user.name }}</li>
<!-- Add additional information here -->
<li>
Games Played:
<!-- {{ user.games_played }} TO BE IMPLEMENTED-->
</li>
<li>
Games Won:
<!-- {{ user.games_won }} TO BE IMPLEMENTED-->
</li>
<!-- Add more fields here-->
</ul>
<div class="user-stats">
<h2>User Match and Tournament Stats</h2>
<ul class="user-info">
<li>Name: {{ user.name }}</li>
<!-- Add additional information here -->
<li>
Matches Played:
{{ match_count }}
</li>
<li>
Matches Won:
{{ match_wins }}
</li>
<li>
Tournaments Played:
{{ tournament_count }}
</li>
<li>
Tournaments Won:
{{ tournament_wins }}
</li>
</ul>
</div>
<style>
.user-stats {
max-width: 600px;
margin: 0 auto;
padding: 20px;
background-color: #f8f8f8;
border: 1px solid #ddd;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

.user-info {
list-style-type: none;
padding: 0;
}

.user-info li {
margin-bottom: 15px;
}
</style>
{% endblock content %}
13 changes: 13 additions & 0 deletions src/templates/users/userprofile_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,22 @@
<p>Bio: {{ object.bio }}</p>
{% if object.user == request.user %}
<a href="{% url 'users:update' %}" class="btn btn-primary">Edit Profile</a>
<a href="{% url 'users:detail' request.user.pk %}"
class="btn btn-primary">Account</a>
<a href="{% url 'users:friend-list' object.user.id %}"
class="btn btn-primary">Friend List</a>
<a href="{% url 'users:user-history' object.user.pk %}"
class="btn btn-primary">Stats</a>
{% elif is_friend %}
<a href="{% url 'users:remove-friend' object.user.pk %}"
class="btn btn-primary">Remove Friend</a>
<a href="{% url 'users:user-history' object.user.pk %}"
class="btn btn-primary">Stats</a>
{% elif is_friend %}
<a href="{% url 'users:remove-friend' object.user.pk %}"
class="btn btn-primary">Remove Friend</a>
<a href="{% url 'users:user-history' object.user.pk %}"
class="btn btn-primary">Stats</a>
{% elif friendship_request %}
{% if friendship_request.sender_id == request.user.pk %}
<a href="{% url 'users:cancel-friend-invitation' object.user.id %}"
Expand All @@ -45,6 +56,8 @@
<a href="{% url 'users:decline-friend-invitation' friendship_request.id %}"
class="btn btn-primary">Decline Friendship Request</a>
{% endif %}
<a href="{% url 'users:user-history' object.user.pk %}"
class="btn btn-primary">Stats</a>
{% else %}
<a href="{% url 'users:add-friend' object.user.pk %}"
class="btn btn-primary">Add Friend</a>
Expand Down

0 comments on commit 3b03340

Please sign in to comment.