Skip to content

Commit

Permalink
Add assignment student detail view basics
Browse files Browse the repository at this point in the history
A lot more to do here, this just sets up the basic view and various connections.

Also, some of the topics tests required some adjustments with these
changes. I'm not sure why my changes caused the failures here, but
our Topic/django-ordered-model implementation has proven to be quite
fragile.
  • Loading branch information
nikolas committed Nov 28, 2023
1 parent e2c274f commit 8066c2c
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 25 deletions.
12 changes: 12 additions & 0 deletions econplayground/assignment/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,3 +534,15 @@ def test_assignment_step_value_submission(self):

score_path.refresh_from_db()
self.assertEqual(score_path.score, 0.5)


class AssignmentDetailStudentViewTest(
LoggedInTestStudentMixin, AssignmentMixin, TestCase):
def test_assignment_step_view(self):
assignment = self.setup_sample_assignment()
r = self.client.get(reverse('assignment_detail_student', kwargs={
'pk': assignment.pk
}))

self.assertEqual(r.status_code, 200)
self.assertContains(r, assignment.title)
8 changes: 8 additions & 0 deletions econplayground/assignment/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ def get_context_data(self, **kwargs):
return ctx


class AssignmentDetailStudentView(LoginRequiredMixin, DetailView):
"""
Read-only view for working through an assignment.
"""
model = Assignment
template_name = 'assignment/assignment_detail_student.html'


class AssignmentTreeUpdateView(LoginRequiredMixin, UserPassesTestMixin, View):
"""
Add and remove nodes from the assignment tree.
Expand Down
24 changes: 18 additions & 6 deletions econplayground/main/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,8 +748,12 @@ def test_get(self):
self.assertContains(r, 'Topic B')
self.assertEqual(r.context['all_count'], 3)
self.assertEqual(r.context['featured_count'], 2)
self.assertEqual(r.context['topic_list'][0].published_graph_count(), 2)
self.assertEqual(r.context['topic_list'][1].published_graph_count(), 1)

self.t1.refresh_from_db()
self.t2.refresh_from_db()
self.assertEqual(len(r.context['topic_list']), 2)
self.assertEqual(self.t1.published_graph_count(), 2)
self.assertEqual(self.t2.published_graph_count(), 1)

r = self.client.get(
'{}?all=true'.format(
Expand All @@ -769,8 +773,12 @@ def test_get(self):
self.assertContains(r, 'Topic B')
self.assertEqual(r.context['all_count'], 3)
self.assertEqual(r.context['featured_count'], 2)
self.assertEqual(r.context['topic_list'][0].published_graph_count(), 2)
self.assertEqual(r.context['topic_list'][1].published_graph_count(), 1)

self.t1.refresh_from_db()
self.t2.refresh_from_db()
self.assertEqual(len(r.context['topic_list']), 2)
self.assertEqual(self.t1.published_graph_count(), 2)
self.assertEqual(self.t2.published_graph_count(), 1)

r = self.client.get(
'{}?topic={}'.format(
Expand Down Expand Up @@ -815,8 +823,12 @@ def test_get(self):
self.assertContains(r, 'Topic B')
self.assertEqual(r.context['all_count'], 3)
self.assertEqual(r.context['featured_count'], 2)
self.assertEqual(r.context['topic_list'][0].published_graph_count(), 2)
self.assertEqual(r.context['topic_list'][1].published_graph_count(), 1)

self.t1.refresh_from_db()
self.t2.refresh_from_db()
self.assertEqual(len(r.context['topic_list']), 2)
self.assertEqual(self.t1.published_graph_count(), 2)
self.assertEqual(self.t2.published_graph_count(), 1)


class MockLTI(object):
Expand Down
38 changes: 38 additions & 0 deletions econplayground/templates/assignment/assignment_detail_student.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{% extends 'base.html' %}
{% load static %}

{% block title %}{{ object.title }}{% endblock %}

{% block breadcrumb %}
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item">
<a href="{% url 'assignment_list' %}" title="Assignment List">
{% include 'main/your_assignments_snippet.html' %}
</a>
</li>
<li class="breadcrumb-item">
{{ object.title|truncatewords:5 }}
</li>
</ol>
</nav>
{% endblock %}

{% block pagetitle %}
<h1>{{ object.title }}</h1>
{% endblock %}

{% block content %}
<div class="container">
Welcome to assignment {{object.pk}}!
</div>

{% if object.first_step %}
<a href="{% url 'step_detail' object.pk object.first_step.pk %}"
class="btn btn-primary mt-2"
role="button"
title="First question">
First question
</a>
{% endif %}
{% endblock %}
10 changes: 3 additions & 7 deletions econplayground/templates/assignment/assignment_list_student.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@
{% for assignment in assignment_list %}
<tr>
<th scope="row">
{% if assignment.first_step %}
<a href="{% url 'step_detail' assignment.pk assignment.first_step.pk %}"
title="{{assignment.title}}">
{{assignment.title}}
</a>
{% else %}
<a href="{% url 'assignment_detail_student' assignment.pk %}"
title="{{assignment.title}}">
{{assignment.title}}
{% endif %}
</a>
</th>
<td>
{% for cohort in assignment.cohorts.all %}
Expand Down
32 changes: 20 additions & 12 deletions econplayground/templates/assignment/step_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,26 @@
{% endblock %}

{% block breadcrumb %}
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item">
<a href="{% url 'assignment_detail' assignment.pk %}">
{{assignment.title|truncatewords:5}}
</a>
</li>
<li class="breadcrumb-item">
Step {{object.pk}}
</li>
</ol>
</nav>
{% user_is_instructor request.user as i_am_instructor %}

<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item">
{% if i_am_instructor %}
<a href="{% url 'assignment_detail' assignment.pk %}">
{{assignment.title|truncatewords:5}}
</a>
{% else %}
<a href="{% url 'assignment_detail_student' assignment.pk %}">
{{assignment.title|truncatewords:5}}
</a>
{% endif %}
</li>
<li class="breadcrumb-item">
Step {{object.pk}}
</li>
</ol>
</nav>
{% endblock %}

{% block pagetitle %}
Expand Down
3 changes: 3 additions & 0 deletions econplayground/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ def trigger_error(request):
path('assignment/<int:pk>/',
assignment_views.AssignmentDetailView.as_view(),
name='assignment_detail'),
path('assignment/<int:pk>/view/',
assignment_views.AssignmentDetailStudentView.as_view(),
name='assignment_detail_student'),
path('assignment_assignment/<int:pk>/edit/',
assignment_views.AssignmentUpdateView.as_view(),
name='assignment_assignment_edit'),
Expand Down

0 comments on commit 8066c2c

Please sign in to comment.