mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-09 19:40:19 +00:00
21
forum/migrations/0005_forumtopic_subscribed_users.py
Normal file
21
forum/migrations/0005_forumtopic_subscribed_users.py
Normal file
@ -0,0 +1,21 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('forum', '0004_auto_20170531_1949'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='forumtopic',
|
||||
name='subscribed_users',
|
||||
field=models.ManyToManyField(verbose_name='subscribed users', related_name='favorite_topics', to=settings.AUTH_USER_MODEL),
|
||||
),
|
||||
]
|
@ -1,6 +1,6 @@
|
||||
# -*- coding:utf-8 -*
|
||||
#
|
||||
# Copyright 2016,2017
|
||||
# Copyright 2016,2017,2018
|
||||
# - Skia <skia@libskia.so>
|
||||
#
|
||||
# Ce fichier fait partie du site de l'Association des Étudiants de l'UTBM,
|
||||
@ -184,6 +184,7 @@ class ForumTopic(models.Model):
|
||||
forum = models.ForeignKey(Forum, related_name='topics')
|
||||
author = models.ForeignKey(User, related_name='forum_topics')
|
||||
description = models.CharField(_('description'), max_length=256, default="")
|
||||
subscribed_users = models.ManyToManyField(User, related_name='favorite_topics', verbose_name=_("subscribed users"))
|
||||
_last_message = models.ForeignKey('ForumMessage', related_name="+", verbose_name=_("the last message"),
|
||||
null=True, on_delete=models.SET_NULL)
|
||||
_title = models.CharField(_('title'), max_length=64, blank=True)
|
||||
|
33
forum/templates/forum/favorite_topics.jinja
Normal file
33
forum/templates/forum/favorite_topics.jinja
Normal file
@ -0,0 +1,33 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
{% from 'forum/macros.jinja' import display_topic %}
|
||||
|
||||
{% block title %}
|
||||
{% trans %}Favorite topics{% endtrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<p>
|
||||
<a href="{{ url('forum:main') }}">Forum</a> >
|
||||
<a href="{{ url('forum:favorite_topics') }}">{% trans %}Favorite topics{% endtrans %}</a>
|
||||
</p>
|
||||
<div id="forum">
|
||||
<h3>{% trans %}Forum{% endtrans %}</h3>
|
||||
<h4>{% trans %}Favorite topics{% endtrans %}</h4>
|
||||
{% for t in page_obj.object_list %}
|
||||
{% if user.can_view(t) %}
|
||||
{{ display_topic(t, user) }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
<p style="text-align: right; background: #d8e7f3;">
|
||||
{% for p in paginator.page_range %}
|
||||
<span class="ib" style="background: {% if p == paginator.number %}white{% endif %}; margin: 0;">
|
||||
<a href="?page={{ p }}">{{ p }}</a>
|
||||
</span>
|
||||
{% endfor %}
|
||||
</p>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
<h3>{% trans %}Forum{% endtrans %}</h3>
|
||||
<p>
|
||||
<a class="ib button" href="{{ url('forum:last_unread') }}">{% trans %}View last unread messages{% endtrans %}</a>
|
||||
<a class="ib button" href="{{ url('forum:favorite_topics') }}">{% trans %}Favorite topics{% endtrans %}</a>
|
||||
</p>
|
||||
{% if user.is_in_group(settings.SITH_GROUP_FORUM_ADMIN_ID) or user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID) %}
|
||||
<p>
|
||||
|
@ -37,7 +37,14 @@
|
||||
<h3>{{ topic.title }}</h3>
|
||||
<div id="forum">
|
||||
<p>{{ topic.description }}</p>
|
||||
<p><a href="{{ url('forum:new_message', topic_id=topic.id) }}">{% trans %}Reply{% endtrans %}</a></p>
|
||||
<p>
|
||||
<a class="ib button" href="{{ url('forum:new_message', topic_id=topic.id) }}">{% trans %}Reply{% endtrans %}</a>
|
||||
{% if user in topic.subscribed_users.all() %}
|
||||
<a class="ib button" href="{{ url('forum:toggle_subscribe_topic', topic_id=topic.id) }}">{% trans %}Unmark as favorite{% endtrans %}</a>
|
||||
{% else %}
|
||||
<a class="ib button" href="{{ url('forum:toggle_subscribe_topic', topic_id=topic.id) }}">{% trans %}Mark as favorite{% endtrans %}</a>
|
||||
{% endif %}
|
||||
</p>
|
||||
|
||||
<p style="text-align: right; background: #d8e7f3;">
|
||||
{% for p in msgs.paginator.page_range %}
|
||||
@ -56,7 +63,7 @@
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
<p><a href="{{ url('forum:new_message', topic_id=topic.id) }}">{% trans %}Reply{% endtrans %}</a></p>
|
||||
<p><a class="ib button" href="{{ url('forum:new_message', topic_id=topic.id) }}">{% trans %}Reply{% endtrans %}</a></p>
|
||||
|
||||
<p style="text-align: right; background: #d8e7f3;">
|
||||
{% for p in msgs.paginator.page_range %}
|
||||
|
@ -1,6 +1,6 @@
|
||||
# -*- coding:utf-8 -*
|
||||
#
|
||||
# Copyright 2016,2017
|
||||
# Copyright 2016,2017,2018
|
||||
# - Skia <skia@libskia.so>
|
||||
#
|
||||
# Ce fichier fait partie du site de l'Association des Étudiants de l'UTBM,
|
||||
@ -31,6 +31,7 @@ urlpatterns = [
|
||||
url(r'^new_forum$', ForumCreateView.as_view(), name='new_forum'),
|
||||
url(r'^mark_all_as_read$', ForumMarkAllAsRead.as_view(), name='mark_all_as_read'),
|
||||
url(r'^last_unread$', ForumLastUnread.as_view(), name='last_unread'),
|
||||
url(r'^favorite_topics$', ForumFavoriteTopics.as_view(), name='favorite_topics'),
|
||||
url(r'^(?P<forum_id>[0-9]+)$', ForumDetailView.as_view(), name='view_forum'),
|
||||
url(r'^(?P<forum_id>[0-9]+)/edit$', ForumEditView.as_view(), name='edit_forum'),
|
||||
url(r'^(?P<forum_id>[0-9]+)/delete$', ForumDeleteView.as_view(), name='delete_forum'),
|
||||
@ -38,6 +39,7 @@ urlpatterns = [
|
||||
url(r'^topic/(?P<topic_id>[0-9]+)$', ForumTopicDetailView.as_view(), name='view_topic'),
|
||||
url(r'^topic/(?P<topic_id>[0-9]+)/edit$', ForumTopicEditView.as_view(), name='edit_topic'),
|
||||
url(r'^topic/(?P<topic_id>[0-9]+)/new_message$', ForumMessageCreateView.as_view(), name='new_message'),
|
||||
url(r'^topic/(?P<topic_id>[0-9]+)/toggle_subscribe$', ForumTopicSubscribeView.as_view(), name='toggle_subscribe_topic'),
|
||||
url(r'^message/(?P<message_id>[0-9]+)$', ForumMessageView.as_view(), name='view_message'),
|
||||
url(r'^message/(?P<message_id>[0-9]+)/edit$', ForumMessageEditView.as_view(), name='edit_message'),
|
||||
url(r'^message/(?P<message_id>[0-9]+)/delete$', ForumMessageDeleteView.as_view(), name='delete_message'),
|
||||
|
@ -1,6 +1,6 @@
|
||||
# -*- coding:utf-8 -*
|
||||
#
|
||||
# Copyright 2016,2017
|
||||
# Copyright 2016,2017,2018
|
||||
# - Skia <skia@libskia.so>
|
||||
#
|
||||
# Ce fichier fait partie du site de l'Association des Étudiants de l'UTBM,
|
||||
@ -62,6 +62,15 @@ class ForumMarkAllAsRead(RedirectView):
|
||||
return super(ForumMarkAllAsRead, self).get(request, *args, **kwargs)
|
||||
|
||||
|
||||
class ForumFavoriteTopics(ListView):
|
||||
model = ForumTopic
|
||||
template_name = "forum/favorite_topics.jinja"
|
||||
paginate_by = settings.SITH_FORUM_PAGE_LENGTH / 2
|
||||
|
||||
def get_queryset(self):
|
||||
topic_list = self.request.user.favorite_topics.all()
|
||||
return topic_list
|
||||
|
||||
class ForumLastUnread(ListView):
|
||||
model = ForumTopic
|
||||
template_name = "forum/last_unread.jinja"
|
||||
@ -184,6 +193,22 @@ class ForumTopicEditView(CanEditMixin, UpdateView):
|
||||
pk_url_kwarg = "topic_id"
|
||||
template_name = "core/edit.jinja"
|
||||
|
||||
class ForumTopicSubscribeView(CanViewMixin, SingleObjectMixin, RedirectView):
|
||||
model = ForumTopic
|
||||
pk_url_kwarg = "topic_id"
|
||||
permanent = False
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
if request.user in self.object.subscribed_users.all():
|
||||
self.object.subscribed_users.remove(request.user)
|
||||
else:
|
||||
self.object.subscribed_users.add(request.user)
|
||||
return super().get(request, *args, **kwargs)
|
||||
|
||||
def get_redirect_url(self, *args, **kwargs):
|
||||
return self.object.get_absolute_url()
|
||||
|
||||
|
||||
class ForumTopicDetailView(CanViewMixin, DetailView):
|
||||
model = ForumTopic
|
||||
|
Reference in New Issue
Block a user