From 862a4b02910afa4caca7969355ce7ee1c93b409a Mon Sep 17 00:00:00 2001 From: Uriel Mehamed Date: Tue, 7 May 2019 09:59:24 +0100 Subject: [PATCH 1/2] New topic property, is_for_logged. --- spirit/topic/forms.py | 2 +- spirit/topic/managers.py | 3 +++ spirit/topic/models.py | 1 + spirit/topic/templates/spirit/topic/detail.html | 12 ++++++++++++ spirit/topic/views.py | 3 +++ 5 files changed, 20 insertions(+), 1 deletion(-) diff --git a/spirit/topic/forms.py b/spirit/topic/forms.py index 21f3de716..1f5796b0e 100644 --- a/spirit/topic/forms.py +++ b/spirit/topic/forms.py @@ -22,7 +22,7 @@ class TopicForm(forms.ModelForm): class Meta: model = Topic - fields = ('title', 'category') + fields = ('title', 'category', 'is_for_logged') def __init__(self, user, *args, **kwargs): super(TopicForm, self).__init__(*args, **kwargs) diff --git a/spirit/topic/managers.py b/spirit/topic/managers.py index 95d014b42..533025304 100644 --- a/spirit/topic/managers.py +++ b/spirit/topic/managers.py @@ -25,6 +25,9 @@ def visible(self): def opened(self): return self.filter(is_closed=False) + + def for_logged_users(self): + return self.filter(is_for_logged=True) def global_(self): return self.filter(category__is_global=True) diff --git a/spirit/topic/models.py b/spirit/topic/models.py index 425b69cad..007f8644c 100644 --- a/spirit/topic/models.py +++ b/spirit/topic/models.py @@ -44,6 +44,7 @@ class Topic(models.Model): is_globally_pinned = models.BooleanField(_("globally pinned"), default=False) is_closed = models.BooleanField(_("closed"), default=False) is_removed = models.BooleanField(default=False) + is_for_logged = models.BooleanField(_("is for logged"), default=False) view_count = models.PositiveIntegerField(_("views count"), default=0) comment_count = models.PositiveIntegerField(_("comment count"), default=0) diff --git a/spirit/topic/templates/spirit/topic/detail.html b/spirit/topic/templates/spirit/topic/detail.html index 300adf99a..657f3de74 100644 --- a/spirit/topic/templates/spirit/topic/detail.html +++ b/spirit/topic/templates/spirit/topic/detail.html @@ -97,6 +97,18 @@

