mirror of
https://github.com/Crocmagnon/charasheet.git
synced 2024-11-22 22:48:03 +01:00
Allow responding to invites
This commit is contained in:
parent
199ed66ddb
commit
ba33291972
5 changed files with 70 additions and 16 deletions
|
@ -23,21 +23,28 @@
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
</p>
|
</p>
|
||||||
<div class="btn-group btn-group-sm">
|
<div class="btn-group btn-group-sm">
|
||||||
{% if character|managed_by:user %}
|
|
||||||
{% if character.player == user %}
|
{% if character.player == user %}
|
||||||
<a href="{% url "character:view" pk=character.pk %}" class="btn btn-success">
|
<a href="{% url "character:view" pk=character.pk %}" class="btn btn-success">
|
||||||
<i class="fa-solid fa-user"></i> Jouer
|
<i class="fa-solid fa-user"></i> Jouer
|
||||||
</a>
|
</a>
|
||||||
{% else %}
|
{% if party %}
|
||||||
<a href="{% url "character:view" pk=character.pk %}" class="btn btn-primary">
|
{% if character in party.characters.all %}
|
||||||
<i class="fa-solid fa-cog"></i> Gérer
|
|
||||||
</a>
|
|
||||||
{% endif %}
|
|
||||||
{% 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>
|
||||||
|
{% elif character in party.invited_characters.all %}
|
||||||
|
<a href="{% url "party:join" pk=party.pk character_pk=character.pk %}" class="btn btn-primary">
|
||||||
|
<i class="fa-solid fa-check"></i> Rejoindre
|
||||||
|
</a>
|
||||||
|
<a href="{% url "party:refuse" pk=party.pk character_pk=character.pk %}" class="btn btn-warning">
|
||||||
|
<i class="fa-solid fa-person-walking-arrow-right"></i> Refuser l'invitation
|
||||||
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
{% elif character|managed_by:user %}
|
||||||
|
<a href="{% url "character:view" pk=character.pk %}" class="btn btn-primary">
|
||||||
|
<i class="fa-solid fa-cog"></i> Gérer
|
||||||
|
</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-eye"></i> Observer
|
<i class="fa-solid fa-eye"></i> Observer
|
||||||
|
|
|
@ -19,6 +19,9 @@ class PartyQuerySet(models.QuerySet):
|
||||||
| Q(characters__in=Character.objects.filter(player=user))
|
| Q(characters__in=Character.objects.filter(player=user))
|
||||||
).distinct()
|
).distinct()
|
||||||
|
|
||||||
|
def invited_to(self, user):
|
||||||
|
return self.filter(invited_characters__in=Character.objects.filter(player=user))
|
||||||
|
|
||||||
|
|
||||||
class PartyManager(UniquelyNamedModelManager):
|
class PartyManager(UniquelyNamedModelManager):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -39,7 +39,25 @@
|
||||||
<h2 class="mt-3">Groupes dont vous êtes membre</h2>
|
<h2 class="mt-3">Groupes dont vous êtes membre</h2>
|
||||||
<div class="row row-cols-1 row-cols-sm-2 row-cols-md-3 row-cols-lg-4 g-4">
|
<div class="row row-cols-1 row-cols-sm-2 row-cols-md-3 row-cols-lg-4 g-4">
|
||||||
{% for party in played_parties %}
|
{% for party in played_parties %}
|
||||||
|
<div class="col">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">
|
||||||
|
{{ party.name }}
|
||||||
|
</h5>
|
||||||
|
<a href="{% url "party:details" pk=party.pk %}" class="btn btn-sm btn-success">
|
||||||
|
<i class="fa-solid fa-users"></i> Accéder
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% empty %}
|
||||||
|
<div class="col">Aucun</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
<h2 class="mt-3">Groupes auxquels vous avez été invités</h2>
|
||||||
|
<div class="row row-cols-1 row-cols-sm-2 row-cols-md-3 row-cols-lg-4 g-4">
|
||||||
|
{% for party in invited_to %}
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
|
|
|
@ -10,4 +10,6 @@ urlpatterns = [
|
||||||
path("<int:pk>/change/", views.party_change, name="change"),
|
path("<int:pk>/change/", views.party_change, name="change"),
|
||||||
path("<int:pk>/delete/", views.party_delete, name="delete"),
|
path("<int:pk>/delete/", views.party_delete, name="delete"),
|
||||||
path("<int:pk>/leave/<int:character_pk>/", views.party_leave, name="leave"),
|
path("<int:pk>/leave/<int:character_pk>/", views.party_leave, name="leave"),
|
||||||
|
path("<int:pk>/join/<int:character_pk>/", views.party_join, name="join"),
|
||||||
|
path("<int:pk>/refuse/<int:character_pk>/", views.party_refuse, name="refuse"),
|
||||||
]
|
]
|
||||||
|
|
|
@ -12,6 +12,7 @@ def parties_list(request):
|
||||||
context = {
|
context = {
|
||||||
"managed_parties": Party.objects.managed_by(request.user),
|
"managed_parties": Party.objects.managed_by(request.user),
|
||||||
"played_parties": Party.objects.played_by(request.user).distinct(),
|
"played_parties": Party.objects.played_by(request.user).distinct(),
|
||||||
|
"invited_to": Party.objects.invited_to(request.user).distinct(),
|
||||||
}
|
}
|
||||||
return render(request, "party/parties_list.html", context)
|
return render(request, "party/parties_list.html", context)
|
||||||
|
|
||||||
|
@ -72,7 +73,7 @@ def party_change(request, pk):
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def party_leave(request, pk, character_pk):
|
def party_leave(request, pk, character_pk):
|
||||||
party = get_object_or_404(Party.objects.managed_by(request.user), pk=pk)
|
party = get_object_or_404(Party.objects.played_by(request.user).distinct(), pk=pk)
|
||||||
character = get_object_or_404(
|
character = get_object_or_404(
|
||||||
Character.objects.owned_by(request.user), pk=character_pk
|
Character.objects.owned_by(request.user), pk=character_pk
|
||||||
)
|
)
|
||||||
|
@ -82,3 +83,26 @@ def party_leave(request, pk, character_pk):
|
||||||
messages.success(request, f"{character} a quitté le groupe {party}.")
|
messages.success(request, f"{character} a quitté le groupe {party}.")
|
||||||
return redirect("party:list")
|
return redirect("party:list")
|
||||||
return render(request, "party/party_leave.html", context)
|
return render(request, "party/party_leave.html", context)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def party_join(request, pk, character_pk):
|
||||||
|
party = get_object_or_404(Party.objects.invited_to(request.user).distinct(), pk=pk)
|
||||||
|
character = get_object_or_404(
|
||||||
|
Character.objects.owned_by(request.user), pk=character_pk
|
||||||
|
)
|
||||||
|
party.characters.add(character)
|
||||||
|
party.invited_characters.remove(character)
|
||||||
|
messages.success(request, f"{character} a rejoint le groupe {party}.")
|
||||||
|
return redirect("party:list")
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def party_refuse(request, pk, character_pk):
|
||||||
|
party = get_object_or_404(Party.objects.invited_to(request.user).distinct(), pk=pk)
|
||||||
|
character = get_object_or_404(
|
||||||
|
Character.objects.owned_by(request.user), pk=character_pk
|
||||||
|
)
|
||||||
|
party.invited_characters.remove(character)
|
||||||
|
messages.success(request, f"{character} a refusé l'invitation au groupe {party}.")
|
||||||
|
return redirect("party:list")
|
||||||
|
|
Loading…
Reference in a new issue