必须是提交成功之后对题目评论
This commit is contained in:
@@ -0,0 +1,30 @@
|
|||||||
|
# Generated by Django 5.0.6 on 2024-06-30 16:20
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('comment', '0002_alter_comment_options'),
|
||||||
|
('submission', '0013_alter_submission_info_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='comment',
|
||||||
|
name='problem_solved',
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='comment',
|
||||||
|
name='language',
|
||||||
|
field=models.CharField(choices=[('Python', 'Python'), ('C', 'C'), ('C++', 'C++'), ('Java', 'Java')], default='Python', max_length=10, verbose_name='解决这道题使用的语言'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='comment',
|
||||||
|
name='submission',
|
||||||
|
field=models.ForeignKey(default='', on_delete=django.db.models.deletion.CASCADE, to='submission.submission'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -15,13 +15,11 @@ class Languages(models.TextChoices):
|
|||||||
class Comment(models.Model):
|
class Comment(models.Model):
|
||||||
problem = models.ForeignKey(Problem, on_delete=models.CASCADE)
|
problem = models.ForeignKey(Problem, on_delete=models.CASCADE)
|
||||||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||||
submission = models.ForeignKey(Submission, null=True, blank=True, on_delete=models.SET_NULL)
|
submission = models.ForeignKey(Submission, on_delete=models.CASCADE)
|
||||||
problem_solved = models.BooleanField()
|
|
||||||
language = models.CharField(
|
language = models.CharField(
|
||||||
max_length=10,
|
max_length=10,
|
||||||
|
default=Languages.Python,
|
||||||
choices=Languages.choices,
|
choices=Languages.choices,
|
||||||
null=True,
|
|
||||||
blank=True,
|
|
||||||
verbose_name="解决这道题使用的语言",
|
verbose_name="解决这道题使用的语言",
|
||||||
)
|
)
|
||||||
description_rating = models.PositiveSmallIntegerField(
|
description_rating = models.PositiveSmallIntegerField(
|
||||||
|
|||||||
@@ -19,31 +19,27 @@ class CommentAPI(APIView):
|
|||||||
except Problem.DoesNotExist:
|
except Problem.DoesNotExist:
|
||||||
self.error("problem is not exists")
|
self.error("problem is not exists")
|
||||||
|
|
||||||
language = None
|
try:
|
||||||
submission = None
|
submission = (
|
||||||
problem_solved = False
|
Submission.objects.select_related("problem")
|
||||||
|
.filter(
|
||||||
submission = (
|
user_id=request.user.id,
|
||||||
Submission.objects.select_related("problem")
|
problem_id=data["problem_id"],
|
||||||
.filter(
|
result=JudgeStatus.ACCEPTED,
|
||||||
user_id=request.user.id,
|
)
|
||||||
problem_id=data["problem_id"],
|
.first()
|
||||||
result=JudgeStatus.ACCEPTED,
|
|
||||||
)
|
)
|
||||||
.first()
|
except Submission.DoesNotExist:
|
||||||
)
|
self.error("submission is not exists or not accepted")
|
||||||
|
|
||||||
if submission:
|
language = submission.language
|
||||||
problem_solved = True
|
if language == "Python3":
|
||||||
language = submission.language
|
language = "Python"
|
||||||
if language == "Python3":
|
|
||||||
language = "Python"
|
|
||||||
|
|
||||||
Comment.objects.create(
|
Comment.objects.create(
|
||||||
user=request.user,
|
user=request.user,
|
||||||
problem=problem,
|
problem=problem,
|
||||||
submission=submission,
|
submission=submission,
|
||||||
problem_solved=problem_solved,
|
|
||||||
language=language,
|
language=language,
|
||||||
description_rating=data["description_rating"],
|
description_rating=data["description_rating"],
|
||||||
difficulty_rating=data["difficulty_rating"],
|
difficulty_rating=data["difficulty_rating"],
|
||||||
@@ -66,8 +62,10 @@ class CommentAPI(APIView):
|
|||||||
comprehensive=Round(Avg("comprehensive_rating"), 2),
|
comprehensive=Round(Avg("comprehensive_rating"), 2),
|
||||||
)
|
)
|
||||||
contents = comments.exclude(content="").values_list("content", flat=True)
|
contents = comments.exclude(content="").values_list("content", flat=True)
|
||||||
return self.success({
|
return self.success(
|
||||||
"count": count,
|
{
|
||||||
"rating": rating,
|
"count": count,
|
||||||
"contents": list(contents),
|
"rating": rating,
|
||||||
})
|
"contents": list(contents),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user