From 0ea9672f69a348813a46e9e687082058110f09dd Mon Sep 17 00:00:00 2001 From: gereon77 Date: Mon, 29 Jan 2024 17:02:58 +0100 Subject: [PATCH] Some additional Games page improvements --- .../templates/agotboardgame_main/games.html | 57 ++++++---------- .../agotboardgame_main/my_games.html | 65 +++++++++++-------- .../templatetags/custom_filters.py | 8 +++ agot-bg-website/agotboardgame_main/views.py | 15 +++-- 4 files changed, 74 insertions(+), 71 deletions(-) create mode 100644 agot-bg-website/agotboardgame_main/templatetags/custom_filters.py 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 b0c291e25..8fb297139 100644 --- a/agot-bg-website/agotboardgame_main/templates/agotboardgame_main/games.html +++ b/agot-bg-website/agotboardgame_main/templates/agotboardgame_main/games.html @@ -1,5 +1,6 @@ {% extends "./base.html" %} {% load games_table %} +{% load custom_filters %} {% block title %} Games - @@ -42,10 +43,10 @@

Online Users ({{ request.online_now |

{% for user in request.online_now %} {% if user.is_admin %} - - {{ user.username }} + + {{ user.username }} {% if user.last_won_tournament %} - Online Users ({{ request.online_now | {% endif %} {% elif user.is_high_member %} - - {{ user.username }} + + {{ user.username }} {% if user.last_won_tournament %} - Online Users ({{ request.online_now | {% endif %} {% else %} - - {{ user.username }} + + {{ user.username }} {% if user.last_won_tournament %} - Running Live Games

+ {% if perms.agotboardgame_main.add_game %}
+ {% endif %}

@@ -157,8 +160,9 @@

- All Games + All Games ({{ all_games|get_length }})
+ {% if perms.agotboardgame_main.add_game %}
+ {% endif %}

@@ -190,33 +195,11 @@

- {% if perms.agotboardgame_main.add_game %} -
-
-
-
-
-
- {% csrf_token %} -
- - -
- -
-
-
-
-
-
- {% endif %} {% if perms.agotboardgame_main.can_play_as_another_player and inactive_games %}
-

Games without a move for 5 days

+

Games without a move for 5 days ({{ inactive_games|get_length }})

{% games_table inactive_games user perms True %}
@@ -228,7 +211,7 @@

Games without a move for 5 days

-

Tournament Games without a move for 2 days

+

Tournament Games without a move for 2 days ({{ inactive_tournament_games|get_length }})

{% games_table inactive_tournament_games user perms True %}
@@ -244,7 +227,7 @@

Tournament Games without a move for 2 days

data-toggle="tooltip" title="These are games where the last move was more than 2 days ago and the player being waited on has not logged in for 8 days." > - Games waiting for inactive players + Games waiting for inactive players ({{ replacement_needed_games|get_length }})
{% games_table replacement_needed_games user perms True %} @@ -258,7 +241,7 @@

Tournament Games without a move for 2 days

- Inactive Private Games + Inactive Private Games ({{ inactive_private_games|get_length }})

{% games_table inactive_private_games user perms %} 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 5456274de..3cf3f8c0d 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 @@ -1,5 +1,6 @@ {% extends "./base.html" %} {% load games_table %} +{% load custom_filters %} {% block title %} Your Games - @@ -41,10 +42,10 @@

Online Users ({{ request.online_now |

{% for user in request.online_now %} {% if user.is_admin %} - - {{ user.username }} + + {{ user.username }} {% if user.last_won_tournament %} - Online Users ({{ request.online_now | {% endif %} {% elif user.is_high_member %} - - {{ user.username }} + + {{ user.username }} {% if user.last_won_tournament %} - Online Users ({{ request.online_now | {% endif %} {% else %} - - {{ user.username }} + + {{ user.username }} {% if user.last_won_tournament %} - Online Users ({{ request.online_now |
- {% if my_games %}

- Your Games + Your Games ({{ my_games|get_length }})
+ {% if perms.agotboardgame_main.add_game %}
+ {% endif %}

-
+
{% csrf_token %}
@@ -128,15 +130,6 @@

- {% else %} -
-
-
-

You currently have no running games!

-
-
-
- {% endif %} {% if open_live_games %}
@@ -157,32 +150,35 @@

Running Live Games

{% endif %} + {% if my_created_games %}
+ {% endif %} + diff --git a/agot-bg-website/agotboardgame_main/templatetags/custom_filters.py b/agot-bg-website/agotboardgame_main/templatetags/custom_filters.py new file mode 100644 index 000000000..98af39504 --- /dev/null +++ b/agot-bg-website/agotboardgame_main/templatetags/custom_filters.py @@ -0,0 +1,8 @@ +# custom_filters.py +from django import template + +register = template.Library() + +@register.filter(name='get_length') +def get_length(value): + return len(value) diff --git a/agot-bg-website/agotboardgame_main/views.py b/agot-bg-website/agotboardgame_main/views.py index ebf7d020d..baf8628e7 100644 --- a/agot-bg-website/agotboardgame_main/views.py +++ b/agot-bg-website/agotboardgame_main/views.py @@ -191,11 +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) + 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, "open_live_games": open_live_games, "running_live_games": running_live_games, "last_finished_game": last_finished_game, @@ -311,24 +315,21 @@ def games(request): "last_finished_game": last_finished_game }) elif request.method == "POST": - if not request.user.has_perm("agotboardgame_main.add_game"): - return HttpResponseRedirect("/") - name = request.POST.get("name", "") + if not request.user.has_perm("agotboardgame_main.add_game") or len(name) > 200: + return HttpResponseRedirect("/games") + game = Game() game.name = name game.owner = request.user game.save() - if len(name) > 200: - return HttpResponseRedirect("/games") - return HttpResponseRedirect(f"/play/{game.id}") def cancel_game(request, game_id): if not request.user.has_perm("agotboardgame_main.cancel_game"): - return HttpResponseRedirect("/") + return HttpResponseRedirect("/games") game = get_object_or_404(Game, id=game_id)