Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
aintbe authored and jimin9038 committed Apr 12, 2022
1 parent a39112f commit 234f129
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -13,6 +13,6 @@ class Migration(migrations.Migration):
migrations.RenameField(
model_name='question',
old_name='status',
new_name='is_resolved',
new_name='is_open',
),
]
10 changes: 5 additions & 5 deletions backend/qna/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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",)
4 changes: 2 additions & 2 deletions backend/qna/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions backend/qna/views/student.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down

0 comments on commit 234f129

Please sign in to comment.