-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
User topics view added (including some tests)
- Loading branch information
Showing
10 changed files
with
204 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Standard library imports | ||
# Third party imports | ||
from django.conf.urls import patterns | ||
from django.conf.urls import url | ||
from django.utils.translation import ugettext_lazy as _ | ||
|
||
# Local application / specific library imports | ||
from machina.core.app import Application | ||
from machina.core.loading import get_class | ||
|
||
|
||
class MemberApp(Application): | ||
name = 'forum-member' | ||
|
||
user_topics_view = get_class('forum_member.views', 'UserTopicsView') | ||
|
||
def get_urls(self): | ||
urls = [ | ||
url(_(r'^ego/topics/$'), self.user_topics_view.as_view(), name='user-topics'), | ||
] | ||
return patterns('', *urls) | ||
|
||
|
||
application = MemberApp() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Standard library imports | ||
# Third party imports | ||
from django.contrib.auth.decorators import login_required | ||
from django.utils.decorators import method_decorator | ||
from django.views.generic import ListView | ||
|
||
# Local application / specific library imports | ||
from machina.conf import settings as machina_settings | ||
from machina.core.db.models import get_model | ||
from machina.core.loading import get_class | ||
|
||
Forum = get_model('forum', 'Forum') | ||
Topic = get_model('forum_conversation', 'Topic') | ||
|
||
PermissionHandler = get_class('forum_permission.handler', 'PermissionHandler') | ||
perm_handler = PermissionHandler() | ||
|
||
|
||
class UserTopicsView(ListView): | ||
template_name = 'forum_member/user_topics_list.html' | ||
context_object_name = 'topics' | ||
paginate_by = machina_settings.FORUM_TOPICS_NUMBER_PER_PAGE | ||
|
||
def get_queryset(self): | ||
forums = perm_handler.forum_list_filter( | ||
Forum.objects.all(), self.request.user) | ||
topics = Topic.objects.filter( | ||
forum__in=forums, | ||
posts__poster_id=self.request.user.id, | ||
posts__approved=True) | ||
return topics.order_by('-updated') | ||
|
||
@method_decorator(login_required) | ||
def dispatch(self, request, *args, **kwargs): | ||
return super(UserTopicsView, self).dispatch(request, *args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
#main_container{ | ||
margin-bottom: 40px; | ||
|
||
.moderation-link-wrapper{ | ||
.controls-link-wrapper{ | ||
margin-top: -20px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
machina/templates/machina/forum_member/user_topics_list.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{% extends 'board_base.html' %} | ||
{% load i18n %} | ||
|
||
{% block sub-title %}{% trans "View my messages" %}{% endblock sub-title %} | ||
|
||
|
||
{% block content %} | ||
<div class="row"> | ||
<div class="col-xs-12"> | ||
<h1>{% trans "View my messages" %}</h1> | ||
</div> | ||
</div> | ||
<div class="row"> | ||
<div class="col-xs-6 col-md-4 forum-actions-block"> | ||
{% if paginator.count > 0 %} | ||
<p class="text-muted"> | ||
{% blocktrans with paginator.count as topic_length %}{{ topic_length }} topics found{% endblocktrans %} | ||
</p> | ||
{% endif %} | ||
</div> | ||
<div class="col-xs-12 col-md-8 pagination-block"> | ||
{% with "pagination-sm" as pagination_size %} | ||
{% include "machina/partials/pagination.html" %} | ||
{% endwith %} | ||
</div> | ||
</div> | ||
{% trans "Not topics found." as empty_message %} | ||
{% with topic_list_title="Topics" empty_message=empty_message %} | ||
{% include "machina/forum_conversation/topic_list.html" %} | ||
{% endwith %} | ||
<div class="row"> | ||
<div class="col-xs-12 col-md-12 pagination-block"> | ||
{% with "pagination-sm" as pagination_size %} | ||
{% include "machina/partials/pagination.html" %} | ||
{% endwith %} | ||
</div> | ||
</div> | ||
{% endblock content %} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Standard library imports | ||
# Third party imports | ||
from django.core.urlresolvers import reverse | ||
from guardian.shortcuts import assign_perm | ||
|
||
# Local application / specific library imports | ||
from machina.core.loading import get_class | ||
from machina.test.factories import create_category_forum | ||
from machina.test.factories import create_forum | ||
from machina.test.factories import create_topic | ||
from machina.test.factories import GroupFactory | ||
from machina.test.factories import PostFactory | ||
from machina.test.factories import UserFactory | ||
from machina.test.testcases import BaseClientTestCase | ||
|
||
PermissionHandler = get_class('forum_permission.handler', 'PermissionHandler') | ||
|
||
|
||
class TestUserTopicsView(BaseClientTestCase): | ||
def setUp(self): | ||
super(TestUserTopicsView, self).setUp() | ||
|
||
# Add some users | ||
self.u1 = UserFactory.create() | ||
self.g1 = GroupFactory.create() | ||
self.u1.groups.add(self.g1) | ||
self.user.groups.add(self.g1) | ||
|
||
# Permission handler | ||
self.perm_handler = PermissionHandler() | ||
|
||
self.top_level_cat_1 = create_category_forum() | ||
|
||
self.forum_1 = create_forum(parent=self.top_level_cat_1) | ||
self.forum_2 = create_forum(parent=self.top_level_cat_1) | ||
self.forum_3 = create_forum(parent=self.top_level_cat_1) | ||
|
||
self.topic_1 = create_topic(forum=self.forum_2, poster=self.u1) | ||
PostFactory.create(topic=self.topic_1, poster=self.u1) | ||
PostFactory.create(topic=self.topic_1, poster=self.user) | ||
|
||
self.topic_2 = create_topic(forum=self.forum_1, poster=self.user) | ||
PostFactory.create(topic=self.topic_2, poster=self.user) | ||
PostFactory.create(topic=self.topic_2, poster=self.u1) | ||
|
||
self.topic_3 = create_topic(forum=self.forum_2, poster=self.u1) | ||
PostFactory.create(topic=self.topic_3, poster=self.u1) | ||
|
||
self.topic_4 = create_topic(forum=self.forum_2, poster=self.user) | ||
PostFactory.create(topic=self.topic_4, poster=self.user) | ||
|
||
# Assign some permissions | ||
assign_perm('can_read_forum', self.g1, self.top_level_cat_1) | ||
assign_perm('can_read_forum', self.g1, self.forum_1) | ||
assign_perm('can_read_forum', self.g1, self.forum_2) | ||
|
||
def test_browsing_works(self): | ||
# Setup | ||
correct_url = reverse('forum-member:user-topics') | ||
# Run | ||
response = self.client.get(correct_url, follow=True) | ||
# Check | ||
self.assertIsOk(response) | ||
|
||
|
||
def test_insert_only_topics_where_the_considered_user_participated_in_the_context(self): | ||
# Setup | ||
correct_url = reverse('forum-member:user-topics') | ||
# Run | ||
response = self.client.get(correct_url, follow=True) | ||
# Check | ||
self.assertIsOk(response) | ||
self.assertQuerysetEqual( | ||
response.context_data['topics'], | ||
[self.topic_4, self.topic_2, self.topic_1, ]) | ||
|
||
def test_does_not_consider_non_approved_posts(self): | ||
# Setup | ||
topic_5 = create_topic(forum=self.forum_2, poster=self.user) | ||
PostFactory.create(topic=topic_5, poster=self.user, approved=False) | ||
correct_url = reverse('forum-member:user-topics') | ||
# Run | ||
response = self.client.get(correct_url, follow=True) | ||
# Check | ||
self.assertIsOk(response) | ||
self.assertQuerysetEqual( | ||
response.context_data['topics'], | ||
[self.topic_4, self.topic_2, self.topic_1, ]) |