Skip to content

Commit 51e1559

Browse files
comments field - configurable in course now
1 parent 651800a commit 51e1559

7 files changed

Lines changed: 51 additions & 15 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Generated by Django 5.1.7 on 2025-06-18 10:44
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('courses', '0018_course_finished'),
10+
]
11+
12+
operations = [
13+
migrations.RemoveField(
14+
model_name='homework',
15+
name='problems_comments_field',
16+
),
17+
migrations.AddField(
18+
model_name='course',
19+
name='homework_problems_comments_field',
20+
field=models.BooleanField(default=False, help_text='Include field for problems and comments in homework'),
21+
),
22+
]

courses/models/course.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ class Course(models.Model):
4242
help_text="The URL of the FAQ document for the course.",
4343
)
4444

45+
homework_problems_comments_field = models.BooleanField(
46+
default=False,
47+
help_text="Include field for problems and comments in homework",
48+
)
49+
4550
def __str__(self):
4651
return self.title
4752

courses/models/homework.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ class Homework(models.Model):
3939
default=True,
4040
help_text="Include field for time spent on homework",
4141
)
42-
problems_comments_field = models.BooleanField(
43-
default=True,
44-
help_text="Include field for problems and comments",
45-
)
42+
4643
faq_contribution_field = models.BooleanField(
4744
default=True, help_text="Include field for FAQ contributions"
4845
)

courses/templates/homework/homework.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,20 @@ <h3 class="mb-3">Questions</h3>
201201
</div>
202202
{% endif %}
203203

204+
{% if course.homework_problems_comments_field %}
205+
<div class="mb-3 question">
206+
<label for="problems_comments" class="question-text">
207+
Problems or comments <span class="text-muted">(optional)</span>
208+
</label>
209+
<textarea
210+
class="form-control"
211+
name="problems_comments"
212+
id="problems_comments"
213+
{% if disabled %} disabled {% endif %}
214+
>{{ submission.problems_comments|default:'' }}</textarea>
215+
</div>
216+
{% endif %}
217+
204218
{% if course.faq_document_url and homework.faq_contribution_field %}
205219
<div class="mb-3 question">
206220
<label for="faq_contribution" class="question-text">

courses/tests/test_data.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,6 @@ def test_homework_data_view(self):
151151
actual_result["homework"]["time_spent_homework_field"],
152152
self.homework.time_spent_homework_field,
153153
)
154-
self.assertEqual(
155-
actual_result["homework"]["problems_comments_field"],
156-
self.homework.problems_comments_field,
157-
)
158154
self.assertEqual(
159155
actual_result["homework"]["faq_contribution_field"],
160156
self.homework.faq_contribution_field,

courses/tests/test_homework.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,9 @@ def test_homework_detail_with_scored_homework(self):
449449

450450
# make sure we have the latest version of the homework
451451
self.homework = Homework.objects.get(id=self.homework.id)
452-
self.assertEqual(self.homework.state, HomeworkState.SCORED.value)
452+
self.assertEqual(
453+
self.homework.state, HomeworkState.SCORED.value
454+
)
453455
self.assertTrue(self.homework.is_scored())
454456

455457
self.client.login(**credentials)
@@ -814,13 +816,14 @@ def test_homework_detail_submission_post_with_submissions(
814816
self.assertEqual(answer6.answer_text, "1,2")
815817

816818
def test_submit_homework_with_all_fields(self):
819+
self.course.homework_problems_comments_field = True
820+
self.course.save()
821+
817822
self.homework.homework_url_field = True
818823
self.homework.learning_in_public_cap = 7
819824
self.homework.time_spent_lectures_field = True
820825
self.homework.time_spent_homework_field = True
821-
self.homework.problems_comments_field = True
822826
self.homework.faq_contribution_field = True
823-
824827
self.homework.save()
825828

826829
self.client.login(**credentials)
@@ -969,8 +972,7 @@ def test_submit_homework_learning_in_public_empty_and_duplicates(
969972
"learning_in_public_links[]": [
970973
"https://httpbin.org/status/200",
971974
"https://httpbin.org/status/200",
972-
"https://github.com/DataTalksClub"
973-
"",
975+
"https://github.com/DataTalksClub",
974976
],
975977
}
976978

@@ -993,7 +995,7 @@ def test_submit_homework_learning_in_public_empty_and_duplicates(
993995

994996
expected_learning_in_public_links = [
995997
"https://httpbin.org/status/200",
996-
"https://github.com/DataTalksClub"
998+
"https://github.com/DataTalksClub",
997999
]
9981000
self.assertEqual(
9991001
submission.learning_in_public_links,

courses/views/homework.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def process_homework_submission(
237237
):
238238
submission.time_spent_homework = float(time_spent_homework)
239239

240-
if homework.problems_comments_field:
240+
if course.homework_problems_comments_field:
241241
problems_comments = request.POST.get("problems_comments", "")
242242
submission.problems_comments = problems_comments.strip()
243243

0 commit comments

Comments
 (0)