Skip to content

Commit f577e8e

Browse files
Add homework submission edit functionality
Co-authored-by: alexeygrigorev <875246+alexeygrigorev@users.noreply.github.com>
1 parent 7557d13 commit f577e8e

5 files changed

Lines changed: 517 additions & 0 deletions

File tree

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
{% extends 'cadmin/base.html' %}
2+
3+
{% load custom_filters %}
4+
5+
{% block breadcrumbs %}
6+
<li><a href="{% url 'cadmin_course_list' %}">Course Admin</a></li>
7+
<li><a href="{% url 'cadmin_course' course.slug %}">{{ course.title }}</a></li>
8+
<li><a href="{% url 'cadmin_homework_submissions' course.slug homework.slug %}">{{ homework.title }} Submissions</a></li>
9+
<li><a href="{% url 'cadmin_homework_submission_edit' course.slug homework.slug submission.id %}">Edit Submission</a></li>
10+
{% endblock %}
11+
12+
{% block cadmin_content %}
13+
<h2>Edit Homework Submission</h2>
14+
15+
<div class="mb-3">
16+
<a href="{% url 'cadmin_homework_submissions' course.slug homework.slug %}" class="btn btn-secondary">Back to Submissions</a>
17+
</div>
18+
19+
<div class="alert alert-info" role="alert">
20+
<strong>Student:</strong> {{ submission.student.username }} ({{ submission.student.email }})<br>
21+
<strong>Homework:</strong> {{ homework.title }}<br>
22+
<strong>Submitted:</strong> {{ submission.submitted_at|date:"Y-m-d H:i" }}<br>
23+
<strong>Current Total Score:</strong> {{ submission.total_score }}
24+
</div>
25+
26+
<form method="post">
27+
{% csrf_token %}
28+
29+
<div class="card mb-3">
30+
<div class="card-header">
31+
<h4>Question Answers</h4>
32+
</div>
33+
<div class="card-body">
34+
{% if questions_with_answers %}
35+
{% for item in questions_with_answers %}
36+
<div class="card mb-3 border-secondary">
37+
<div class="card-header bg-light">
38+
<strong>Question {{ forloop.counter }}:</strong> {{ item.question.text }}
39+
</div>
40+
<div class="card-body">
41+
<div class="mb-2">
42+
<strong>Question Type:</strong> {{ item.question.get_question_type_display }}<br>
43+
{% if item.question.correct_answer %}
44+
<strong>Correct Answer:</strong> {{ item.question.correct_answer }}
45+
{% endif %}
46+
</div>
47+
48+
{% if item.question.question_type == "MC" %}
49+
{# Multiple choice question #}
50+
<div class="form-group">
51+
<label for="answer_{{ item.question.id }}">Answer (option number):</label>
52+
<input type="text"
53+
class="form-control"
54+
id="answer_{{ item.question.id }}"
55+
name="answer_{{ item.question.id }}"
56+
value="{{ item.answer_text }}"
57+
placeholder="Enter option number">
58+
{% if item.question.possible_answers %}
59+
<small class="form-text text-muted">
60+
Options:
61+
{% for option in item.question.get_possible_answers %}
62+
{{ forloop.counter }}. {{ option }}{% if not forloop.last %}, {% endif %}
63+
{% endfor %}
64+
</small>
65+
{% endif %}
66+
</div>
67+
{% elif item.question.question_type == "CB" %}
68+
{# Checkbox question #}
69+
<div class="form-group">
70+
<label for="answer_{{ item.question.id }}">Answer (comma-separated option numbers):</label>
71+
<input type="text"
72+
class="form-control"
73+
id="answer_{{ item.question.id }}"
74+
name="answer_{{ item.question.id }}"
75+
value="{{ item.answer_text }}"
76+
placeholder="e.g., 1,3,4">
77+
{% if item.question.possible_answers %}
78+
<small class="form-text text-muted">
79+
Options:
80+
{% for option in item.question.get_possible_answers %}
81+
{{ forloop.counter }}. {{ option }}{% if not forloop.last %}, {% endif %}
82+
{% endfor %}
83+
</small>
84+
{% endif %}
85+
</div>
86+
{% elif item.question.question_type == "FL" %}
87+
{# Free form long #}
88+
<div class="form-group">
89+
<label for="answer_{{ item.question.id }}">Answer:</label>
90+
<textarea class="form-control"
91+
id="answer_{{ item.question.id }}"
92+
name="answer_{{ item.question.id }}"
93+
rows="4">{{ item.answer_text }}</textarea>
94+
</div>
95+
{% else %}
96+
{# Free form or other #}
97+
<div class="form-group">
98+
<label for="answer_{{ item.question.id }}">Answer:</label>
99+
<input type="text"
100+
class="form-control"
101+
id="answer_{{ item.question.id }}"
102+
name="answer_{{ item.question.id }}"
103+
value="{{ item.answer_text }}">
104+
</div>
105+
{% endif %}
106+
107+
{% if item.answer %}
108+
<div class="mt-2">
109+
<span class="badge {% if item.answer.is_correct %}badge-success{% else %}badge-danger{% endif %}">
110+
{% if item.answer.is_correct %}Correct{% else %}Incorrect{% endif %}
111+
</span>
112+
</div>
113+
{% endif %}
114+
</div>
115+
</div>
116+
{% endfor %}
117+
{% else %}
118+
<p class="text-muted">No questions found for this homework.</p>
119+
{% endif %}
120+
</div>
121+
</div>
122+
123+
<div class="card mb-3">
124+
<div class="card-header">
125+
<h4>Learning in Public Links</h4>
126+
</div>
127+
<div class="card-body">
128+
<div class="form-group">
129+
<label for="learning_in_public_links">Links (comma-separated):</label>
130+
<textarea class="form-control"
131+
id="learning_in_public_links"
132+
name="learning_in_public_links"
133+
rows="3"
134+
placeholder="https://example.com/post1, https://example.com/post2">{% if submission.learning_in_public_links %}{{ submission.learning_in_public_links|join:", " }}{% endif %}</textarea>
135+
<small class="form-text text-muted">
136+
Enter URLs separated by commas. Each link contributes to the learning in public score (capped at {{ homework.learning_in_public_cap }}).
137+
</small>
138+
</div>
139+
</div>
140+
</div>
141+
142+
<div class="card mb-3">
143+
<div class="card-header">
144+
<h4>Current Scores (Read-Only)</h4>
145+
</div>
146+
<div class="card-body">
147+
<div class="row">
148+
<div class="col-md-3">
149+
<div class="form-group">
150+
<label>Questions Score</label>
151+
<input type="text" class="form-control" value="{{ submission.questions_score }}" readonly>
152+
</div>
153+
</div>
154+
<div class="col-md-3">
155+
<div class="form-group">
156+
<label>FAQ Score</label>
157+
<input type="text" class="form-control" value="{{ submission.faq_score }}" readonly>
158+
</div>
159+
</div>
160+
<div class="col-md-3">
161+
<div class="form-group">
162+
<label>Learning in Public Score</label>
163+
<input type="text" class="form-control" value="{{ submission.learning_in_public_score }}" readonly>
164+
</div>
165+
</div>
166+
<div class="col-md-3">
167+
<div class="form-group">
168+
<label>Total Score</label>
169+
<input type="text" class="form-control" value="{{ submission.total_score }}" readonly>
170+
</div>
171+
</div>
172+
</div>
173+
<small class="form-text text-muted">
174+
Scores will be automatically recalculated when you save. If the total score changes, the leaderboard will be updated.
175+
</small>
176+
</div>
177+
</div>
178+
179+
<div class="text-center">
180+
<button type="submit" class="btn btn-primary">Save Changes</button>
181+
<a href="{% url 'cadmin_homework_submissions' course.slug homework.slug %}" class="btn btn-secondary">Cancel</a>
182+
</div>
183+
</form>
184+
185+
{% endblock %}

cadmin/templates/cadmin/homework_submissions.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ <h2>{{ homework.title }} - Submissions</h2>
7070
</td>
7171
{% endfor %}
7272
<td>
73+
<a href="{% url 'cadmin_homework_submission_edit' course.slug homework.slug data.submission.id %}"
74+
class="btn btn-sm btn-primary"
75+
title="Edit submission">
76+
<i class="fas fa-edit"></i> Edit
77+
</a>
7378
<form method="post" action="{% url 'loginas-user-login' data.submission.student.id %}" style="display: inline;">
7479
{% csrf_token %}
7580
<input type="hidden" name="next" value="{% url 'cadmin_homework_submissions' course.slug homework.slug %}">

0 commit comments

Comments
 (0)