Skip to content

Commit

Permalink
[#N/A] Changed styling for base.html
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmckissock committed Jul 26, 2024
1 parent 6ddb54a commit eeb9b7a
Show file tree
Hide file tree
Showing 3 changed files with 992 additions and 34 deletions.
41 changes: 22 additions & 19 deletions audioapp/templates/audioapp/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,32 @@
<head>
{% tailwind_css %}
</head>
<body>
<header>
<nav>
{% if user.is_authenticated %}
<span>{{ user.username }}</span>
{% endif %}

<a href="{% url 'index' %}">Home</a>
{% if user.is_authenticated %}
<a href="{% url 'profile' %}">Profile</a>
<form method="post" action="{% url 'account_logout' %}">
{% csrf_token %}
<button type="submit">Sign Out</button>
</form>
{% else %}
<a href="{% url 'account_login' %}">Sign In</a>
<a href="{% url 'account_signup' %}">Sign Up</a>
{% endif %}
<body class="bg-gray-100">
<header class="bg-white shadow">
<nav class="container mx-auto flex justify-between items-center p-4">
<div class="flex items-center space-x-4">
<a href="{% url 'index' %}" class="text-blue-500 hover:text-blue-700">Home</a>
<a href="{% url 'for_you' %}" class="text-blue-500 hover:text-blue-700">For You</a>
<a href="{% url 'upload_audio' %}" class="text-blue-500 hover:text-blue-700">Upload Sound</a>
</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">{{ 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">Sign Out</button>
</form>
{% else %}
<a href="{% url 'account_login' %}" class="text-blue-500 hover:text-blue-700">Sign In</a>
<a href="{% url 'account_signup' %}" class="text-blue-500 hover:text-blue-700">Sign Up</a>
{% endif %}
</div>
</nav>
</header>
<main>
<main class="container mx-auto p-4">
{% block content %}
{% endblock %}
</main>
</body>
</html>

24 changes: 10 additions & 14 deletions audioapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,13 @@ def update_fyp_index(request, fyp_order, fyp_index):

return fyp_index, reached_end


def handle_post_request(request, audio_file):
action = request.POST.get("action")
if action == "comment":
handle_comment(request, audio_file)
elif action == "like":
handle_like(request, audio_file)


def handle_comment(request, audio_file):
comment_form = CommentForm(request.POST)
if comment_form.is_valid():
Expand All @@ -131,7 +129,6 @@ def handle_comment(request, audio_file):
comment.audio_file = audio_file
comment.save()


def handle_like(request, audio_file):
if not Like.objects.filter(user=request.user, audio_file=audio_file).exists():
like, created = Like.objects.get_or_create(
Expand All @@ -141,8 +138,6 @@ def handle_like(request, audio_file):
print("Like created:", like)
else:
Like.objects.filter(user=request.user, audio_file=audio_file).delete()



def fyp_xml_http_request(audio_file, reached_end, fyp_index):
return JsonResponse(
Expand All @@ -160,6 +155,7 @@ def fyp_xml_http_request(audio_file, reached_end, fyp_index):
],
}
)

if "fyp_order" not in request.session:
audio_files = list(AudioFile.objects.all())
fyp_order = [audio_file.id for audio_file in audio_files]
Expand Down Expand Up @@ -198,13 +194,13 @@ def fyp_xml_http_request(audio_file, reached_end, fyp_index):
},
)

def update_autoplay(request):
if (
request.headers.get("x-requested-with") == "XMLHttpRequest"
and "autoplay" in request.GET
):
request.session["autoplay"] = request.GET.get("autoplay") == "true"
request.session.modified = True
return JsonResponse({"status": "success"})
return JsonResponse({"status": "fail"}, status=400)

def update_autoplay(request):
if (
request.headers.get("x-requested-with") == "XMLHttpRequest"
and "autoplay" in request.GET
):
request.session["autoplay"] = request.GET.get("autoplay") == "true"
request.session.modified = True
return JsonResponse({"status": "success"})
return JsonResponse({"status": "fail"}, status=400)
Loading

0 comments on commit eeb9b7a

Please sign in to comment.