Again, lot of forum improvements

This commit is contained in:
Skia 2017-02-24 17:22:13 +01:00
parent fe07ee0963
commit 777fdd7bd5
8 changed files with 158 additions and 91 deletions

View File

@ -416,10 +416,13 @@ textarea {
margin: 2px; margin: 2px;
background: #eff7ff; background: #eff7ff;
} }
.message:nth-child(odd) {
background: #fff;
}
.message h5 { .message h5 {
font-size: 100%; font-size: 100%;
} }
.unread { .message.unread {
background: #d8e7f3; background: #d8e7f3;
} }
.msg_author.deleted { .msg_author.deleted {

View File

@ -178,7 +178,9 @@ class ForumMessage(models.Model):
return self.topic.get_absolute_url() + "#msg_" + str(self.id) return self.topic.get_absolute_url() + "#msg_" + str(self.id)
def mark_as_read(self, user): def mark_as_read(self, user):
self.readers.add(user) try: # Need the try/except because of AnonymousUser
self.readers.add(user)
except: pass
def is_read(self, user): def is_read(self, user):
return (self.date < user.forum_infos.last_read_date) or (user in self.readers.all()) return (self.date < user.forum_infos.last_read_date) or (user in self.readers.all())

View File

@ -23,14 +23,14 @@
{% if forum.children.exists() %} {% if forum.children.exists() %}
<div> <div>
<div class="ib w_big"> <div class="ib w_big">
Title {% trans %}Title{% endtrans %}
</div> </div>
<div class="ib w_small"> <div class="ib w_small">
<div class="ib w_medium"> <div class="ib w_medium">
Topics {% trans %}Topics{% endtrans %}
</div> </div>
<div class="ib w_small"> <div class="ib w_small">
Last message {% trans %}Last message{% endtrans %}
</div> </div>
</div> </div>
</div> </div>
@ -41,17 +41,17 @@
{% if topics %} {% if topics %}
<div> <div>
<div class="ib w_medium"> <div class="ib w_medium">
Title {% trans %}Title{% endtrans %}
</div> </div>
<div class="ib w_medium"> <div class="ib w_medium">
<div class="ib w_small"> <div class="ib w_small">
Author {% trans %}Author{% endtrans %}
</div> </div>
<div class="ib w_medium"> <div class="ib w_medium">
Messages {% trans %}Messages{% endtrans %}
</div> </div>
<div class="ib w_small"> <div class="ib w_small">
Last message {% trans %}Last message{% endtrans %}
</div> </div>
</div> </div>
</div> </div>

View File

@ -71,3 +71,57 @@
</div> </div>
{% endmacro %} {% endmacro %}
{% macro display_message(m, user, unread=False) %}
{% if user.can_view(m) %}
<div id="msg_{{ m.id }}" class="message {% if unread %}unread{% endif %}">
<div class="msg_author {% if m.deleted %}deleted{% endif %}">
{% if m.author.avatar_pict %}
<img src="{{ m.author.avatar_pict.get_download_url() }}" alt="{% trans %}Profile{% endtrans %}" id="picture" />
{% else %}
<img src="{{ static('core/img/unknown.jpg') }}" alt="{% trans %}Profile{% endtrans %}" id="picture" />
{% endif %}
<br/>
<strong><a href="{{ m.author.get_absolute_url() }}">{{ m.author.get_short_name() }}</a></strong>
</div>
<div class="msg_content {% if m.deleted %}deleted{% endif %}" {% if m.id == first_unread_message_id %}id="first_unread"{% endif %}>
<div style="display: inline-block; width: 74%;">
{% if m.title %}
<h5>{{ m.title }}</h5>
{% endif %}
</div>
<div style="display: inline-block; width: 25%;">
<span><a href="{{ url('forum:new_message', topic_id=m.topic.id) }}?quote_id={{ m.id }}">
{% trans %}Reply as quote{% endtrans %}</a></span>
{% if user.can_edit(m) %}
<span> <a href="{{ url('forum:edit_message', message_id=m.id) }}">{% trans %}Edit{% endtrans %}</a></span>
{% endif %}
{% if m.can_be_moderated_by(user) %}
{% if m.deleted %}
<span> <a href="{{ url('forum:undelete_message', message_id=m.id) }}">{% trans %}Undelete{% endtrans %}</a></span>
{% else %}
<span> <a href="{{ url('forum:delete_message', message_id=m.id) }}">{% trans %}Delete{% endtrans %}</a></span>
{% endif %}
{% endif %}
<br/>
<span>{{ m.date|localtime|date(DATETIME_FORMAT) }} {{ m.date|localtime|time(DATETIME_FORMAT) }}</span>
</div>
<hr>
<div>
{{ m.message|markdown }}
</div>
{% if m.can_be_moderated_by(user) %}
<ul class="msg_meta">
{% for meta in m.metas.select_related('user').order_by('id') %}
<li style="background: {% if m.author == meta.user %}#bfffbf{% else %}#ffffbf{% endif %}">
{{ meta.get_action_display() }} {{ meta.user.get_display_name() }}
{% trans %} at {% endtrans %}{{ meta.date|localtime|time(DATETIME_FORMAT) }}
{% trans %} the {% endtrans %}{{ meta.date|localtime|date(DATETIME_FORMAT)}}</li>
{% endfor %}
</ul>
{% endif %}
</div>
</div>
{{ m.mark_as_read(user) or "" }}
{% endif %}
{% endmacro %}

View File

@ -0,0 +1,35 @@
{% extends "core/base.jinja" %}
{% from 'forum/macros.jinja' import display_message %}
{% block title %}
{% trans %}Reply{% endtrans %}
{% endblock %}
{% block content %}
<p>
<a href="{{ url('forum:main') }}">{% trans %}Forum{% endtrans %}</a>
{% for f in topic.forum.get_parent_list() %}
> <a href="{{ f.get_absolute_url() }}">{{ f }}</a>
{% endfor %}
> <a href="{{ topic.forum.get_absolute_url() }}">{{ topic.forum }}</a>
> <a href="{{ topic.get_absolute_url() }}">{{ topic }}</a>
</p>
<h3>{{ topic.title }}</h3>
<h4>{% trans %}Reply{% endtrans %}</h4>
<form action="" method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p() }}
<p><input type="submit" value="{% trans %}Save{% endtrans %}" /></p>
</form>
<hr>
{% for m in topic.messages.select_related('author__avatar_pict').order_by('-id') %}
{{ display_message(m, user) }}
{% endfor %}
{% endblock %}

