Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: For logged #272

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions spirit/comment/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@
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")),
(MOVED, _("topic moved")),
(CLOSED, _("topic closed")),
(UNCLOSED, _("topic unclosed")),
(PINNED, _("topic pinned")),
(UNPINNED, _("topic unpinned")))
(UNPINNED, _("topic unpinned")),
(FOR_LOGGED, _("topic for logged users")),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"logged users" -> "logged-in users"

(FOR_NON_LOGGED, _("topic for non logged users")),
)


class Comment(models.Model):
Expand Down
2 changes: 1 addition & 1 deletion spirit/topic/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions spirit/topic/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ def visible(self):

def opened(self):
return self.filter(is_closed=False)

def for_non_logged_users(self):
return self.filter(is_for_logged=False)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it may be better to change the visible filter to take a user parameter and do the (conditional) filtering there.

We would otherwise be adding this new filter everywhere where visible is used. Also, since we are breaking the visible API, then the test should fail in all the places where this filtering is required (i.e: the user profile comes to mind).


def global_(self):
return self.filter(category__is_global=True)
Expand Down Expand Up @@ -66,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)

Expand Down
1 change: 1 addition & 0 deletions spirit/topic/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be a better name would be is_login_required (like the decorator) or is_for_logged_in_users (but it's loooong)`

Don't forget to run the makemigrations command and commit the new migration file.


view_count = models.PositiveIntegerField(_("views count"), default=0)
comment_count = models.PositiveIntegerField(_("comment count"), default=0)
Expand Down
2 changes: 2 additions & 0 deletions spirit/topic/moderate/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@

url(r'^global-pin/(?P<pk>[0-9]+)/$', views.global_pin, name='global-pin'),
url(r'^global-unpin/(?P<pk>[0-9]+)/$', views.global_unpin, name='global-unpin'),
url(r'^for-logged/(?P<pk>[0-9]+)/$', views.for_logged, name='for-logged'),
url(r'^for-non-logged/(?P<pk>[0-9]+)/$', views.for_non_logged, name='for-non-logged'),
]
19 changes: 18 additions & 1 deletion spirit/topic/moderate/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)
12 changes: 12 additions & 0 deletions spirit/topic/templates/spirit/topic/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ <h1 class="headline">
</li>
{% endif %}

{% if topic.is_for_logged %}
<li>
<a class="menu-link js-post" href="{% url "spirit:topic:moderate:for-non-logged" topic.pk %}">
<i class="fa fa-thumb-tack"></i> {% trans "Set for non logged users" %}</a>
</li>
{% else %}
<li>
<a class="menu-link js-post" href="{% url "spirit:topic:moderate:for-logged" topic.pk %}">
<i class="fa fa-thumb-tack"></i> {% trans "Set for logged users" %}</a>
</li>
{% endif %}

{% if topic.is_globally_pinned %}
<li>
<a class="menu-link js-post" href="{% url "spirit:topic:moderate:global-unpin" topic.pk %}">
Expand Down
3 changes: 3 additions & 0 deletions spirit/topic/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ def index_active(request):
.order_by('-is_globally_pinned', '-last_active')
.select_related('category'))

if not request.user.is_authenticated:
topics = topics.for_non_logged_users()

topics = yt_paginate(
topics,
per_page=config.topics_per_page,
Expand Down