diff --git a/src/character/tests/test_interactions.py b/src/character/tests/test_interactions.py
index f499b5e..bab1081 100644
--- a/src/character/tests/test_interactions.py
+++ b/src/character/tests/test_interactions.py
@@ -147,13 +147,12 @@ def test_delete_character(selenium: WebDriver, live_server: LiveServer):
@pytest.mark.django_db
-@pytest.mark.parametrize("profile_name", ["Magicien", "Druide", "Guerrier"])
def test_reset_stats_view(
- profile_name: str, selenium: WebDriver, live_server: LiveServer, initial_data: None
+ selenium: WebDriver, live_server: LiveServer, initial_data: None
):
username, password = "user", "some_password"
player = User.objects.create_user(username, password=password)
- profile = Profile.objects.get(name__iexact=profile_name)
+ profile = Profile.objects.get(name__iexact="Magicien")
character = create_hurt_character(player, profile)
login(selenium, live_server, username, password)
diff --git a/src/party/models.py b/src/party/models.py
index ff393fe..9ba30de 100644
--- a/src/party/models.py
+++ b/src/party/models.py
@@ -1,5 +1,6 @@
from django.db import models
from django.db.models import Q
+from django.urls import reverse
from django_extensions.db.models import TimeStampedModel
from character.models import Character
@@ -53,3 +54,10 @@ class Party(UniquelyNamedModel, TimeStampedModel, models.Model):
class Meta(UniquelyNamedModel.Meta, TimeStampedModel.Meta):
verbose_name = "Groupe"
verbose_name_plural = "Groupes"
+
+ def get_absolute_url(self) -> str:
+ return reverse("party:details", kwargs={"pk": self.pk})
+
+ def reset_stats(self):
+ for character in self.characters.all():
+ character.reset_stats()
diff --git a/src/party/templates/party/party_details.html b/src/party/templates/party/party_details.html
index 8ea6dad..9f96930 100644
--- a/src/party/templates/party/party_details.html
+++ b/src/party/templates/party/party_details.html
@@ -7,6 +7,9 @@
{% block content %}
{{ party.name }}
MJ : {{ party.game_master.get_full_name|default:party.game_master.username }}
+
+ Réinitialiser les stats
+
Personnages
{% for character in party.characters.all %}
diff --git a/src/party/templates/party/party_reset_stats.html b/src/party/templates/party/party_reset_stats.html
new file mode 100644
index 0000000..835e401
--- /dev/null
+++ b/src/party/templates/party/party_reset_stats.html
@@ -0,0 +1,17 @@
+{% extends "common/base.html" %}
+
+{% block title %}Réinitialisation des stats des membres de {{ party.name }}{% endblock %}
+
+{% block content %}
+
Réinitialisation des stats des membres de {{ party.name }}
+
+{% endblock %}
diff --git a/src/party/tests/test_interactions.py b/src/party/tests/test_interactions.py
index e441c45..889911c 100644
--- a/src/party/tests/test_interactions.py
+++ b/src/party/tests/test_interactions.py
@@ -7,8 +7,8 @@ from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.webdriver import WebDriver
from selenium.webdriver.support.select import Select
-from character.models import Character
-from character.tests.test_interactions import login
+from character.models import Character, Profile
+from character.tests.test_interactions import create_hurt_character, login
from common.models import User
from party.models import Party
@@ -90,3 +90,31 @@ def test_gm_observe_invited_character_in_two_groups(
).click()
title = selenium.find_element(By.TAG_NAME, "h1").text.strip()
assert title == character.name
+
+
+@pytest.mark.django_db
+def test_reset_stats_view(
+ selenium: WebDriver, live_server: LiveServer, initial_data: None
+):
+ user, password = "gm", "password"
+ gm = User.objects.create_user(user, password=password)
+ assert Profile.objects.count() > 1
+ for profile in Profile.objects.all():
+ player = User.objects.create_user(f"user{profile}", password="password")
+ create_hurt_character(player, profile)
+ party = baker.make(Party, game_master=gm)
+ party.characters.set(Character.objects.all())
+
+ login(selenium, live_server, user, password)
+
+ url = reverse("party:details", kwargs={"pk": party.pk})
+ selenium.get(live_server.url + url)
+ selenium.find_element(By.ID, "reset-stats").click()
+ selenium.find_element(By.CSS_SELECTOR, "[type=submit]").click()
+ assert selenium.current_url == live_server.url + party.get_absolute_url()
+
+ for character in Character.objects.all():
+ assert character.health_remaining == character.health_max
+ assert character.mana_remaining == character.mana_max
+ assert character.recovery_points_remaining == character.recovery_points_max
+ assert character.luck_points_remaining == character.luck_points_max
diff --git a/src/party/urls.py b/src/party/urls.py
index cc74dcc..c7c3d8a 100644
--- a/src/party/urls.py
+++ b/src/party/urls.py
@@ -9,6 +9,7 @@ urlpatterns = [
path("
/", views.party_details, name="details"),
path("/change/", views.party_change, name="change"),
path("/delete/", views.party_delete, name="delete"),
+ path("/reset_stats/", views.party_reset_stats, name="reset_stats"),
path("/leave//", views.party_leave, name="leave"),
path("/join//", views.party_join, name="join"),
path("/refuse//", views.party_refuse, name="refuse"),
diff --git a/src/party/views.py b/src/party/views.py
index 8fe6b1d..5fc7a00 100644
--- a/src/party/views.py
+++ b/src/party/views.py
@@ -55,6 +55,19 @@ def party_delete(request, pk):
return render(request, "party/party_delete.html", context)
+@login_required
+def party_reset_stats(request, pk):
+ party = get_object_or_404(Party.objects.managed_by(request.user), pk=pk)
+ context = {"party": party}
+ if request.method == "POST":
+ name = party.name
+ party.reset_stats()
+ message = f"Les stats de tous les membres de {name} ont été réinitialisées."
+ messages.success(request, message)
+ return redirect(party)
+ return render(request, "party/party_reset_stats.html", context)
+
+
@login_required
def party_change(request, pk):
party = get_object_or_404(Party.objects.managed_by(request.user), pk=pk)