View File

@ -1,5 +1,6 @@
{% extends "core/base.jinja" %} {% extends "core/base.jinja" %}
{% from 'core/macros.jinja' import user_profile_link %} {% from 'core/macros.jinja' import user_profile_link %}
{% from 'forum/macros.jinja' import display_message %}
{% block title %} {% block title %}
{{ topic }} {{ topic }}
@ -35,66 +36,17 @@
</p> </p>
<h3>{{ topic.title }}</h3> <h3>{{ topic.title }}</h3>
<p>{{ topic.description }}</p> <p>{{ topic.description }}</p>
<p><a href="{{ url('forum:new_message', topic_id=topic.id) }}">Reply</a></p> <p><a href="{{ url('forum:new_message', topic_id=topic.id) }}">{% trans %}Reply{% endtrans %}</a></p>
{% for m in topic.messages.select_related('author__avatar_pict').all() %} {% for m in topic.messages.select_related('author__avatar_pict').all() %}
{% if user.can_view(m) %} {% if m.id >= first_unread_message_id %}
{% if m.id >= first_unread_message_id %} {{ display_message(m, user, True) }}
<div id="msg_{{ m.id }}" class="message unread"> {% else %}
{% else %} {{ display_message(m, user, False) }}
<div id="msg_{{ m.id }}" class="message"> {% endif %}
{% endif %}
<div class="msg_author {% if m.deleted %}deleted{% endif %}">
{% if m.author.avatar_pict %}
<img src="{{ m.author.avatar_pict.get_download_url() }}" alt="{% trans %}Profile{% endtrans %}" id="picture" />
{% else %}
<img src="{{ static('core/img/unknown.jpg') }}" alt="{% trans %}Profile{% endtrans %}" id="picture" />
{% endif %}
<br/>
<strong><a href="{{ m.author.get_absolute_url() }}">{{ m.author.get_short_name() }}</a></strong>
</div>
<div class="msg_content {% if m.deleted %}deleted{% endif %}" {% if m.id == first_unread_message_id %}id="first_unread"{% endif %}>
<div style="display: inline-block; width: 74%;">
{% if m.title %}
<h5>{{ m.title }}</h5>
{% endif %}
</div>
<div style="display: inline-block; width: 25%;">
<span><a href="{{ url('forum:new_message', topic_id=topic.id) }}?quote_id={{ m.id }}">
{% trans %}Reply as quote{% endtrans %}</a></span>
{% if user.can_edit(m) %}
<span> <a href="{{ url('forum:edit_message', message_id=m.id) }}">{% trans %}Edit{% endtrans %}</a></span>
{% endif %}
{% if m.can_be_moderated_by(user) %}
{% if m.deleted %}
<span> <a href="{{ url('forum:undelete_message', message_id=m.id) }}">{% trans %}Undelete{% endtrans %}</a></span>
{% else %}
<span> <a href="{{ url('forum:delete_message', message_id=m.id) }}">{% trans %}Delete{% endtrans %}</a></span>
{% endif %}
{% endif %}
<br/>
<span>{{ m.date|localtime|date(DATETIME_FORMAT) }} {{ m.date|localtime|time(DATETIME_FORMAT) }}</span>
</div>
<hr>
<div>
{{ m.message|markdown }}
</div>
{% if m.can_be_moderated_by(user) %}
<ul class="msg_meta">
{% for meta in m.metas.select_related('user').order_by('id') %}
<li style="background: {% if m.author == meta.user %}#bfffbf{% else %}#ffffbf{% endif %}">
{{ meta.get_action_display() }} {{ meta.user.get_display_name() }}
{% trans %} at {% endtrans %}{{ meta.date|localtime|time(DATETIME_FORMAT) }}
{% trans %} the {% endtrans %}{{ meta.date|localtime|date(DATETIME_FORMAT)}}</li>
{% endfor %}
</ul>
{% endif %}
</div>
</div>
{{ m.mark_as_read(user) or "" }}
{% endif %}
{% endfor %} {% endfor %}
<p><a href="{{ url('forum:new_message', topic_id=topic.id) }}">Reply</a></p>
<p><a href="{{ url('forum:new_message', topic_id=topic.id) }}">{% trans %}Reply{% endtrans %}</a></p>
{% endblock %} {% endblock %}

