Skip to content

Commit

Permalink
me
Browse files Browse the repository at this point in the history
  • Loading branch information
SupraSummus committed Sep 29, 2024
1 parent 1bb53d7 commit 19eedba
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 40 deletions.
3 changes: 1 addition & 2 deletions llm_wars/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@
from labirynth.map_view import router as labirynth_router
from stories.models import router as stories_router
from users.views import SignupView
from warriors import my_warriors_view
from warriors import my_warriors_view, warrior_detail_view
from warriors.create_view import WarriorCreateView
from warriors.views import (
ArenaDetailView, BattleDetailView, ChallengeWarriorView, WarriorDetailView,
WarriorLeaderboard, warrior_set_public_battle_results,
)
from warriors import warrior_detail_view


class SignedIntConverter:
Expand Down
79 changes: 41 additions & 38 deletions warriors/warrior_detail_view.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,18 @@
from collections import Counter

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

from .models import WarriorArena, Battle, WarriorUserPermission
from .views import is_request_authorized
from djsfc import Router, parse_template

router = Router(__name__)

@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'
)

show_secrets = is_request_authorized(warrior, request)
warrior_user_permission = None
if request.user.is_authenticated:
warrior_user_permission = WarriorUserPermission.objects.filter(
warrior=warrior.warrior,
user=request.user,
).first()
from .models import Battle, WarriorArena, WarriorUserPermission
from .views import is_request_authorized

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,
}
router = Router(__name__)

return TemplateResponse(request, 'warrior_detail.html', context)

TEMPLATE = '''
template = parse_template('''\
{% extends "base.html" %}
{% block title %}{{ warrior.name }} - Global Warrior Details{% endblock %}
Expand Down Expand Up @@ -84,7 +55,7 @@ def warrior_detail(request, warrior_id):
<form method="post" action="{% url 'warrior_set_public_battles' warrior.id %}">
{% csrf_token %}
<label>
<input type="checkbox" name="public_battle_results"
<input type="checkbox" name="public_battle_results"
{% if warrior_user_permission.public_battle_results %}checked{% endif %}>
Public battle results
</label>
Expand Down Expand Up @@ -124,6 +95,38 @@ def warrior_detail(request, warrior_id):
<a href="{% url 'challenge_warrior' warrior.id %}" role="button">Challenge this warrior</a>
{% endblock %}
'''
''', router=router)


@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'
)

show_secrets = is_request_authorized(warrior, request)
warrior_user_permission = None
if request.user.is_authenticated:
warrior_user_permission = WarriorUserPermission.objects.filter(
warrior=warrior.warrior,
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,
}

router.add_template('warrior_detail.html', TEMPLATE)
return TemplateResponse(request, template, context)

0 comments on commit 19eedba

Please sign in to comment.