Skip to content

Commit 2edfb9e

Browse files
authored
Homework API: raw markdown in questions (#2745)
1 parent 3a4bfaf commit 2edfb9e

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

src/apps/homework/api/serializers/question.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,22 @@
99

1010
class QuestionSerializer(serializers.ModelSerializer):
1111
text = MarkdownField()
12+
markdown_text = serializers.CharField(source="text")
1213

1314
class Meta:
1415
model = Question
1516
fields = [
1617
"slug",
1718
"name",
1819
"text",
20+
"markdown_text",
1921
"deadline",
2022
]
2123

2224

2325
class QuestionDetailSerializer(serializers.ModelSerializer):
2426
text = MarkdownField()
27+
markdown_text = serializers.CharField(source="text")
2528
breadcrumbs = serializers.SerializerMethodField()
2629
homework = HomeworkStatsSerializer(source="*")
2730
course = serializers.SerializerMethodField()
@@ -33,6 +36,7 @@ class Meta:
3336
"slug",
3437
"name",
3538
"text",
39+
"markdown_text",
3640
"deadline",
3741
"homework",
3842
"course",

src/apps/homework/tests/homework/api/questions/tests_question_retrieve.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@ def test_markdown(api, question, course):
3636
got = api.get(f"/api/v2/homework/questions/{question.slug}/")
3737

3838
assert "<em>should be rendered" in got["text"]
39+
assert "*" not in got["text"]
3940
assert "<em>should be rendered" in got["course"]["homework_check_recommendations"]
4041

42+
assert "*" in got["markdown_text"], "The field is not rendered"
43+
assert "<em>" not in got["markdown_text"], "The field is not rendered"
44+
4145

4246
def test_breadcrumbs(api, question, factory, another_course):
4347
Lesson.objects.filter(question=question).delete()

src/apps/lms/tests/api/homework_status_in_lesson_list/test_generic_homework_data.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ def test_question(api, module, question):
2525

2626
assert got["name"] == question.name
2727
assert "<em>" in got["text"], "text is rendered"
28+
assert "<em>" not in got["markdown_text"], "text is not rendered"
29+
assert "*" in got["markdown_text"], "text is not rendered"
2830

2931

3032
@pytest.mark.xfail(reason="Moved N+1 out of scope, cuz too few real-world users will encounter it")

0 commit comments

Comments
 (0)