From 6f34b8ad0cc61c00cfba2828dcea1be9bf07def3 Mon Sep 17 00:00:00 2001 From: gereon77 Date: Mon, 25 Mar 2024 10:09:01 +0100 Subject: [PATCH] Add "Join as owner" button --- .../components/games_table.html | 17 +++++++++++++++-- .../templates/agotboardgame_main/games.html | 4 ++-- .../templates/agotboardgame_main/my_games.html | 2 +- .../templatetags/games_table.py | 11 +++++++++-- agot-bg-website/agotboardgame_main/views.py | 6 +++--- 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/agot-bg-website/agotboardgame_main/templates/agotboardgame_main/components/games_table.html b/agot-bg-website/agotboardgame_main/templates/agotboardgame_main/components/games_table.html index bf2709b3c..f992e0be8 100644 --- a/agot-bg-website/agotboardgame_main/templates/agotboardgame_main/components/games_table.html +++ b/agot-bg-website/agotboardgame_main/templates/agotboardgame_main/components/games_table.html @@ -11,7 +11,9 @@ Players - {% if show_join_as and perms.agotboardgame_main.can_play_as_another_player %} + {% if show_join_as_waited and perms.agotboardgame_main.can_play_as_another_player %} + + {% elif show_join_as_owner and perms.agotboardgame_main.can_play_as_another_player %} {% elif perms.agotboardgame_main.cancel_game %} @@ -148,7 +150,7 @@ {% endif %} {% endif %} - {% if show_join_as and game.inactive_user_id and perms.agotboardgame_main.can_play_as_another_player %} + {% if show_join_as_waited and game.inactive_user_id and perms.agotboardgame_main.can_play_as_another_player %} {% endif %} + {% if show_join_as_owner and perms.agotboardgame_main.can_play_as_another_player and game.state == "IN_LOBBY" %} + + Join as host + + {% endif %} {% if perms.agotboardgame_main.cancel_game %}
{% csrf_token %} diff --git a/agot-bg-website/agotboardgame_main/templates/agotboardgame_main/games.html b/agot-bg-website/agotboardgame_main/templates/agotboardgame_main/games.html index 30cb4c4ae..091f4e97d 100644 --- a/agot-bg-website/agotboardgame_main/templates/agotboardgame_main/games.html +++ b/agot-bg-website/agotboardgame_main/templates/agotboardgame_main/games.html @@ -97,7 +97,7 @@

Online Users({{ request.online_now |

Open Live Games

- {% games_table open_live_games user perms %} + {% games_table open_live_games user perms False True %}
@@ -189,7 +189,7 @@

- {% games_table all_games user perms %} + {% games_table all_games user perms False True %}
diff --git a/agot-bg-website/agotboardgame_main/templates/agotboardgame_main/my_games.html b/agot-bg-website/agotboardgame_main/templates/agotboardgame_main/my_games.html index 3cba1828c..4e04875ce 100644 --- a/agot-bg-website/agotboardgame_main/templates/agotboardgame_main/my_games.html +++ b/agot-bg-website/agotboardgame_main/templates/agotboardgame_main/my_games.html @@ -134,7 +134,7 @@

Open Live Games

- {% games_table open_live_games user perms %} + {% games_table open_live_games user perms False True %}
diff --git a/agot-bg-website/agotboardgame_main/templatetags/games_table.py b/agot-bg-website/agotboardgame_main/templatetags/games_table.py index 90072d026..d546585f1 100644 --- a/agot-bg-website/agotboardgame_main/templatetags/games_table.py +++ b/agot-bg-website/agotboardgame_main/templatetags/games_table.py @@ -4,5 +4,12 @@ @register.inclusion_tag("agotboardgame_main/components/games_table.html") -def games_table(games, user, perms, showJoinAs = False): - return {"games": games, "user": user, "perms": perms, "on_probation": user.is_authenticated and user.is_in_group("On probation"), "show_join_as": showJoinAs} +def games_table(games, user, perms, showJoinAsWaited = False, showJoinAsOwner = False): + return { + "games": games, + "user": user, + "perms": perms, + "on_probation": user.is_authenticated and user.is_in_group("On probation"), + "show_join_as_waited": showJoinAsWaited, + "show_join_as_owner": showJoinAsOwner + } diff --git a/agot-bg-website/agotboardgame_main/views.py b/agot-bg-website/agotboardgame_main/views.py index baf8628e7..e4ccb33d0 100644 --- a/agot-bg-website/agotboardgame_main/views.py +++ b/agot-bg-website/agotboardgame_main/views.py @@ -191,15 +191,15 @@ def my_games(request): my_games = games_query.filter((Q(state=IN_LOBBY) | Q(state=ONGOING)) & Q(user_is_in_game=1)).order_by("state", "-last_active_at") enrich_games(request, my_games, True, False, True) - my_created_games = games_query.filter((Q(state=IN_LOBBY) | Q(state=ONGOING)) & Q(owner=request.user)).order_by("state", "-last_active_at") - enrich_games(request, my_created_games, False, False, False) + #my_created_games = games_query.filter((Q(state=IN_LOBBY) | Q(state=ONGOING)) & Q(owner=request.user)).order_by("state", "-last_active_at") + #enrich_games(request, my_created_games, False, False, False) last_finished_game = Game.objects.filter(state=FINISHED).annotate(players_count=Count('players')).latest() public_room_id = Room.objects.get(name='public').id return render(request, "agotboardgame_main/my_games.html", { "my_games": my_games, - "my_created_games": my_created_games, + #"my_created_games": my_created_games, "open_live_games": open_live_games, "running_live_games": running_live_games, "last_finished_game": last_finished_game,