From 234f1290fc42fee8bc147f89690d9d7d43450a39 Mon Sep 17 00:00:00 2001 From: aintbe Date: Mon, 21 Feb 2022 08:48:17 +0900 Subject: [PATCH] Minor fixes --- ...olved.py => 0005_rename_status_question_is_open.py} | 4 ++-- backend/qna/models.py | 10 +++++----- backend/qna/tests.py | 4 ++-- backend/qna/views/student.py | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) rename backend/qna/migrations/{0005_rename_status_question_is_resolved.py => 0005_rename_status_question_is_open.py} (78%) diff --git a/backend/qna/migrations/0005_rename_status_question_is_resolved.py b/backend/qna/migrations/0005_rename_status_question_is_open.py similarity index 78% rename from backend/qna/migrations/0005_rename_status_question_is_resolved.py rename to backend/qna/migrations/0005_rename_status_question_is_open.py index b6764260b..73b7bf7ce 100644 --- a/backend/qna/migrations/0005_rename_status_question_is_resolved.py +++ b/backend/qna/migrations/0005_rename_status_question_is_open.py @@ -1,4 +1,4 @@ -# Generated by Django 3.2.4 on 2022-02-16 06:48 +# Generated by Django 3.2.4 on 2022-02-20 23:43 from django.db import migrations @@ -13,6 +13,6 @@ class Migration(migrations.Migration): migrations.RenameField( model_name='question', old_name='status', - new_name='is_resolved', + new_name='is_open', ), ] diff --git a/backend/qna/models.py b/backend/qna/models.py index b0a0c4f22..11a6244f8 100644 --- a/backend/qna/models.py +++ b/backend/qna/models.py @@ -17,7 +17,7 @@ class Question(models.Model): content = models.TextField() create_time = models.DateTimeField(auto_now_add=True) last_update_time = models.DateTimeField(auto_now=True) - is_resolved = models.BooleanField(default=True) + is_open = models.BooleanField(default=True) class Meta: db_table = "question" @@ -32,6 +32,10 @@ class Answer(models.Model): last_update_time = models.DateTimeField(auto_now=True) admin_type = models.TextField(default=AdminType.NONE) + class Meta: + db_table = "answer" + ordering = ("-create_time",) + def update_admin_type(self, user): if user.is_authenticated and user.is_admin_role(): self.admin_type = AdminType.PROFESSOR @@ -43,7 +47,3 @@ def name(self): if self.admin_type == AdminType.PROFESSOR: return self.created_by.userprofile.real_name return self.created_by.username - - class Meta: - db_table = "answer" - ordering = ("-create_time",) diff --git a/backend/qna/tests.py b/backend/qna/tests.py index f226dcc0f..02df4a781 100644 --- a/backend/qna/tests.py +++ b/backend/qna/tests.py @@ -92,7 +92,7 @@ def setUp(self): def create_question(self): self.professor = self.create_admin(login=False) course_id = Course.objects.create(created_by=self.professor, **DEFAULT_COURSE_DATA).id - return Question.objects.create(created_by_id=self.user.id, course_id=course_id, title="title", content="content", status=True).id + return Question.objects.create(created_by_id=self.user.id, course_id=course_id, title="title", content="content", is_open=True).id def test_create_answer(self): response = self.client.post(self.url, data=self.data) @@ -122,7 +122,7 @@ def test_question_closure(self): self.data.update({"closure": True}) response = self.client.post(self.url, data=self.data) self.assertSuccess(response) - self.assertFalse(Question.objects.get(id=self.question_id).status) + self.assertFalse(Question.objects.get(id=self.question_id).is_open) def test_unauthorized_closure(self): self.create_user("2020700000", "pass") diff --git a/backend/qna/views/student.py b/backend/qna/views/student.py index fd9042e63..57d22b93b 100644 --- a/backend/qna/views/student.py +++ b/backend/qna/views/student.py @@ -129,7 +129,7 @@ class AnswerAPI(APIView): def post(self, request): data = request.data try: - question = Question.objects.get(id=data.pop("question_id"), status=True) + question = Question.objects.get(id=data.pop("question_id"), is_open=True) data["question"] = question data["created_by"] = request.user except Question.DoesNotExist: @@ -138,7 +138,7 @@ def post(self, request): if data.pop("closure", False): if not request.user.is_question_admin(question): return self.error("No permission for closure") - question.status = False + question.is_open = False question.save() answer = Answer.objects.create(**data)