Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Commit

Permalink
feat(apps/users): improve profile page
Browse files Browse the repository at this point in the history
  • Loading branch information
bitterteriyaki committed Nov 27, 2023
1 parent af183f9 commit 9dbb1c6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 26 deletions.
4 changes: 1 addition & 3 deletions apps/users/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@

urlpatterns = [
path("register/", RegisterView.as_view(), name="register"),
path(
"profile/<str:user_username>/", ProfileView.as_view(), name="profile"
),
path("profile/<str:username>/", ProfileView.as_view(), name="profile"),
]
13 changes: 3 additions & 10 deletions apps/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ def post(self, request: HttpRequest) -> HttpResponse:
class ProfileView(View):
template_name = "users/profile.html"

def get(self, request: HttpRequest, user_username: str) -> HttpResponse:
user = get_object_or_404(User, username=user_username)

is_own_profile = user == request.user

return render(
request,
self.template_name,
{"user": user, "is_own_profile": is_own_profile},
)
def get(self, request: HttpRequest, *, username: str) -> HttpResponse:
user = get_object_or_404(User, username=username)
return render(request, self.template_name, {"user": user})
37 changes: 24 additions & 13 deletions templates/users/profile.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
{% extends "base.html" %}
{% extends "base.html" %}

{% block title %}User{% endblock title %}
{% block title %}{{ user.username }}{% endblock title %}

{% block content %}
<div class="user-profile">
<h2>{{ user.username }}</h2>

{% if is_own_profile %}
<p>Email: {{ user.email }}</p>
{% endif %}
<p>Score: {{ user.score }}</p>
<p>Contests: {{ user.contest }}</p>
</div>
{% endblock content %}
{% block content %}
<div class="card">
<div
class="card-header"
style="display: flex; align-items: center; justify-content: space-between;"
>
<h2>{{ user.username }}</h2>
{% if user.is_staff %}
<span class="badge bg-primary float-end mt-1">
Staff
</span>
{% endif %}
</div>
<div class="card-body">
{% if request.user.is_authenticated and request.user == user %}
<p>E-mail: {{ user.email }}</p>
{% endif %}
<p>Score: 0</p>
<p>Contests: {{ user.contests|length }}</p>
</div>
</div>
{% endblock content %}

0 comments on commit 9dbb1c6

Please sign in to comment.