Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolas committed Dec 1, 2023
1 parent c48aec6 commit 7488b11
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
15 changes: 15 additions & 0 deletions econplayground/assignment/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@ <h1>{{ object.title }}</h1>
Welcome to assignment {{object.pk}}!
</div>

<div class="ep-assignment-graph">
{{ graph | safe }}
</div>

Your path:

<div class="ep-score-path">
<div class="ep-score-path w-50">
{% for step in steps %}
<div class="assignment-step">
{{forloop.counter}}.
<a href="{% url 'step_detail' object.pk step.pk %}">
Step {{step.pk}}
</a>
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,5 @@ pyparsing==3.1.1
django-s3sign==0.4.0

django-treebeard==4.7

graphviz==0.20.1

0 comments on commit 7488b11

Please sign in to comment.