Skip to content

Commit

Permalink
Merge pull request #311 from jwjacobson/list
Browse files Browse the repository at this point in the history
List
  • Loading branch information
jwjacobson authored Sep 18, 2024
2 parents f76a949 + b1364a1 commit d519fd4
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 24 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,5 @@ cython_debug/
!.elasticbeanstalk/*.global.yml
tune/scratch*.py
vars.sh
latest.dump
latest.dump
.idea/
4 changes: 3 additions & 1 deletion tune/templates/tune/browse.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ <h5 class = "card-title">Tune Search</h5>
<div>
<form
hx-post="{% url 'tune:tune_browse' %}"
hx-target="#public-table"
hx-target="#table_count"
hx-swap="outerHTML">
{% csrf_token %}
<label for="basic_search"></label>
Expand All @@ -28,6 +28,7 @@ <h5 class = "card-title">Tune Search</h5>
</div>
</div>

<div id="table_count">
<div class="row mt-4 align-items-end justify-content-evenly">
<div class="col-10">
<h1
Expand Down Expand Up @@ -90,6 +91,7 @@ <h4>
</tbody>
</table>
</div>
</div>
<script>
$(document).ready(function () {
$('#public-table').DataTable({
Expand Down
5 changes: 4 additions & 1 deletion tune/templates/tune/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<h5 class="card-title">Tune Search</h5>
<div>
<form hx-post="{% url 'tune:tune_list' %}"
hx-target="#rep-table"
hx-target="#table_count"
hx-swap="outerHTML">
{% csrf_token %}
<label for="basic_search"></label>
Expand All @@ -41,6 +41,8 @@ <h5 class="card-title">Tune Search</h5>
</div>
</div>


<div id="table_count">
<div class="row mt-4 align-items-end justify-content-evenly">
<div class="col-10">
<h1
Expand Down Expand Up @@ -121,6 +123,7 @@ <h4>
</tbody>
</table>
</div>
</div>
<script>
// Uncomment this script for column visibility toggling; good but ugly
// $(document).ready(function() {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
<div class="row mt-4 align-items-end justify-content-evenly">
<div class="col-10">
<h1
class="text-info-emphasis">Public Tunes
</h1>
</div>
<div class="col-2" style="text-align: right;" id="count" hx-get="/count" hx-trigger="tuneDeleted from:body" hx-swap="outerHTML">
<h4>
{% if tune_count == 1 %}
{{ tune_count }} tune
{% else %}
{{ tune_count }} tunes
{% endif %}
</h4>
</div>
</div>

<table class="table table-success table-striped table-hover border border-primary" id="public-table">
<thead>
<tr>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
<div class="row mt-4 align-items-end justify-content-evenly">
<div class="col-10">
<h1
class="text-info-emphasis">{{ user }}'s repertoire
</h1>
</div>
<div class="col-2" style="text-align: right;" id="count" hx-get="/count" hx-trigger="tuneDeleted from:body" hx-swap="outerHTML">
<h4>
{% if tune_count == 1 %}
{{ tune_count }} tune
{% else %}
{{ tune_count }} tunes
{% endif %}
</h4>
</div>
</div>

<table class="table table-responsive table-success table-striped table-hover border border-primary" id="rep-table">
<thead>
<tr>
Expand Down
File renamed without changes.
File renamed without changes.
54 changes: 33 additions & 21 deletions tune/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
@login_required
def tune_list(request):
"""
View for the app's home page, which shows a user's repertoire and allows searching and tune management.
Show the user's home page, which displays a searchable repertoire and allows for tune management.
"""
user = request.user
tunes = RepertoireTune.objects.select_related("tune").filter(player=user)
Expand All @@ -56,7 +56,11 @@ def tune_list(request):
search_form = SearchForm()

if request.headers.get("Hx-Request"):
return render(request, "tune/_table_list.html", {"tunes": tunes})
return render(
request,
"tune/partials/_table_list.html",
{"tunes": tunes, "tune_count": tune_count},
)

request.session["tune_count"] = tune_count
return render(
Expand All @@ -74,7 +78,7 @@ def tune_list(request):
@login_required
def tune_new(request):
"""
View for creating a new tune in a user's repertoire.
Create a new tune in a user's repertoire.
"""
if request.method != "POST":
tune_form = TuneForm()
Expand Down Expand Up @@ -121,7 +125,7 @@ def tune_new(request):
@login_required
def tune_edit(request, pk):
"""
View for editing a tune in a user's repertoire.
Edit a tune in a user's repertoire.
"""
tune = get_object_or_404(Tune, pk=pk)
rep_tune = get_object_or_404(RepertoireTune, tune=tune, player=request.user)
Expand Down Expand Up @@ -156,7 +160,7 @@ def tune_edit(request, pk):
@login_required
def tune_delete(request, pk):
"""
View for deleting a tune from a user's repertoire.
Delete a tune from a user's repertoire.
"""
tune = get_object_or_404(Tune, pk=pk)
rep_tune = get_object_or_404(RepertoireTune, tune=tune, player=request.user)
Expand All @@ -175,10 +179,10 @@ def tune_delete(request, pk):
@login_required
def recount(request):
"""
View for updating the tune count that displays on the home and public pages.
Update the tune count that displays on the home and public pages.
"""
tune_count = request.session["tune_count"]
return render(request, "tune/_count.html", {"tune_count": tune_count})
return render(request, "tune/partials/_count.html", {"tune_count": tune_count})


@login_required
Expand Down Expand Up @@ -217,13 +221,15 @@ def get_random_tune(request):
selected_tune = None
request.session.save()

return render(request, "tune/_play_card.html", {"selected_tune": selected_tune})
return render(
request, "tune/partials/_play_card.html", {"selected_tune": selected_tune}
)


@login_required
def change_tune(request):
"""
Function for selecting a different random tune from the search results on the play page if the previous one is rejected.
Select a different tune from the play search results if the previous one is rejected.
"""
if not request.session.get("rep_tunes"):
return render(request, "tune/_play_card.html", {"selected_tune": None})
Expand All @@ -233,18 +239,20 @@ def change_tune(request):
request.session.save()

selected_tune = RepertoireTune.objects.get(id=chosen_tune_id)
return render(request, "tune/_play_card.html", {"selected_tune": selected_tune})
return render(
request, "tune/partials/_play_card.html", {"selected_tune": selected_tune}
)


@login_required
def play(request, pk):
"""
View for updating a tune's last_played field, functioning differently if called from the home or play pages.
Update a tune's last_played field to now.
"""
url_name = request.resolver_match.url_name
templates = {
"play_list": "tune/_play_list.html",
"play_play": "tune/_play_play.html",
"play_list": "tune/partials/_play_list.html",
"play_play": "tune/partials/_play_play.html",
}

rep_tune = get_object_or_404(RepertoireTune, id=pk, player=request.user)
Expand All @@ -255,7 +263,7 @@ def play(request, pk):
if url_name == "play_play":
return render(
request,
"tune/_another_button.html",
"tune/partials/_another_button.html",
{"last_played": rep_tune.last_played, "selected_tune": rep_tune},
)

Expand All @@ -269,15 +277,15 @@ def play(request, pk):
@login_required
def tune_play(request):
"""
View for loading the play page.
Load the play page.
"""
return render(request, "tune/play.html")


@login_required
def tune_browse(request):
"""
View for loading the public page, where users can browse public tunes and take them into their repertoire
Show the public page of preloaded tunes.
"""

user_tunes = RepertoireTune.objects.select_related("tune").filter(
Expand All @@ -302,7 +310,11 @@ def tune_browse(request):
search_form = SearchForm()

if request.headers.get("Hx-Request"):
return render(request, "tune/_table_browse.html", {"tunes": tunes})
return render(
request,
"tune/partials/_table_browse.html",
{"tunes": tunes, "tune_count": tune_count},
)

return render(
request,
Expand All @@ -319,7 +331,7 @@ def tune_browse(request):
@login_required
def tune_take(request, pk):
"""
View for taking a public tune into a user's repertoire.
Take a public tune into a user's repertoire.
"""
user = request.user
admin_tune = get_object_or_404(RepertoireTune, pk=pk)
Expand All @@ -339,15 +351,15 @@ def tune_take(request, pk):

return render(
request,
"tune/_take.html",
"tune/partials/_take.html",
{"rep_form": rep_form, "tune": tune, "new_rep_tune": new_rep_tune},
)


@login_required
def set_rep_fields(request, pk):
"""
View for setting the knowledge and last_played fields when a user takes a public tune into their repertoire.
Set the knowledge, last_played, and tags of a public tune when a user takes it into their repertoire.
"""
rep_tune = RepertoireTune.objects.get(pk=pk)
rep_form = RepertoireTuneForm(request.POST)
Expand All @@ -361,4 +373,4 @@ def set_rep_fields(request, pk):
print("invalid")
print(rep_form.errors)

return render(request, "tune/_taken.html", {"rep_form": rep_form})
return render(request, "tune/partials/_taken.html", {"rep_form": rep_form})

0 comments on commit d519fd4

Please sign in to comment.