From 7488b111262f83ef92546bb4687a2cf45ede24eb Mon Sep 17 00:00:00 2001 From: Nikolas Nyby Date: Fri, 1 Dec 2023 12:18:33 -0500 Subject: [PATCH] WIP --- econplayground/assignment/views.py | 15 +++++++++++++++ .../assignment/assignment_detail_student.html | 7 ++++++- requirements.txt | 2 ++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/econplayground/assignment/views.py b/econplayground/assignment/views.py index 2252c4785..629dcfa31 100644 --- a/econplayground/assignment/views.py +++ b/econplayground/assignment/views.py @@ -21,6 +21,7 @@ CreateView, UpdateView, DeleteView ) from django.shortcuts import get_object_or_404 +from graphviz import Digraph from econplayground.assignment.utils import make_rules from econplayground.main.views import EnsureCsrfCookieMixin from econplayground.main.utils import user_is_instructor @@ -124,6 +125,11 @@ class AssignmentDetailStudentView(LoginRequiredMixin, DetailView): def get_context_data(self, **kwargs): ctx = super().get_context_data(**kwargs) + root = self.object.get_root() + print(root.numchild) + bulk_tree = Step.dump_bulk(parent=root) + root = bulk_tree[0] + score_path = None try: score_path = ScorePath.objects.get( @@ -137,8 +143,17 @@ def get_context_data(self, **kwargs): results = score_path.get_step_results() steps = list(map(lambda x: x.step, results)) + print(root) + graph = Digraph(format='svg') + for step in root.get('children'): + print(step) + graph.edge('Root', str(step.get('id'))) + for substep in step.get('children'): + graph.edge(str(step.get('id')), str(substep.get('id'))) + ctx.update({ 'steps': steps, + 'graph': graph.pipe().decode('utf-8'), }) return ctx diff --git a/econplayground/templates/assignment/assignment_detail_student.html b/econplayground/templates/assignment/assignment_detail_student.html index 952a485a8..6fa8c87ab 100644 --- a/econplayground/templates/assignment/assignment_detail_student.html +++ b/econplayground/templates/assignment/assignment_detail_student.html @@ -27,11 +27,16 @@

{{ object.title }}

Welcome to assignment {{object.pk}}! +
+ {{ graph | safe }} +
+ Your path: -
+
{% for step in steps %}
+ {{forloop.counter}}. Step {{step.pk}} diff --git a/requirements.txt b/requirements.txt index b7ac178a2..c0d123b24 100644 --- a/requirements.txt +++ b/requirements.txt @@ -110,3 +110,5 @@ pyparsing==3.1.1 django-s3sign==0.4.0 django-treebeard==4.7 + +graphviz==0.20.1