diff --git a/core/templates/core/macros.jinja b/core/templates/core/macros.jinja
index 89c9d364..a781635b 100644
--- a/core/templates/core/macros.jinja
+++ b/core/templates/core/macros.jinja
@@ -156,6 +156,38 @@
{% endmacro %}
+{% macro paginate_jinja(page, nb_pages) %}
+
+{% endmacro %}
+
{% macro paginate(page_obj, paginator, js_action) %}
{% set js = js_action|default('') %}
{% if page_obj.has_previous() or page_obj.has_next() %}
diff --git a/forum/models.py b/forum/models.py
index 3a657f8f..3ac2fda3 100644
--- a/forum/models.py
+++ b/forum/models.py
@@ -170,7 +170,7 @@ class Forum(models.Model):
def is_owned_by(self, user):
if user.is_anonymous:
return False
- if user.is_in_group(pk=settings.SITH_GROUP_FORUM_ADMIN_ID):
+ if user.is_root or user.is_in_group(pk=settings.SITH_GROUP_FORUM_ADMIN_ID):
return True
try:
m = Forum._club_memberships[self.id][user.id]
@@ -273,10 +273,10 @@ class ForumTopic(models.Model):
return self.forum.is_owned_by(user)
def can_be_edited_by(self, user):
- return user.can_edit(self.forum)
+ return user.is_root or user.can_edit(self.forum)
def can_be_viewed_by(self, user):
- return user.can_view(self.forum)
+ return user.is_root or user.can_view(self.forum)
def get_first_unread_message(self, user: User) -> ForumMessage | None:
if not hasattr(user, "forum_infos"):
@@ -355,7 +355,7 @@ class ForumMessage(models.Model):
return not self._deleted
def can_be_moderated_by(self, user):
- return self.topic.forum.is_owned_by(user) or user.id == self.author.id
+ return self.topic.forum.is_owned_by(user) or user.id == self.author_id
def get_url(self):
return (
diff --git a/forum/static/forum/css/forum.scss b/forum/static/forum/css/forum.scss
index b592231d..a618cf33 100644
--- a/forum/static/forum/css/forum.scss
+++ b/forum/static/forum/css/forum.scss
@@ -6,21 +6,26 @@
padding: 10px;
font-weight: bold;
border-radius: 5px;
+
&:hover {
background-color: rgb(211, 211, 211);
}
}
+
.topic {
border: solid $primary-neutral-color 1px;
padding: 1px;
margin: 1px;
+
p {
margin: 1px;
font-size: smaller;
}
+
a {
color: $black-color;
}
+
a:hover {
text-decoration: underline;
}
@@ -30,6 +35,7 @@
font-size: x-small;
border: none;
font-weight: bold;
+
a {
padding: 1px;
}
@@ -41,10 +47,6 @@
padding: 2px;
}
- .last_message date {
- white-space: nowrap;
- }
-
.last_message span {
white-space: nowrap;
text-overflow: ellipsis;
@@ -57,31 +59,36 @@
background: $primary-neutral-light-color;
padding: 1px;
margin: 1px;
+
p {
margin: 1px;
font-size: smaller;
}
+
a {
color: $black-color;
}
a:hover {
text-decoration: underline;
}
+
}
.search_bar {
margin: 10px 0;
display: flex;
flex-wrap: wrap;
- height: 20px;
align-items: center;
}
+
.search_check {
margin-left: 10px;
}
+
.search_bouton {
margin-left: 10px;
}
+
.category {
margin-top: 5px;
background: $secondary-color;
@@ -93,66 +100,67 @@
}
.message {
- padding: 1px;
- margin: 1px;
+ padding: 15px;
+ margin: 20px;
+ display: flex;
+ flex-direction: column;
+ gap: 10px;
background: $secondary-neutral-light-color;
+ border-radius: 5px;
+ border: 1px darken($secondary-neutral-light-color, 10%) solid;
+
&:nth-child(odd) {
background: $primary-neutral-light-color;
}
- .title {
- font-size: 100%;
+
+ .message-header {
+ display: flex;
+ gap: 20px;
+ border-bottom: 0.0625rem grey dotted;
+ padding-bottom: 10px;
+
+ img {
+ width: 50px;
+ height: 50px;
+ border-radius: 50%;
+ }
+
+ .message-metadata {
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+ }
+
+ .message-options {
+ flex: 2;
+ display: flex;
+ justify-content: right;
+ gap: 15px;
+ }
}
+
+ .message-content {
+ padding: 0 20px;
+
+ &.delete > * {
+ margin-top: 0;
+ }
+
+ .markdown blockquote h5 {
+ padding-top: 0;
+ margin-top: 0;
+ }
+ }
+
+ .forum-signature {
+ margin: 0;
+ font-size: small;
+ font-style: italic;
+ border-top: 0.0625rem grey dotted;
+ }
+
&.unread {
background: #e9eea1;
}
}
-
- .msg_author.deleted {
- background: #ffcfcf;
- }
-
- .msg_content {
- &.deleted {
- background: #ffefef;
- }
- display: inline-block;
- width: 80%;
- vertical-align: top;
- }
-
- .msg_author {
- display: inline-block;
- width: 19%;
- text-align: center;
- img {
- max-width: 70%;
- margin: 0 auto;
- }
- }
-
- .msg_header {
- display: inline-block;
- width: 100%;
- font-size: small;
- }
-
- .msg_meta {
- font-size: small;
- list-style-type: none;
- li {
- padding: 1px;
- margin: 1px;
- }
- }
-
- .forum_signature {
- color: hsl(0, 0%, 75%);
- border-top: 1px solid hsl(0, 0%, 75%);
- a {
- color: hsl(0, 0%, 75%);
- &:hover {
- text-decoration: underline;
- }
- }
- }
-}
\ No newline at end of file
+}
diff --git a/forum/templates/forum/macros.jinja b/forum/templates/forum/macros.jinja
index 6b4c0649..f65a5606 100644
--- a/forum/templates/forum/macros.jinja
+++ b/forum/templates/forum/macros.jinja
@@ -97,73 +97,81 @@
{% endmacro %}
{% macro display_message(m, user, unread=False) %}
- {% if user.can_view(m) %}
-
-
+ {% set user_is_admin = m.topic.is_owned_by(user) %}
+
+ {% if user_is_admin or not m._deleted %}
+
-
-
+ {% endif %} {# close `user.can_view(m) or user_is_admin` #}
+ {% if user.can_view(m) %}
+
+ {{ m.message|markdown }}
{% if m.can_be_moderated_by(user) %}
{% endif %}
-
{{ m.author.forum_signature|markdown }}
-
-{% else %}
-
-
-
-
-
{% trans %}Deleted or unreadable message.{% endtrans %}
-
{{ m.date|localtime|date(DATETIME_FORMAT) }} {{ m.date|localtime|time(DATETIME_FORMAT) }}
-
-
-{% endif %}
-{{ m.mark_as_read(user) or "" }}
+ {% if m.author.forum_signature %}
+ {{ m.author.forum_signature|markdown }}
+ {% endif %}
+ {% else %}
+
+
{% trans %}Deleted or unreadable message.{% endtrans %}
+
+ {% endif %}
+
+ {{ m.mark_as_read(user) or "" }}
{% endmacro %}
{% macro display_search_bar(request) %}
diff --git a/forum/templates/forum/topic.jinja b/forum/templates/forum/topic.jinja
index f730544e..715a6cb4 100644
--- a/forum/templates/forum/topic.jinja
+++ b/forum/templates/forum/topic.jinja
@@ -1,6 +1,7 @@
{% extends "core/base.jinja" %}
{% from 'core/macros.jinja' import user_profile_link %}
{% from 'forum/macros.jinja' import display_message, display_breadcrumb, display_search_bar %}
+{% from 'core/macros.jinja' import paginate_jinja %}
{% block title %}
{{ topic }}
@@ -9,25 +10,7 @@
{% block additional_css %}
-{% endblock %}
-
-{% block head %}
- {{ super() }}
-
+
{% endblock %}
{% block content %}
@@ -45,30 +28,24 @@
{{ display_search_bar(request) }}
-
- {% for p in msgs.paginator.page_range %}
- {{ p }}
- {% endfor %}
-
+ {{ paginate_jinja(msgs.number, msgs.paginator.num_pages) }}
- {% for m in msgs %}
- {% if m.id == first_unread_message_id %}
-
- {% endif %}
- {% if m.id >= first_unread_message_id %}
- {{ display_message(m, user, True) }}
- {% else %}
- {{ display_message(m, user, False) }}
- {% endif %}
- {% endfor %}
+
+ {% for m in msgs %}
+ {% if m.id == first_unread_message_id %}
+
+ {% endif %}
+ {% if m.id >= first_unread_message_id %}
+ {{ display_message(m, user, True) }}
+ {% else %}
+ {{ display_message(m, user, False) }}
+ {% endif %}
+ {% endfor %}
+
{% trans %}Reply{% endtrans %}
-
- {% for p in msgs.paginator.page_range %}
- {{ p }}
- {% endfor %}
-
+ {{ paginate_jinja(msgs.number, msgs.paginator.num_pages) }}
{% endblock %}
diff --git a/forum/views.py b/forum/views.py
index bbb2ba32..052eb068 100644
--- a/forum/views.py
+++ b/forum/views.py
@@ -306,14 +306,15 @@ class ForumTopicDetailView(CanViewMixin, DetailView):
queryset = ForumTopic.objects.select_related("forum__parent")
def get_context_data(self, **kwargs):
+ topic: ForumTopic = self.object
kwargs = super().get_context_data(**kwargs)
- msg = self.object.get_first_unread_message(self.request.user)
+ msg = topic.get_first_unread_message(self.request.user)
if msg is None:
kwargs["first_unread_message_id"] = math.inf
else:
kwargs["first_unread_message_id"] = msg.id
paginator = Paginator(
- self.object.messages.select_related("author__avatar_pict")
+ topic.messages.select_related("author__avatar_pict", "topic__forum")
.prefetch_related("topic__forum__edit_groups", "readers")
.order_by("date"),
settings.SITH_FORUM_PAGE_LENGTH,