On affiche la liste des managers

This commit is contained in:
Tom Hubrecht 2021-10-26 20:01:58 +02:00
parent cc50d540c3
commit 29c5abbc1a
2 changed files with 38 additions and 34 deletions

View file

@ -4,44 +4,49 @@
{% block wiki_site_title %}Groupes - WikiENS{% endblock %} {% block wiki_site_title %}Groupes - WikiENS{% endblock %}
{% block wiki_contents %} {% block wiki_contents %}
<h2>Liste des groupes du wiki</h2> <h2>
Liste des groupes du wiki
{% if request.user.is_staff or request.user.managed_groups.exists %}
<a class="btn btn-primary float-right" href="{% url 'wiki_groups:managed-groups' %}">
Liste des groupes gérés
</a>
{% endif %}
</h2>
<hr>
<hr /> <ul>
{% for group in wikigroup_list %}
<li>{{ group.django_group.name }} {% if group.managers.exists %}(Géré par {% for m in group.managers.all %}{{ m }}{% if not forloop.last %}, {% endif %}{% endfor %}){% endif %}</li>
{% endfor %}
</ul>
<ul> <h2>Graphe des groupes du wiki</h2>
{% for id, name in groups %} <hr>
<li>{{name}}</li>
{% endfor %}
</ul>
<h2>Graphe des groupes du wiki</h2> <div id="svg-graph"></div>
<hr>
<hr /> <p>
Les flèches représentent l'inclusion : <code>A -&gt; B</code> signifie que
le groupe <code>A</code> est contenu dans le groupe <code>B</code>.
</p>
<div id="svg-graph"></div> <script src="{% static 'wiki_groups/js/vendor/viz.js' %}"></script>
<script src="{% static 'wiki_groups/js/vendor/lite.render.js' %}"></script>
<script>
var viz = new Viz();
<hr /> var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
<p> if (this.readyState == 4 && this.status == 200) {
Les flèches représentent l'inclusion : <code>A -&gt; B</code> signifie que viz.renderSVGElement(this.responseText)
le groupe <code>A</code> est contenu dans le groupe <code>B</code>.
</p>
<script src="{% static 'wiki_groups/js/vendor/viz.js' %}"></script>
<script src="{% static 'wiki_groups/js/vendor/lite.render.js' %}"></script>
<script>
var viz = new Viz();
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
viz.renderSVGElement(this.responseText)
.then(element => { .then(element => {
document.getElementById("svg-graph").appendChild(element); document.getElementById("svg-graph").appendChild(element);
}) })
} }
}; };
xhttp.open("GET", "{% url 'wiki_groups:dot_graph' %}", true); xhttp.open('GET', '{% url 'wiki_groups:dot_graph' %}', true);
xhttp.send(); xhttp.send();
</script>
</script>
{% endblock %} {% endblock %}

View file

@ -2,7 +2,7 @@ from django.contrib.auth import get_user_model
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
from django.http import HttpResponse, HttpResponseRedirect from django.http import HttpResponse, HttpResponseRedirect
from django.urls import reverse, reverse_lazy from django.urls import reverse, reverse_lazy
from django.views.generic import DetailView, ListView, RedirectView, TemplateView from django.views.generic import DetailView, ListView, RedirectView
from django.views.generic.detail import SingleObjectMixin from django.views.generic.detail import SingleObjectMixin
from django.views.generic.edit import BaseFormView from django.views.generic.edit import BaseFormView
@ -33,10 +33,9 @@ def dot_graph(request):
class GroupList(ListView): class GroupList(ListView):
template_name = "wiki_groups/list.html" template_name = "wiki_groups/list.html"
model = WikiGroup model = WikiGroup
context_object_name = "groups"
def get_queryset(self): def get_queryset(self):
return WikiGroup.objects.values_list("id", "django_group__name").order_by( return WikiGroup.objects.select_related("django_group").order_by(
"django_group__name" "django_group__name"
) )