1
0
Fork 0
mirror of https://github.com/Findus23/RPGnotes.git synced 2024-09-19 15:43:45 +02:00
RPGnotes/graph/views.py

39 lines
873 B
Python
Raw Normal View History

2022-11-19 22:09:15 +01:00
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
})