Fix review comments

This commit is contained in:
2026-09-13 21:54:04 +02:00
parent 02df76c31f
commit 464f38af23
3 changed files with 28 additions and 26 deletions
@@ -15,9 +15,9 @@
{{ form.reporter }}
{{ form.comment }}
<div class="buttons">
<div class="buttons row gap">
<button
class="btn btn-red left"
class="btn btn-grey"
hx-get="{{ ue_detail_url }}"
hx-target="closest form"
hx-swap="outerHTML"
@@ -25,7 +25,7 @@
{% trans %}Cancel{% endtrans %}
</button>
<input class="btn btn-green" type="submit" value="{% trans %}Report{% endtrans %}" />
<input class="btn btn-blue" type="submit" value="{% trans %}Report{% endtrans %}" />
</div>
</form>
+21 -14
View File
@@ -25,6 +25,7 @@ from typing import Callable
import pytest
from django.conf import settings
from django.contrib.auth.models import Permission
from django.db.models import Max
from django.test import Client, TestCase
from django.urls import reverse
from model_bakery import baker
@@ -316,10 +317,11 @@ class TestUVCommentDisplay(TestCase):
)
cls.subscriber = subscriber_user.make()
comments = baker.make(UEComment, ue=cls.ue, _quantity=10)
cls.unreported, cls.reported = comments[:5], comments[5:]
baker.make(
UECommentReport,
comment=iter(comments[5:]),
_quantity=len(comments[5:]),
comment=iter(cls.reported),
_quantity=len(cls.reported),
_bulk_create=True,
)
@@ -347,7 +349,10 @@ class TestUVCommentDisplay(TestCase):
def test_access_not_found(self):
self.client.force_login(self.admin)
res = self.client.get(
reverse("pedagogy:ue_detail", kwargs={"ue_id": UE.objects.last().id + 1})
reverse(
"pedagogy:ue_detail",
kwargs={"ue_id": UE.objects.aggregate(id=Max("id"))["id"] + 1},
)
)
assert res.status_code == 404
@@ -359,22 +364,20 @@ class TestUVCommentDisplay(TestCase):
self.client.force_login(self.subscriber)
comments = self.client.get(self.ue_url).context_data.get("comments", [])
assert len(comments) == 5
assert all(not comment.reports.exists() for comment in comments)
assert len(comments) == len(self.unreported)
assert set(comments) == set(self.unreported)
# Make user comment
user_comment = baker.make(UEComment, ue=self.ue, author=self.subscriber)
comments = self.client.get(self.ue_url).context_data.get("comments", [])
assert len(comments) == 6
assert all(not comment.reports.exists() for comment in comments)
assert user_comment in comments
assert len(comments) == len(self.unreported) + 1
assert set(comments) == {*self.unreported, user_comment}
# Report user comment
baker.make(UECommentReport, comment=user_comment)
comments = self.client.get(self.ue_url).context_data.get("comments", [])
assert len(comments) == 6
assert not all(not comment.reports.exists() for comment in comments)
assert user_comment in comments
assert len(comments) == len(self.unreported) + 1
assert set(comments) == {*self.unreported, user_comment}
# Report someone's else comment
comment_reported_by_user = baker.make(UEComment, ue=self.ue)
@@ -382,8 +385,12 @@ class TestUVCommentDisplay(TestCase):
UECommentReport, comment=comment_reported_by_user, reporter=self.subscriber
)
comments = self.client.get(self.ue_url).context_data.get("comments", [])
assert len(comments) == 7
assert comment_reported_by_user in comments
assert len(comments) == len(self.unreported) + 2
assert set(comments) == {
*self.unreported,
user_comment,
comment_reported_by_user,
}
def test_comments_pedagogy_admin(self):
# Pedagogy admin sees everything
@@ -478,7 +485,7 @@ class TestUECommentCreation(TestCase):
def test_create_ue_comment_ue_not_exist_fails(self):
self.client.force_login(self.bibou)
not_existing_id = UE.objects.all().last().id + 1
not_existing_id = UE.objects.aggregate(id=Max("id"))["id"] + 1
response = self.client.post(
reverse("pedagogy:comment_create", kwargs={"ue_id": not_existing_id}),
create_ue_comment_template(
+4 -9
View File
@@ -106,7 +106,7 @@ class UEDetailView(
.annotate_is_reported()
.select_related("author")
.order_by("-publish_date")
),
)
}
@@ -135,7 +135,7 @@ class UECommentUpdateView(PermissionOrAuthorRequiredMixin, AllowFragment, Update
}
def get_success_url(self):
return reverse("pedagogy:ue_detail", kwargs={"ue_id": self.object.ue.id})
return reverse("pedagogy:ue_detail", kwargs={"ue_id": self.object.ue_id})
class UECommentDeleteView(PermissionOrAuthorRequiredMixin, AllowFragment, DeleteView):
@@ -147,13 +147,8 @@ class UECommentDeleteView(PermissionOrAuthorRequiredMixin, AllowFragment, Delete
permission_required = "pedagogy.delete_uecomment"
author_field = "author"
def form_valid(self, form):
response = super().form_valid(form)
response.headers["HX-Trigger"] = "CommentUpdate"
return response
def get_success_url(self):
return reverse("pedagogy:ue_detail", kwargs={"ue_id": self.object.ue.id})
return reverse("pedagogy:ue_detail", kwargs={"ue_id": self.object.ue_id})
class UEGuideView(PermissionRequiredMixin, TemplateView):
@@ -177,7 +172,7 @@ class UECommentReportCreateView(PermissionRequiredMixin, AllowFragment, CreateVi
@cached_property
def ue_detail_url(self):
return reverse("pedagogy:ue_detail", kwargs={"ue_id": self.ue_comment.ue.id})
return reverse("pedagogy:ue_detail", kwargs={"ue_id": self.ue_comment.ue_id})
def get_form_kwargs(self):
kwargs = super().get_form_kwargs()