Rajoute la création de groupes de manière plus simple pour les admins #25
3 changed files with 53 additions and 4 deletions
|
@ -4,7 +4,10 @@
|
||||||
{% block wiki_site_title %}Groupes administrés - WikiENS{% endblock %}
|
{% block wiki_site_title %}Groupes administrés - WikiENS{% endblock %}
|
||||||
|
|
||||||
{% block wiki_contents %}
|
{% block wiki_contents %}
|
||||||
<h2>Gestion du groupe « {{ wikigroup }} »</h2>
|
<h2>
|
||||||
|
Gestion du groupe « {{ wikigroup }} »
|
||||||
|
<a class="btn btn-dark float-right" href="{% url 'wiki_groups:managed-groups' %}">Retour</a>
|
||||||
|
</h2>
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
|
|
@ -6,6 +6,25 @@
|
||||||
<h2>Liste des groupes administrés</h2>
|
<h2>Liste des groupes administrés</h2>
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
|
{% if request.user.is_staff %}
|
||||||
|
<form method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
<div class="input-group">
|
||||||
|
<input type="text" class="form-control {% if form.errors %}is-invalid{% endif %}" name="group" value="{% if form.group.value %}{{ form.group.value }}{% endif %}" placeholder="Créer un nouveau un groupe">
|
||||||
|
<div class="input-group-append">
|
||||||
|
<button type="submit" class="btn btn-primary rounded-right">Créer</button>
|
||||||
|
</div>
|
||||||
|
{% if form.group.errors %}
|
||||||
|
{% for error in form.group.errors %}
|
||||||
|
<div class="invalid-feedback">{{ error }}</div>
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
<small class="form-text text-muted">Entrer le nom du groupe à créer</small>
|
||||||
|
</form>
|
||||||
|
<br>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if wikigroup_list %}
|
{% if wikigroup_list %}
|
||||||
<div class="list-group">
|
<div class="list-group">
|
||||||
{% for group in wikigroup_list %}
|
{% for group in wikigroup_list %}
|
||||||
|
@ -14,5 +33,4 @@
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -63,10 +63,17 @@ class StaffMixin(UserPassesTestMixin):
|
||||||
return self.request.user.is_staff
|
return self.request.user.is_staff
|
||||||
|
|
||||||
|
|
||||||
class ManagedGroupsView(LoginRequiredMixin, ListView):
|
class ManagedGroupsView(LoginRequiredMixin, BaseFormView, ListView):
|
||||||
|
"""Displays the list of managed groups and allows creating new groups"""
|
||||||
|
|
||||||
model = WikiGroup
|
model = WikiGroup
|
||||||
template_name = "wiki_groups/managed.html"
|
template_name = "wiki_groups/managed.html"
|
||||||
|
|
||||||
|
form_class = CreateGroupForm
|
||||||
|
|
||||||
|
def get_success_url(self):
|
||||||
|
return reverse("wiki_groups:admin-group", args=[self.group_pk])
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
if self.request.user.is_staff:
|
if self.request.user.is_staff:
|
||||||
return WikiGroup.objects.select_related("django_group")
|
return WikiGroup.objects.select_related("django_group")
|
||||||
|
@ -84,6 +91,24 @@ class ManagedGroupsView(LoginRequiredMixin, ListView):
|
||||||
|
|
||||||
return ctx
|
return ctx
|
||||||
|
|
||||||
|
def post(self, request, *args, **kwargs):
|
||||||
|
form = self.get_form()
|
||||||
|
|
||||||
|
# Only the staff can create new groups
|
||||||
|
if self.user.is_staff and form.is_valid():
|
||||||
|
return self.form_valid(form)
|
||||||
|
|
||||||
|
return self.form_invalid(form)
|
||||||
|
|
||||||
|
def form_valid(self, form):
|
||||||
|
self.group_pk = form.cleaned_data["group"].pk
|
||||||
|
return super().form_valid(form)
|
||||||
|
|
||||||
|
def form_invalid(self, form):
|
||||||
|
self.object_list = self.get_queryset()
|
||||||
|
|
||||||
|
return super().form_invalid(form)
|
||||||
|
|
||||||
|
|
||||||
class WikiGroupView(WikiGroupMixin, DetailView):
|
class WikiGroupView(WikiGroupMixin, DetailView):
|
||||||
template_name = "wiki_groups/admin.html"
|
template_name = "wiki_groups/admin.html"
|
||||||
|
@ -214,7 +239,10 @@ class CreateGroupView(WikiGroupMixin, BaseFormView):
|
||||||
new_group = form.cleaned_data["group"]
|
new_group = form.cleaned_data["group"]
|
||||||
|
|
||||||
self.object.includes_groups.add(new_group)
|
self.object.includes_groups.add(new_group)
|
||||||
new_group.managers.add(self.request.user)
|
|
||||||
|
# On ne met pas les admins dans les managers explicites
|
||||||
|
if not self.request.user.is_staff:
|
||||||
|
new_group.managers.add(self.request.user)
|
||||||
|
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue