mirror of
https://github.com/Crocmagnon/charasheet.git
synced 2024-11-22 22:48:03 +01:00
Allow inviting characters to group
This commit is contained in:
parent
3cf359744a
commit
199ed66ddb
6 changed files with 60 additions and 4 deletions
|
@ -29,12 +29,11 @@
|
||||||
<i class="fa-solid fa-user"></i> Jouer
|
<i class="fa-solid fa-user"></i> Jouer
|
||||||
</a>
|
</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|
||||||
<a href="{% url "character:view" pk=character.pk %}" class="btn btn-primary">
|
<a href="{% url "character:view" pk=character.pk %}" class="btn btn-primary">
|
||||||
<i class="fa-solid fa-cog"></i> Gérer
|
<i class="fa-solid fa-cog"></i> Gérer
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if party %}
|
{% if party and character in party.characters.all %}
|
||||||
<a href="{% url "party:leave" pk=party.pk character_pk=character.pk %}" class="btn btn-warning">
|
<a href="{% url "party:leave" pk=party.pk character_pk=character.pk %}" class="btn btn-warning">
|
||||||
<i class="fa-solid fa-person-walking-arrow-right"></i> Quitter le groupe
|
<i class="fa-solid fa-person-walking-arrow-right"></i> Quitter le groupe
|
||||||
</a>
|
</a>
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from django import forms
|
from django import forms
|
||||||
|
from django.core.exceptions import ValidationError
|
||||||
|
|
||||||
from party.models import Party
|
from party.models import Party
|
||||||
|
|
||||||
|
@ -6,4 +7,17 @@ from party.models import Party
|
||||||
class PartyForm(forms.ModelForm):
|
class PartyForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Party
|
model = Party
|
||||||
fields = ["name", "characters"]
|
fields = ["name", "invited_characters"]
|
||||||
|
|
||||||
|
def clean_invited_characters(self):
|
||||||
|
invited = self.cleaned_data["invited_characters"]
|
||||||
|
if not self.instance:
|
||||||
|
return invited
|
||||||
|
members = self.instance.characters.all()
|
||||||
|
for character in invited:
|
||||||
|
if character in members:
|
||||||
|
self.add_error(
|
||||||
|
"invited_characters",
|
||||||
|
ValidationError(f"{character} is already a group member."),
|
||||||
|
)
|
||||||
|
return invited
|
||||||
|
|
24
src/party/migrations/0002_party_invited_characters.py
Normal file
24
src/party/migrations/0002_party_invited_characters.py
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
# Generated by Django 4.1.2 on 2022-11-06 14:10
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("character", "0036_delete_party"),
|
||||||
|
("party", "0001_initial"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="party",
|
||||||
|
name="invited_characters",
|
||||||
|
field=models.ManyToManyField(
|
||||||
|
blank=True,
|
||||||
|
related_name="invites",
|
||||||
|
to="character.character",
|
||||||
|
verbose_name="personnages invités",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
|
@ -1 +1 @@
|
||||||
0001_initial
|
0002_party_invited_characters
|
||||||
|
|
|
@ -31,6 +31,12 @@ class Party(UniquelyNamedModel, TimeStampedModel, models.Model):
|
||||||
related_name="parties",
|
related_name="parties",
|
||||||
verbose_name="meneur de jeu",
|
verbose_name="meneur de jeu",
|
||||||
)
|
)
|
||||||
|
invited_characters = models.ManyToManyField(
|
||||||
|
"character.Character",
|
||||||
|
blank=True,
|
||||||
|
related_name="invites",
|
||||||
|
verbose_name="personnages invités",
|
||||||
|
)
|
||||||
characters = models.ManyToManyField(
|
characters = models.ManyToManyField(
|
||||||
"character.Character",
|
"character.Character",
|
||||||
blank=True,
|
blank=True,
|
||||||
|
|
|
@ -7,9 +7,22 @@
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>{{ party.name }}</h1>
|
<h1>{{ party.name }}</h1>
|
||||||
<p>MJ : {{ party.game_master.get_full_name|default:party.game_master.username }}</p>
|
<p>MJ : {{ party.game_master.get_full_name|default:party.game_master.username }}</p>
|
||||||
|
<h2>Personnages</h2>
|
||||||
<div class="row row-cols-1 row-cols-md-2 row-cols-lg-3 row-cols-xl-4 g-4">
|
<div class="row row-cols-1 row-cols-md-2 row-cols-lg-3 row-cols-xl-4 g-4">
|
||||||
{% for character in party.characters.all %}
|
{% for character in party.characters.all %}
|
||||||
{% include "character/snippets/characters_list/character_card.html" %}
|
{% include "character/snippets/characters_list/character_card.html" %}
|
||||||
|
{% empty %}
|
||||||
|
<p>Aucun...</p>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
{% with party.invited_characters.all as invites %}
|
||||||
|
{% if invites %}
|
||||||
|
<h2>Invités</h2>
|
||||||
|
<div class="row row-cols-1 row-cols-md-2 row-cols-lg-3 row-cols-xl-4 g-4">
|
||||||
|
{% for character in invites %}
|
||||||
|
{% include "character/snippets/characters_list/character_card.html" %}
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% endwith %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Loading…
Reference in a new issue