View File

@ -134,8 +134,8 @@ class ForumTopicDetailView(CanViewMixin, DetailView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
kwargs = super(ForumTopicDetailView, self).get_context_data(**kwargs) kwargs = super(ForumTopicDetailView, self).get_context_data(**kwargs)
msg = self.object.messages.exclude(readers=self.request.user).filter(date__gte=self.request.user.forum_infos.last_read_date).order_by('id').first()
try: try:
msg = self.object.messages.exclude(readers=self.request.user).filter(date__gte=self.request.user.forum_infos.last_read_date).order_by('id').first()
kwargs['first_unread_message_id'] = msg.id kwargs['first_unread_message_id'] = msg.id
except: except:
kwargs['first_unread_message_id'] = float("inf") kwargs['first_unread_message_id'] = float("inf")
@ -176,7 +176,7 @@ class ForumMessageUndeleteView(SingleObjectMixin, RedirectView):
class ForumMessageCreateView(CanCreateMixin, CreateView): class ForumMessageCreateView(CanCreateMixin, CreateView):
model = ForumMessage model = ForumMessage
fields = ['title', 'message'] fields = ['title', 'message']
template_name = "core/create.jinja" template_name = "forum/reply.jinja"
def dispatch(self, request, *args, **kwargs): def dispatch(self, request, *args, **kwargs):
self.topic = get_object_or_404(ForumTopic, id=self.kwargs['topic_id']) self.topic = get_object_or_404(ForumTopic, id=self.kwargs['topic_id'])
@ -202,4 +202,8 @@ class ForumMessageCreateView(CanCreateMixin, CreateView):
form.instance.author = self.request.user form.instance.author = self.request.user
return super(ForumMessageCreateView, self).form_valid(form) return super(ForumMessageCreateView, self).form_valid(form)
def get_context_data(self, **kwargs):
kwargs = super(ForumMessageCreateView, self).get_context_data(**kwargs)
kwargs['topic'] = self.topic
return kwargs

View File

@ -6,7 +6,7 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-02-24 04:33+0100\n" "POT-Creation-Date: 2017-02-24 16:30+0100\n"
"PO-Revision-Date: 2016-07-18\n" "PO-Revision-Date: 2016-07-18\n"
"Last-Translator: Skia <skia@libskia.so>\n" "Last-Translator: Skia <skia@libskia.so>\n"
"Language-Team: AE info <ae.info@utbm.fr>\n" "Language-Team: AE info <ae.info@utbm.fr>\n"
@ -125,10 +125,10 @@ msgstr "numéro"
msgid "journal" msgid "journal"
msgstr "classeur" msgstr "classeur"
#: accounting/models.py:194 core/models.py:546 core/models.py:902 #: accounting/models.py:194 core/models.py:546 core/models.py:899
#: core/models.py:942 counter/models.py:242 counter/models.py:290 #: core/models.py:939 counter/models.py:242 counter/models.py:290
#: counter/models.py:416 eboutic/models.py:15 eboutic/models.py:48 #: counter/models.py:416 eboutic/models.py:15 eboutic/models.py:48
#: forum/models.py:155 forum/models.py:205 #: forum/models.py:155 forum/models.py:207
msgid "date" msgid "date"
msgstr "date" msgstr "date"
@ -1089,7 +1089,7 @@ msgstr "résumé"
msgid "content" msgid "content"
msgstr "contenu de la nouvelle" msgstr "contenu de la nouvelle"
#: com/models.py:36 core/models.py:941 launderette/models.py:60 #: com/models.py:36 core/models.py:938 launderette/models.py:60
#: launderette/models.py:85 launderette/models.py:121 #: launderette/models.py:85 launderette/models.py:121
msgid "type" msgid "type"
msgstr "type" msgstr "type"
@ -1171,6 +1171,7 @@ msgstr "Type"
#: com/templates/com/news_admin_list.jinja:15 #: com/templates/com/news_admin_list.jinja:15
#: com/templates/com/news_admin_list.jinja:49 #: com/templates/com/news_admin_list.jinja:49
#: com/templates/com/weekmail.jinja:18 com/templates/com/weekmail.jinja:41 #: com/templates/com/weekmail.jinja:18 com/templates/com/weekmail.jinja:41
#: forum/templates/forum/forum.jinja:26 forum/templates/forum/forum.jinja:44
msgid "Title" msgid "Title"
msgstr "Titre" msgstr "Titre"
@ -1182,6 +1183,7 @@ msgstr "Résumé"
#: com/templates/com/news_admin_list.jinja:18 #: com/templates/com/news_admin_list.jinja:18
#: com/templates/com/news_admin_list.jinja:52 #: com/templates/com/news_admin_list.jinja:52
#: com/templates/com/weekmail.jinja:16 com/templates/com/weekmail.jinja:39 #: com/templates/com/weekmail.jinja:16 com/templates/com/weekmail.jinja:39
#: forum/templates/forum/forum.jinja:48
msgid "Author" msgid "Author"
msgstr "Auteur" msgstr "Auteur"
@ -1614,7 +1616,7 @@ msgstr "Un utilisateur de ce nom d'utilisateur existe déjà"
#: core/templates/core/user_detail.jinja:16 #: core/templates/core/user_detail.jinja:16
#: core/templates/core/user_edit.jinja:17 #: core/templates/core/user_edit.jinja:17
#: election/templates/election/election_detail.jinja:316 #: election/templates/election/election_detail.jinja:316
#: forum/templates/forum/topic.jinja:48 forum/templates/forum/topic.jinja:50 #: forum/templates/forum/topic.jinja:49 forum/templates/forum/topic.jinja:51
msgid "Profile" msgid "Profile"
msgstr "Profil" msgstr "Profil"
@ -1725,8 +1727,7 @@ msgid ""
"Enter a valid page name. This value may contain only letters, numbers and ./" "Enter a valid page name. This value may contain only letters, numbers and ./"
"+/-/_ characters." "+/-/_ characters."
msgstr "" msgstr ""
"Entrez un nom de page correct. Uniquement des lettres, numéros, et ./" "Entrez un nom de page correct. Uniquement des lettres, numéros, et ./+/-/_"
"+/-/_"
#: core/models.py:747 #: core/models.py:747
msgid "page name" msgid "page name"
@ -1752,27 +1753,27 @@ msgstr "Une page de ce nom existe déjà"
msgid "Loop in page tree" msgid "Loop in page tree"
msgstr "Boucle dans l'arborescence des pages" msgstr "Boucle dans l'arborescence des pages"
#: core/models.py:899 #: core/models.py:896
msgid "revision" msgid "revision"
msgstr "révision" msgstr "révision"
#: core/models.py:900 #: core/models.py:897
msgid "page title" msgid "page title"
msgstr "titre de la page" msgstr "titre de la page"
#: core/models.py:901 #: core/models.py:898
msgid "page content" msgid "page content"
msgstr "contenu de la page" msgstr "contenu de la page"
#: core/models.py:939 #: core/models.py:936
msgid "url" msgid "url"
msgstr "url" msgstr "url"
#: core/models.py:940 #: core/models.py:937
msgid "param" msgid "param"
msgstr "param" msgstr "param"
#: core/models.py:943 #: core/models.py:940
msgid "viewed" msgid "viewed"
msgstr "vue" msgstr "vue"
@ -3342,7 +3343,7 @@ msgstr "Les votes ouvriront "
#: election/templates/election/election_list.jinja:34 #: election/templates/election/election_list.jinja:34
#: election/templates/election/election_list.jinja:39 #: election/templates/election/election_list.jinja:39
#: election/templates/election/election_list.jinja:42 #: election/templates/election/election_list.jinja:42
#: forum/templates/forum/topic.jinja:86 #: forum/templates/forum/topic.jinja:87
msgid " at " msgid " at "
msgstr " à " msgstr " à "
@ -3457,23 +3458,23 @@ msgstr "message"
msgid "readers" msgid "readers"
msgstr "lecteurs" msgstr "lecteurs"
#: forum/models.py:197 #: forum/models.py:199
msgid "Message edited by" msgid "Message edited by"
msgstr "Message édité par" msgstr "Message édité par"
#: forum/models.py:198 #: forum/models.py:200
msgid "Message deleted by" msgid "Message deleted by"
msgstr "Message supprimé par" msgstr "Message supprimé par"
#: forum/models.py:199 #: forum/models.py:201
msgid "Message undeleted by" msgid "Message undeleted by"
msgstr "Message restauré par" msgstr "Message restauré par"
#: forum/models.py:206 #: forum/models.py:208
msgid "action" msgid "action"
msgstr "action" msgstr "action"
#: forum/models.py:215 #: forum/models.py:217
msgid "last read date" msgid "last read date"
msgstr "dernière date de lecture" msgstr "dernière date de lecture"
@ -3485,6 +3486,18 @@ msgstr "Nouveau forum"
msgid "New topic" msgid "New topic"
msgstr "Nouveau sujet" msgstr "Nouveau sujet"
#: forum/templates/forum/forum.jinja:30
msgid "Topics"
msgstr "Sujets"
#: forum/templates/forum/forum.jinja:33 forum/templates/forum/forum.jinja:54
msgid "Last message"
msgstr "Dernier message"
#: forum/templates/forum/forum.jinja:51
msgid "Messages"
msgstr "Messages"
#: forum/templates/forum/last_unread.jinja:5 #: forum/templates/forum/last_unread.jinja:5
#: forum/templates/forum/last_unread.jinja:13 #: forum/templates/forum/last_unread.jinja:13
msgid "Last unread messages" msgid "Last unread messages"
@ -3498,6 +3511,10 @@ msgstr "Rafraîchir"
msgid "View last unread messages" msgid "View last unread messages"
msgstr "Voir les derniers messages non lus" msgstr "Voir les derniers messages non lus"
#: forum/templates/forum/topic.jinja:38 forum/templates/forum/topic.jinja:97
msgid "Reply"
msgstr "Répondre"
#: forum/templates/forum/topic.jinja:64 #: forum/templates/forum/topic.jinja:64
msgid "Reply as quote" msgid "Reply as quote"
msgstr "Répondre en citant" msgstr "Répondre en citant"
@ -3506,15 +3523,15 @@ msgstr "Répondre en citant"
msgid "Undelete" msgid "Undelete"
msgstr "Restaurer" msgstr "Restaurer"
#: forum/templates/forum/topic.jinja:87 #: forum/templates/forum/topic.jinja:88
msgid " the " msgid " the "
msgstr " le " msgstr " le "
#: forum/views.py:65 #: forum/views.py:67
msgid "Apply rights and club owner recursively" msgid "Apply rights and club owner recursively"
msgstr "Appliquer les droits et le club propriétaire récursivement" msgstr "Appliquer les droits et le club propriétaire récursivement"
#: forum/views.py:183 #: forum/views.py:191
#, python-format #, python-format
msgid "%(author)s said" msgid "%(author)s said"
msgstr "Citation de %(author)s" msgstr "Citation de %(author)s"