diff --git a/core/static/bundled/base-bundle-index.ts b/core/static/bundled/base-bundle-index.ts index 53e3cc94..98a6d4f5 100644 --- a/core/static/bundled/base-bundle-index.ts +++ b/core/static/bundled/base-bundle-index.ts @@ -70,6 +70,7 @@ htmx.registerExtension("aria-busy", { }); htmx.config.transitions = true; + Object.assign(window, { htmx }); /** diff --git a/pedagogy/models.py b/pedagogy/models.py index 7333037a..309a80f5 100644 --- a/pedagogy/models.py +++ b/pedagogy/models.py @@ -26,6 +26,7 @@ from django.conf import settings from django.core import validators from django.db import models from django.db.models import Exists, OuterRef +from django.db.models.query_utils import Q from django.urls import reverse from django.utils import timezone from django.utils.functional import cached_property @@ -123,8 +124,10 @@ class UE(models.Model): This function checks that no other comment has been posted by a specified user. Returns: - True if the user has already posted a comment on this UE, else False. + True if the user has already posted a comment on this UE or is anonymous, else False. """ + if user.is_anonymous: + return True return self.comments.filter(author=user).exists() @cached_property @@ -155,7 +158,14 @@ class UECommentQuerySet(models.QuerySet): # so he can view non-moderated comments return self if user.has_perm("pedagogy.view_uecomment"): - return self.filter(reports=None) + return self.filter( + Q(author=user) + | ~Exists( + UECommentReport.objects.filter( + ~Q(reporter=user), comment=OuterRef("pk") + ) + ) + ).distinct() return self.filter(author=user) def annotate_is_reported(self) -> Self: @@ -257,7 +267,7 @@ class UEResult(models.Model): class UECommentReport(models.Model): - """Report an inapropriate comment.""" + """Report an inappropriate comment.""" comment = models.ForeignKey( UEComment, diff --git a/pedagogy/static/pedagogy/css/pedagogy.scss b/pedagogy/static/pedagogy/css/pedagogy.scss index e94fa813..ca7cc368 100644 --- a/pedagogy/static/pedagogy/css/pedagogy.scss +++ b/pedagogy/static/pedagogy/css/pedagogy.scss @@ -69,6 +69,7 @@ $pedagogy-white-text: #f0f0f0; input[type="checkbox"] { display: none; } + margin-top: 10px; margin-bottom: 0; color: white; @@ -128,14 +129,14 @@ $pedagogy-white-text: #f0f0f0; grid-area: hours-the; } - #leave_comment_not_allowed { + .leave-comment-not-allowed { p { text-align: center; color: red; } } - #leave_comment { + .leave-comment { .leave-comment-grid-container { display: grid; grid-template-columns: 270px auto; @@ -168,10 +169,6 @@ $pedagogy-white-text: #f0f0f0; .input-stars { margin-top: 20px; } - - input[type="submit"] { - float: right; - } } .ue-details-container { @@ -333,8 +330,9 @@ $pedagogy-white-text: #f0f0f0; padding-left: 10px; } - .actions { + .action { float: right; + margin-top: 0; } } @@ -402,6 +400,7 @@ $pedagogy-white-text: #f0f0f0; a { color: $pedagogy-white-text; + cursor: pointer; } a:hover { @@ -443,4 +442,10 @@ details.accordion>.accordion-content { background-color: $white-color; border-color: $pedagogy-orange; border-right: none; +} + +.buttons { + display: flex; + justify-content: flex-end; + align-items: center; } \ No newline at end of file diff --git a/pedagogy/templates/pedagogy/fragments/comment_report.jinja b/pedagogy/templates/pedagogy/fragments/comment_report.jinja new file mode 100644 index 00000000..9ebdfd97 --- /dev/null +++ b/pedagogy/templates/pedagogy/fragments/comment_report.jinja @@ -0,0 +1,31 @@ +
\ No newline at end of file diff --git a/pedagogy/templates/pedagogy/fragments/ue_comment_form.jinja b/pedagogy/templates/pedagogy/fragments/ue_comment_form.jinja new file mode 100644 index 00000000..7ec115be --- /dev/null +++ b/pedagogy/templates/pedagogy/fragments/ue_comment_form.jinja @@ -0,0 +1,71 @@ +{% trans %}You already posted a comment on this UE. If you want to comment again, please modify or delete your previous comment.{% endtrans %}
+{% trans %}Global grade{% endtrans %}
+{% trans %}Utility{% endtrans %}
+{% trans %}Interest{% endtrans %}
+{% trans %}Teaching{% endtrans %}
+{% trans %}Work load{% endtrans %}
+{{ display_star(object.grade_global_average) }}
+{{ display_star(object.grade_utility_average) }}
+{{ display_star(object.grade_interest_average) }}
+{{ display_star(object.grade_teaching_average) }}
+{{ display_star(object.grade_work_load_average) }}
+{% trans %}Objectives{% endtrans %}
+{{ object.objectives|markdown }}
+{% trans %}Program{% endtrans %}
+{{ object.program|markdown }}
+{% trans %}Earned skills{% endtrans %}
+{{ object.skills|markdown }}
+{% trans %}Key concepts{% endtrans %}
+{{ object.key_concepts|markdown }}
+{% trans %}UE manager: {% endtrans %}{{ object.manager }}
+{% trans %}Global grade{% endtrans %}
-{% trans %}Utility{% endtrans %}
-{% trans %}Interest{% endtrans %}
-{% trans %}Teaching{% endtrans %}
-{% trans %}Work load{% endtrans %}
-{{ display_star(object.grade_global_average) }}
-{{ display_star(object.grade_utility_average) }}
-{{ display_star(object.grade_interest_average) }}
-{{ display_star(object.grade_teaching_average) }}
-{{ display_star(object.grade_work_load_average) }}
-{% trans %}Objectives{% endtrans %}
-{{ object.objectives|markdown }}
-{% trans %}Program{% endtrans %}
-{{ object.program|markdown }}
-{% trans %}Earned skills{% endtrans %}
-{{ object.skills|markdown }}
-{% trans %}Key concepts{% endtrans %}
-{{ object.key_concepts|markdown }}
-{% trans %}UE manager: {% endtrans %}{{ object.manager }}
-{% trans %}You already posted a comment on this UE. If you want to comment again, please modify or delete your previous comment.{% endtrans %}
-
{% trans %}Global grade{% endtrans %}
+{% trans %}Utility{% endtrans %}
+{% trans %}Interest{% endtrans %}
+{% trans %}Teaching{% endtrans %}
+{% trans %}Work load{% endtrans %}
+{{ display_star(comment.grade_global) }}
+{{ display_star(comment.grade_utility) }}
+{{ display_star(comment.grade_interest) }}
+{{ display_star(comment.grade_teaching) }}
+{{ display_star(comment.grade_work_load) }}
++ {% trans %}This comment has been reported{% endtrans %} +
+ {% endif %} + + {% if comment.author_id == user.id or user.has_perm("pedagogy.change_comment") %} + + {% endif %} + {% if comment.author_id == user.id or user.has_perm("pedagogy.delete_comment") %} + + {% endif %} ++ + {% trans %}Report this comment{% endtrans %} + +
+{{ comment.publish_date.strftime('%d/%m/%Y') }}
{{ user_profile_link(comment.author) }}