Skip to content

Commit

Permalink
[#6] Removed profile view and replaced it with user detail.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmckissock committed Aug 7, 2024
1 parent c136b72 commit c2f7797
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 32 deletions.
2 changes: 1 addition & 1 deletion audioapp/templates/audioapp/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</div>
<div class="flex items-center space-x-4">
{% if user.is_authenticated %}
<a href="{% url 'profile' %}" class="text-blue-500 hover:text-blue-700 focus-visible:text-blue-700">{{ user.username }}</a>
<a href="{% url 'user_detail' user.username %}" class="text-blue-500 hover:text-blue-700 focus-visible:text-blue-700">{{ user.username }}</a>
<form method="post" action="{% url 'account_logout' %}" class="inline">
{% csrf_token %}
<button type="submit" class="text-blue-500 hover:text-blue-700 focus-visible:text-blue-700">Sign Out</button>
Expand Down
18 changes: 0 additions & 18 deletions audioapp/templates/audioapp/profile.html

This file was deleted.

12 changes: 10 additions & 2 deletions audioapp/templates/audioapp/user_detail.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{% extends 'base.html' %}

{% block content %}
<h1>{{ page_user.username }}</h1>
<h1 class="text-2xl font-bold text-center my-8">{{page_user.username}}</h1>
<div class="flex justify-center my-4">
<a id="users_sounds" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded mx-2">Sounds</a>
<a id="liked_sounds" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded mx-2">Liked</a>
</div>
<h2>{{ page_user.username }}'s Sounds</h2>
<ul>
<ul id="audio_list">
{% for audio in audio_files %}
<li>
<a href="{% url 'audio_detail' audio.pk %}">{{ audio.title }}</a>
Expand All @@ -16,3 +20,7 @@ <h2>{{ page_user.username }}'s Sounds</h2>
</ul>
<a href="{% url 'upload_audio' %}">Upload new sound</a>
{% endblock %}




1 change: 0 additions & 1 deletion audioapp/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
urlpatterns = [
path("", for_you, name="for_you"),
path("accounts/", include("allauth.urls")),
path("accounts/profile/", views.profile_view, name="profile"),
path("upload/", upload_audio, name="upload_audio"),
path("audio/<int:pk>/", audio_detail, name="audio_detail"),
path("user/<str:username>/", user_detail, name="user_detail"),
Expand Down
14 changes: 4 additions & 10 deletions audioapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,9 @@
from .forms import AudioFileForm, CommentForm
from .models import AudioFile, Like, Comment
from django.contrib.auth.models import User
from django.db.models import Subquery


# Create your views here.
@login_required
def profile_view(request):
audio_files = AudioFile.objects.filter(user=request.user)
context = {
"username": request.user.username,
"audio_files": audio_files,
}
return render(request, "profile.html", context)


@login_required
Expand Down Expand Up @@ -71,10 +63,12 @@ def audio_detail(request, pk):
def user_detail(request, username):
page_user = get_object_or_404(User, username=username)
audio_files = AudioFile.objects.filter(user=page_user)
all_liked_sounds = Like.objects.filter(user=page_user).values('audio_file_id')
user_liked_sounds = AudioFile.objects.filter(id__in=Subquery(all_liked_sounds))
return render(
request,
"user_detail.html",
{"page_user": page_user, "audio_files": audio_files},
{"page_user": page_user, "audio_files": audio_files, "user_liked_sounds": user_liked_sounds},
)


Expand Down

0 comments on commit c2f7797

Please sign in to comment.