2019-12-29 18:29:49 +01:00
|
|
|
from django.http import HttpResponse
|
2021-01-06 20:17:25 +01:00
|
|
|
from django.views.generic import ListView
|
2019-12-16 01:02:26 +01:00
|
|
|
|
2019-12-29 18:29:49 +01:00
|
|
|
from wiki_groups.models import WikiGroup
|
|
|
|
|
|
|
|
|
|
|
|
def dot_graph(request):
|
|
|
|
response = HttpResponse(content_type="text/vnd.graphviz")
|
|
|
|
response["Content-Disposition"] = 'attachment; filename="groups.dot"'
|
|
|
|
|
|
|
|
response.write("digraph {\n")
|
|
|
|
nodes = WikiGroup.objects.values_list("id", "django_group__name")
|
|
|
|
edges = WikiGroup.includes_groups.through.objects.values_list(
|
|
|
|
"to_wikigroup", "from_wikigroup"
|
|
|
|
)
|
|
|
|
for id, name in nodes:
|
|
|
|
response.write(' {} ["label"="{}"];\n'.format(id, name))
|
|
|
|
for u, v in edges:
|
|
|
|
response.write(" {} -> {};\n".format(u, v))
|
|
|
|
response.write("}\n")
|
|
|
|
|
|
|
|
return response
|
|
|
|
|
|
|
|
|
2021-01-06 20:17:25 +01:00
|
|
|
class GroupList(ListView):
|
|
|
|
template_name = "wiki_groups/list.html"
|
|
|
|
model = WikiGroup
|
|
|
|
context_object_name = "groups"
|
|
|
|
|
|
|
|
def get_queryset(self):
|
|
|
|
return WikiGroup.objects.values_list("id", "django_group__name").order_by(
|
|
|
|
"django_group__name"
|
|
|
|
)
|