mirror of
https://github.com/Findus23/RPGnotes.git
synced 2024-09-19 15:43:45 +02:00
39 lines
873 B
Python
39 lines
873 B
Python
|
from django.http import JsonResponse, HttpRequest, HttpResponse
|
||
|
from django.views.generic import TemplateView
|
||
|
|
||
|
from locations.models import Location
|
||
|
from notes.models import Note
|
||
|
|
||
|
|
||
|
# @dataclass
|
||
|
# class Node:
|
||
|
#
|
||
|
#
|
||
|
# class Graph:
|
||
|
# def __init__(self):
|
||
|
# self.nodes=
|
||
|
|
||
|
class GraphView(TemplateView):
|
||
|
template_name = "graph/graph.jinja"
|
||
|
|
||
|
|
||
|
def get_graph(request: HttpRequest) -> HttpResponse:
|
||
|
nodes = []
|
||
|
edges = []
|
||
|
for loc in list(Location.objects.all())+list(Note.objects.all()):
|
||
|
nodes.append({
|
||
|
"key": loc.graphkey,
|
||
|
"attributes": {"label": loc.name}
|
||
|
})
|
||
|
if loc.parent:
|
||
|
edges.append({
|
||
|
"source": loc.graphkey,
|
||
|
"target": loc.parent.graphkey
|
||
|
})
|
||
|
|
||
|
return JsonResponse({
|
||
|
"attributes": {},
|
||
|
"nodes": nodes,
|
||
|
"edges": edges
|
||
|
})
|