Skip to content

Commit

Permalink
me
Browse files Browse the repository at this point in the history
  • Loading branch information
SupraSummus committed Oct 17, 2024
1 parent 4c5e39a commit 4b3e9c3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 29 deletions.
2 changes: 1 addition & 1 deletion llm_wars/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def to_url(self, value):
router.route_all('labirynth/', labirynth_router, name='labirynth')
router.route_all('stories/', stories_router, name='stories')
router.route_all('my-warriors/', my_warriors_view.router, name='my_warriors')
router.route_all('warrior-detail/', warrior_detail_view.router, name='warrior_detail')

urlpatterns = (
path('', TemplateView.as_view(template_name="home.html"), name='home'),
Expand All @@ -75,7 +76,6 @@ def to_url(self, value):
),
path('challenge/<uuid:pk>/', ChallengeWarriorView.as_view(), name='challenge_warrior'),
path('battle/<uuid:pk>/', BattleDetailView.as_view(), name='battle_detail'),
path('global-warrior/', warrior_detail_view.router.urls),

path('login/', LoginView.as_view(), name='login'),
path('logout/', LogoutView.as_view(), name='logout'),
Expand Down
10 changes: 0 additions & 10 deletions warriors/tests/warrior_detail_view_tests.py

This file was deleted.

22 changes: 4 additions & 18 deletions warriors/warrior_detail_view.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from collections import Counter

from django.shortcuts import get_object_or_404
from django.template.response import TemplateResponse

from djsfc import Router, parse_template

from .models import Battle, WarriorArena, WarriorUserPermission
from .models import WarriorUserPermission
from .views import is_request_authorized
from .warriors import Warrior


router = Router(__name__)
Expand Down Expand Up @@ -99,12 +98,8 @@


@router.route('GET', '<uuid:warrior_id>/')
def warrior_detail(request, warrior_id):
warrior = get_object_or_404(WarriorArena, id=warrior_id)

battles_qs = Battle.objects.with_warrior(warrior).select_related(
'warrior_1', 'warrior_1__warrior', 'warrior_2', 'warrior_2__warrior'
)
def root(request, warrior_id):
warrior = get_object_or_404(Warrior, id=warrior_id)

show_secrets = is_request_authorized(warrior, request)
warrior_user_permission = None
Expand All @@ -114,19 +109,10 @@ def warrior_detail(request, warrior_id):
user=request.user,
).first()

top_opponents = Counter(
battle.opponent(warrior) for battle in battles_qs
).most_common(5)

context = {
'warrior': warrior,
'total_battles': battles_qs.count(),
'battles': [battle.get_warrior_viewpoint(warrior) for battle in battles_qs[:100]],
'show_secrets': show_secrets,
'warrior_user_permission': warrior_user_permission,
'last_battle': battles_qs.order_by('-scheduled_at').first(),
'top_opponents': top_opponents,
'arena': warrior.arena,
}

return TemplateResponse(request, template, context)
9 changes: 9 additions & 0 deletions warriors/warrior_detail_view_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import pytest
from django.urls import reverse


@pytest.mark.django_db
def test_warrior_detail_view(client, warrior):
url = reverse('warrior_detail:root', kwargs={'warrior_id': warrior.id})
response = client.get(url)
assert response.status_code == 200

0 comments on commit 4b3e9c3

Please sign in to comment.