{% endif %} + {% if topic.is_for_logged %} +
  • + + {% trans "Set for non logged users" %} +
  • + {% else %} +
  • + + {% trans "Set for logged users" %} +
  • + {% endif %} + {% if topic.is_globally_pinned %}
  • diff --git a/spirit/topic/views.py b/spirit/topic/views.py index 6a3158e9a..e96ad4698 100644 --- a/spirit/topic/views.py +++ b/spirit/topic/views.py @@ -123,6 +123,9 @@ def index_active(request): .order_by('-is_globally_pinned', '-last_active') .select_related('category')) + if request.user.is_authenticated: + topics = topics.for_logged_users() + topics = yt_paginate( topics, per_page=config.topics_per_page, From 9f0743061db918431866f6ddfcc3e49a533ec0fc Mon Sep 17 00:00:00 2001 From: Uriel Mehamed Date: Mon, 27 May 2019 20:38:34 +0100 Subject: [PATCH 2/2] Actions, moderate views, urls, templates. --- spirit/comment/models.py | 8 ++++++-- spirit/topic/managers.py | 5 +++-- spirit/topic/moderate/urls.py | 2 ++ spirit/topic/moderate/views.py | 19 ++++++++++++++++++- .../topic/templates/spirit/topic/detail.html | 4 ++-- spirit/topic/views.py | 4 ++-- 6 files changed, 33 insertions(+), 9 deletions(-) diff --git a/spirit/comment/models.py b/spirit/comment/models.py index 59aa17d4e..675cbcccf 100644 --- a/spirit/comment/models.py +++ b/spirit/comment/models.py @@ -11,7 +11,8 @@ from ..core.conf import settings from .managers import CommentQuerySet -COMMENT, MOVED, CLOSED, UNCLOSED, PINNED, UNPINNED = range(6) +(COMMENT, MOVED, CLOSED, UNCLOSED, PINNED, +UNPINNED, FOR_LOGGED, FOR_NON_LOGGED) = range(8) ACTION = ( (COMMENT, _("comment")), @@ -19,7 +20,10 @@ (CLOSED, _("topic closed")), (UNCLOSED, _("topic unclosed")), (PINNED, _("topic pinned")), - (UNPINNED, _("topic unpinned"))) + (UNPINNED, _("topic unpinned")), + (FOR_LOGGED, _("topic for logged users")), + (FOR_NON_LOGGED, _("topic for non logged users")), + ) class Comment(models.Model): diff --git a/spirit/topic/managers.py b/spirit/topic/managers.py index 533025304..ee8d39074 100644 --- a/spirit/topic/managers.py +++ b/spirit/topic/managers.py @@ -26,8 +26,8 @@ def visible(self): def opened(self): return self.filter(is_closed=False) - def for_logged_users(self): - return self.filter(is_for_logged=True) + def for_non_logged_users(self): + return self.filter(is_for_logged=False) def global_(self): return self.filter(category__is_global=True) @@ -69,6 +69,7 @@ def get_public_or_404(self, pk, user): else: return get_object_or_404( self.visible() + .for_non_logged_users() .select_related('category__parent'), pk=pk) diff --git a/spirit/topic/moderate/urls.py b/spirit/topic/moderate/urls.py index 2e48abefa..a62303aa5 100644 --- a/spirit/topic/moderate/urls.py +++ b/spirit/topic/moderate/urls.py @@ -20,4 +20,6 @@ url(r'^global-pin/(?P[0-9]+)/$', views.global_pin, name='global-pin'), url(r'^global-unpin/(?P[0-9]+)/$', views.global_unpin, name='global-unpin'), + url(r'^for-logged/(?P[0-9]+)/$', views.for_logged, name='for-logged'), + url(r'^for-non-logged/(?P[0-9]+)/$', views.for_non_logged, name='for-non-logged'), ] diff --git a/spirit/topic/moderate/views.py b/spirit/topic/moderate/views.py index 1e59c75b1..981a26d68 100644 --- a/spirit/topic/moderate/views.py +++ b/spirit/topic/moderate/views.py @@ -6,7 +6,8 @@ from django.shortcuts import render, redirect, get_object_or_404 from ...core.utils.decorators import moderator_required -from ...comment.models import Comment, CLOSED, UNCLOSED, PINNED, UNPINNED +from ...comment.models import (Comment, CLOSED, UNCLOSED, PINNED, UNPINNED, + FOR_LOGGED, FOR_NON_LOGGED) from ..models import Topic @@ -103,3 +104,19 @@ def global_unpin(request, pk): field_name='is_globally_pinned', to_value=False, action=UNPINNED) + +def for_logged(request, pk): + return _moderate( + request=request, + pk=pk, + field_name='is_for_logged', + to_value=True, + action=FOR_LOGGED) + +def for_non_logged(request, pk): + return _moderate( + request=request, + pk=pk, + field_name='is_for_logged', + to_value=False, + action=FOR_NON_LOGGED) diff --git a/spirit/topic/templates/spirit/topic/detail.html b/spirit/topic/templates/spirit/topic/detail.html index 657f3de74..f469d0da7 100644 --- a/spirit/topic/templates/spirit/topic/detail.html +++ b/spirit/topic/templates/spirit/topic/detail.html @@ -99,12 +99,12 @@

    {% if topic.is_for_logged %}
  • - + {% trans "Set for non logged users" %}
  • {% else %}
  • - + {% trans "Set for logged users" %}
  • {% endif %} diff --git a/spirit/topic/views.py b/spirit/topic/views.py index e96ad4698..8dcb73900 100644 --- a/spirit/topic/views.py +++ b/spirit/topic/views.py @@ -123,8 +123,8 @@ def index_active(request): .order_by('-is_globally_pinned', '-last_active') .select_related('category')) - if request.user.is_authenticated: - topics = topics.for_logged_users() + if not request.user.is_authenticated: + topics = topics.for_non_logged_users() topics = yt_paginate( topics,