Skip to content

Commit

Permalink
improve search
Browse files Browse the repository at this point in the history
  • Loading branch information
catgirlinspace committed Nov 29, 2023
1 parent 420e150 commit 2f1453d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 30 deletions.
63 changes: 34 additions & 29 deletions search/templates/search/search_for_players_played_with.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,41 @@

{% block content %}
<h1 class="font-splatoon1 text-3xl">
{% block title %}Battles you've had with {{ player.name }}#{{ player.name_id }}{% endblock %}
{% block title %}{% if player %}Battles you've had with {{ player.name }}#{{ player.name_id }}{% else %}No
Battles Found{% endif %}{% endblock %}
</h1>
<div class="text-sm font-mono">{{ player.npln_id }}</div>
{% if player %}
<div class="text-sm font-mono">{{ player.npln_id }}</div>

<table class="table-auto w-full border border-slate-600 border-collapse border-spacing-2">
<thead>
<tr>
<th class="border border-slate-600">Mode</th>
<th class="border border-slate-600">Rule</th>
<th class="border border-slate-600">Stage</th>
<th class="border border-slate-600">Played Time</th>
<th class="border border-slate-600">Judgement</th>
</tr>
</thead>
<tbody>
{% for battle in battles %}
<tr class="odd:bg-gray-500/25 even:bg-gray-900/25">
<td class="border border-slate-600">{{ battle.get_vs_mode_display }}</td>
<td class="border border-slate-600">{{ battle.get_vs_rule_display }}</td>
<td class="border border-slate-600">{{ battle.vs_stage.name.string }}</td>
<td class="border border-slate-600">{{ battle.played_time }}</td>
<td class="border border-slate-600">{{ battle.get_judgement_display }}</td>
<td class="border border-slate-600 p-2">
<a href="{% url 'battles:view_battle' battle.id %}"
class="px-2 bg-purple-700 text-white rounded-lg">
View Battle
</a>
</td>
<table class="table-auto w-full border border-slate-600 border-collapse border-spacing-2">
<thead>
<tr>
<th class="border border-slate-600">Mode</th>
<th class="border border-slate-600">Rule</th>
<th class="border border-slate-600">Stage</th>
<th class="border border-slate-600">Played Time</th>
<th class="border border-slate-600">Judgement</th>
</tr>
{% endfor %}
</tbody>
</table>
</thead>
<tbody>
{% for battle in battles %}
<tr class="odd:bg-gray-500/25 even:bg-gray-900/25">
<td class="border border-slate-600">{{ battle.get_vs_mode_display }}</td>
<td class="border border-slate-600">{{ battle.get_vs_rule_display }}</td>
<td class="border border-slate-600">{{ battle.vs_stage.name.string }}</td>
<td class="border border-slate-600">{{ battle.played_time }}</td>
<td class="border border-slate-600">{{ battle.get_judgement_display }}</td>
<td class="border border-slate-600 p-2">
<a href="{% url 'battles:view_battle' battle.id %}"
class="px-2 bg-purple-700 text-white rounded-lg">
View Battle
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
You haven't had any battles with this player.
{% endif %}
{% endblock %}
8 changes: 7 additions & 1 deletion search/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseBadRequest
from django.shortcuts import render

from battles.models import Player, Battle
Expand All @@ -8,10 +9,15 @@

@login_required
def search_for_players_played_with(request, npln_id: str):
request_user_player = Player.objects.filter(team__battle__uploader_id=request.user.id, is_self=True).latest(
'team__battle__played_time')
if str.lower(request_user_player.npln_id) == str.lower(npln_id):
return HttpResponseBadRequest('You cannot search for yourself.')

players = Player.objects.filter(team__battle__uploader_id=request.user.id, npln_id__iexact=npln_id).distinct()
battles_with_player = Battle.objects.filter(teams__players__in=players).distinct().order_by('-played_time')

return render(request, 'search/search_for_players_played_with.html', {
'battles': battles_with_player,
'player': players.latest('team__battle__played_time'),
'player': players.latest('team__battle__played_time') if len(players) > 0 else None,
})

0 comments on commit 2f1453d

Please sign in to comment.