Example #1
0
    def test_make_read_aware_sets_read_flag_for_empty_forum(self):
        """make_read_aware sets read flag on empty forum"""
        forumstracker.make_read_aware(self.anon, self.forums)
        self.assertTrue(self.forum.is_read)

        forumstracker.make_read_aware(self.user, self.forums)
        self.assertTrue(self.forum.is_read)
Example #2
0
    def test_thread_read(self):
        """thread read flag is set for user, then its set as unread by reply"""
        add_acl(self.user, self.forums)
        threadstracker.make_read_aware(self.user, self.thread)
        self.assertFalse(self.thread.is_read)

        threadstracker.read_thread(self.user, self.thread, self.post)
        threadstracker.make_read_aware(self.user, self.thread)
        self.assertTrue(self.thread.is_read)
        forumstracker.make_read_aware(self.user, self.forums)
        self.assertTrue(self.forum.is_read)

        self.thread.last_post_on = timezone.now()
        self.thread.save()
        self.forum.synchronize()
        self.forum.save()

        self.reply_thread()
        threadstracker.make_read_aware(self.user, self.thread)
        self.assertFalse(self.thread.is_read)
        forumstracker.make_read_aware(self.user, self.forums)
        self.assertFalse(self.forum.is_read)

        posts = [post for post in self.thread.post_set.order_by('id')]
        threadstracker.make_posts_read_aware(self.thread, posts)

        for post in posts[:-1]:
            self.assertTrue(post.is_read)
        self.assertFalse(posts[-1].is_read)
Example #3
0
    def _test_thread_read(self):
        """thread read flag is set for user, then its set as unread by reply"""
        self.reply_thread(self.thread)

        add_acl(self.user, self.forums)
        threadstracker.make_read_aware(self.user, self.thread)
        self.assertFalse(self.thread.is_read)

        threadstracker.read_thread(self.user, self.thread, self.post)
        threadstracker.make_read_aware(self.user, self.thread)
        self.assertTrue(self.thread.is_read)
        forumstracker.make_read_aware(self.user, self.forums)
        self.assertTrue(self.forum.is_read)

        self.thread.last_post_on = timezone.now()
        self.thread.save()
        self.forum.synchronize()
        self.forum.save()

        self.reply_thread()
        threadstracker.make_read_aware(self.user, self.thread)
        self.assertFalse(self.thread.is_read)
        forumstracker.make_read_aware(self.user, self.forums)
        self.assertFalse(self.forum.is_read)

        posts = [post for post in self.thread.post_set.order_by('id')]
        threadstracker.make_posts_read_aware(self.user, self.thread, posts)

        for post in posts[:-1]:
            self.assertTrue(post.is_read)
        self.assertFalse(posts[-1].is_read)
Example #4
0
    def test_make_read_aware_sets_read_flag_for_empty_forum(self):
        """make_read_aware sets read flag on empty forum"""
        forumstracker.make_read_aware(self.anon, self.forums)
        self.assertTrue(self.forum.is_read)

        forumstracker.make_read_aware(self.user, self.forums)
        self.assertTrue(self.forum.is_read)
Example #5
0
    def test_sync_record_for_empty_forum(self):
        """sync_record sets read flag on empty forum"""
        add_acl(self.user, self.forums)
        forumstracker.sync_record(self.user, self.forum)
        self.user.forumread_set.get(forum=self.forum)

        forumstracker.make_read_aware(self.user, self.forums)
        self.assertTrue(self.forum.is_read)
Example #6
0
    def test_sync_record_for_empty_forum(self):
        """sync_record sets read flag on empty forum"""
        add_acl(self.user, self.forums)
        forumstracker.sync_record(self.user, self.forum)
        self.user.forumread_set.get(forum=self.forum)

        forumstracker.make_read_aware(self.user, self.forums)
        self.assertTrue(self.forum.is_read)
Example #7
0
    def __init__(self, user, forum):
        self.user = user
        self.forum = forum

        forumstracker.make_read_aware(user, forum)

        self.pinned_count = 0
        self.filter_by = None
        self.sort_by = '-last_post_on'
Example #8
0
    def __init__(self, user, forum):
        self.user = user
        self.forum = forum

        forumstracker.make_read_aware(user, forum)

        self.pinned_count = 0
        self.filter_by = None
        self.sort_by = '-last_post_on'
Example #9
0
    def test_sync_record_for_forum_with_deleted_threads(self):
        """unread forum reverts to read after its emptied"""
        self.post_thread(cutoff_date() + timedelta(days=1))
        self.post_thread(cutoff_date() + timedelta(days=1))
        self.post_thread(cutoff_date() + timedelta(days=1))

        add_acl(self.user, self.forums)
        forumstracker.sync_record(self.user, self.forum)
        forumstracker.make_read_aware(self.user, self.forums)
        self.assertFalse(self.forum.is_read)

        self.forum.thread_set.all().delete()
        self.forum.synchronize()
        self.forum.save()

        forumstracker.make_read_aware(self.user, self.forums)
        self.assertTrue(self.forum.is_read)
Example #10
0
    def test_sync_record_for_forum_with_deleted_threads(self):
        """unread forum reverts to read after its emptied"""
        self.post_thread(self.user.joined_on + timedelta(days=1))
        self.post_thread(self.user.joined_on + timedelta(days=1))
        self.post_thread(self.user.joined_on + timedelta(days=1))

        add_acl(self.user, self.forums)
        forumstracker.sync_record(self.user, self.forum)
        forumstracker.make_read_aware(self.user, self.forums)
        self.assertFalse(self.forum.is_read)

        self.forum.thread_set.all().delete()
        self.forum.synchronize()
        self.forum.save()

        forumstracker.make_read_aware(self.user, self.forums)
        self.assertTrue(self.forum.is_read)
Example #11
0
    def test_read_all_threads(self):
        """read_all view updates reads cutoff on user model"""
        forum = Forum.objects.all_forums().filter(role="forum")[:1][0]
        threads = [testutils.post_thread(forum) for t in xrange(10)]

        forum = Forum.objects.get(id=forum.id)
        make_read_aware(self.user, [forum])
        self.assertFalse(forum.is_read)

        response = self.client.post(reverse('misago:read_all'))
        self.assertEqual(response.status_code, 302)

        forum = Forum.objects.get(id=forum.id)
        user = get_user_model().objects.get(id=self.user.id)

        make_read_aware(user, [forum])
        self.assertTrue(forum.is_read)
Example #12
0
    def test_sync_record_for_forum_with_many_threads(self):
        """sync_record sets unread flag on forum with many threads"""
        self.post_thread(self.user.joined_on + timedelta(days=1))
        self.post_thread(self.user.joined_on - timedelta(days=1))
        self.post_thread(self.user.joined_on + timedelta(days=1))
        self.post_thread(self.user.joined_on - timedelta(days=1))

        add_acl(self.user, self.forums)
        forumstracker.sync_record(self.user, self.forum)
        self.user.forumread_set.get(forum=self.forum)

        forumstracker.make_read_aware(self.user, self.forums)
        self.assertFalse(self.forum.is_read)

        self.post_thread(self.user.joined_on + timedelta(days=1))
        forumstracker.sync_record(self.user, self.forum)
        forumstracker.make_read_aware(self.user, self.forums)
        self.assertFalse(self.forum.is_read)
Example #13
0
    def test_sync_record_for_forum_with_new_thread(self):
        """
        sync_record sets read flag on forum with old thread,
        then keeps flag to unread when new reply is posted
        """
        self.post_thread(self.user.joined_on + timedelta(days=1))

        add_acl(self.user, self.forums)
        forumstracker.sync_record(self.user, self.forum)
        self.user.forumread_set.get(forum=self.forum)

        forumstracker.make_read_aware(self.user, self.forums)
        self.assertFalse(self.forum.is_read)

        self.post_thread(self.user.joined_on + timedelta(days=1))
        forumstracker.sync_record(self.user, self.forum)
        forumstracker.make_read_aware(self.user, self.forums)
        self.assertFalse(self.forum.is_read)
Example #14
0
    def test_sync_record_for_forum_with_new_thread(self):
        """
        sync_record sets read flag on forum with old thread,
        then keeps flag to unread when new reply is posted
        """
        self.post_thread(cutoff_date() + timedelta(days=1))

        add_acl(self.user, self.forums)
        forumstracker.sync_record(self.user, self.forum)
        self.user.forumread_set.get(forum=self.forum)

        forumstracker.make_read_aware(self.user, self.forums)
        self.assertFalse(self.forum.is_read)

        self.post_thread(cutoff_date() + timedelta(days=1))
        forumstracker.sync_record(self.user, self.forum)
        forumstracker.make_read_aware(self.user, self.forums)
        self.assertFalse(self.forum.is_read)
Example #15
0
    def test_sync_record_for_forum_with_many_threads(self):
        """sync_record sets unread flag on forum with many threads"""
        self.post_thread(cutoff_date() + timedelta(days=1))
        self.post_thread(cutoff_date() - timedelta(days=1))
        self.post_thread(cutoff_date() + timedelta(days=1))
        self.post_thread(cutoff_date() - timedelta(days=1))

        add_acl(self.user, self.forums)
        forumstracker.sync_record(self.user, self.forum)
        self.user.forumread_set.get(forum=self.forum)

        forumstracker.make_read_aware(self.user, self.forums)
        self.assertFalse(self.forum.is_read)

        self.post_thread(cutoff_date() + timedelta(days=1))
        forumstracker.sync_record(self.user, self.forum)
        forumstracker.make_read_aware(self.user, self.forums)
        self.assertFalse(self.forum.is_read)
Example #16
0
    def test_sync_record_for_forum_with_old_thread_and_reply(self):
        """
        sync_record sets read flag on forum with old thread,
        then changes flag to unread when new reply is posted
        """
        self.post_thread(self.user.reads_cutoff - timedelta(days=1))

        add_acl(self.user, self.forums)
        forumstracker.sync_record(self.user, self.forum)
        self.user.forumread_set.get(forum=self.forum)

        forumstracker.make_read_aware(self.user, self.forums)
        self.assertTrue(self.forum.is_read)

        thread = self.post_thread(self.user.reads_cutoff + timedelta(days=1))
        forumstracker.sync_record(self.user, self.forum)
        forumstracker.make_read_aware(self.user, self.forums)
        self.assertFalse(self.forum.is_read)
Example #17
0
    def test_sync_record_for_forum_with_old_thread_and_reply(self):
        """
        sync_record sets read flag on forum with old thread,
        then changes flag to unread when new reply is posted
        """
        self.post_thread(self.user.reads_cutoff - timedelta(days=1))

        add_acl(self.user, self.forums)
        forumstracker.sync_record(self.user, self.forum)
        self.user.forumread_set.get(forum=self.forum)

        forumstracker.make_read_aware(self.user, self.forums)
        self.assertTrue(self.forum.is_read)

        thread = self.post_thread(self.user.reads_cutoff + timedelta(days=1))
        forumstracker.sync_record(self.user, self.forum)
        forumstracker.make_read_aware(self.user, self.forums)
        self.assertFalse(self.forum.is_read)
Example #18
0
    def test_read_forum(self):
        """read_forum view updates reads cutoff on forum tracker"""
        forum = Forum.objects.all_forums().filter(role="forum")[:1][0]
        threads = [testutils.post_thread(forum) for t in xrange(10)]

        forum = Forum.objects.get(id=forum.id)
        make_read_aware(self.user, [forum])
        self.assertFalse(forum.is_read)

        response = self.client.post(
            reverse('misago:read_forum', kwargs={'forum_id': forum.id}))
        self.assertEqual(response.status_code, 302)
        self.assertTrue(
            response['location'].endswith(forum.get_absolute_url()))

        forum = Forum.objects.get(id=forum.id)
        user = get_user_model().objects.get(id=self.user.id)

        make_read_aware(user, [forum])
        self.assertTrue(forum.is_read)
Example #19
0
def get_forums_list(user, parent=None):
    if not user.acl['visible_forums']:
        return []

    if parent:
        queryset = parent.get_descendants().order_by('lft')
    else:
        queryset = Forum.objects.all_forums()
    queryset_with_acl = queryset.filter(id__in=user.acl['visible_forums'])

    visible_forums = [f for f in queryset_with_acl]

    forums_dict = {}
    forums_list = []

    parent_level = parent.level + 1 if parent else 1

    for forum in visible_forums:
        forum.subforums = []
        forums_dict[forum.pk] = forum
        forums_list.append(forum)

        if forum.level > parent_level:
            forums_dict[forum.parent_id].subforums.append(forum)

    add_acl(user, forums_list)
    forumstracker.make_read_aware(user, forums_list)

    for forum in reversed(visible_forums):
        if forum.acl['can_browse']:
            forum_parent = forums_dict.get(forum.parent_id)
            if forum_parent:
                forum_parent.threads += forum.threads
                forum_parent.posts += forum.posts

                if forum_parent.last_post_on and forum.last_post_on:
                    parent_last_post = forum_parent.last_post_on
                    forum_last_post = forum.last_post_on
                    update_last_thead = parent_last_post < forum_last_post
                elif not forum_parent.last_post_on and forum.last_post_on:
                    update_last_thead = True
                else:
                    update_last_thead = False

                if update_last_thead:
                    forum_parent.last_post_on = forum.last_post_on
                    forum_parent.last_thread_id = forum.last_thread_id
                    forum_parent.last_thread_title = forum.last_thread_title
                    forum_parent.last_thread_slug = forum.last_thread_slug
                    forum_parent.last_poster_name = forum.last_poster_name
                    forum_parent.last_poster_slug = forum.last_poster_slug

                if not forum.is_read:
                    forum_parent.is_read = False

    flat_list = []
    for forum in forums_list:
        if forum.role != "category" or forum.subforums:
            flat_list.append(forum)

    return flat_list
Example #20
0
    def test_make_read_aware_sets_unread_flag_for_forum_with_new_thread(self):
        """make_read_aware sets unread flag on forum with new thread"""
        self.forum.last_post_on = cutoff_date() + timedelta(days=1)

        forumstracker.make_read_aware(self.user, self.forums)
        self.assertFalse(self.forum.is_read)
Example #21
0
    def test_make_read_aware_sets_read_flag_for_forum_with_old_thread(self):
        """make_read_aware sets read flag on forum with old thread"""
        self.forum.last_post_on = cutoff_date() - timedelta(days=1)

        forumstracker.make_read_aware(self.user, self.forums)
        self.assertTrue(self.forum.is_read)
Example #22
0
 def test_anon_empty_forum_read(self):
     """anon users content is always read"""
     forumstracker.make_read_aware(self.anon, self.forums)
     self.assertIsNone(self.forum.last_post_on)
     self.assertTrue(self.forum.is_read)
Example #23
0
    def test_make_read_aware_sets_read_flag_for_forum_with_old_thread(self):
        """make_read_aware sets read flag on forum with old thread"""
        self.forum.last_post_on = self.user.joined_on - timedelta(days=1)

        forumstracker.make_read_aware(self.user, self.forums)
        self.assertTrue(self.forum.is_read)
Example #24
0
 def test_anon_forum_with_recent_reply_read(self):
     """anon users content is always read"""
     forumstracker.make_read_aware(self.anon, self.forums)
     self.forum.last_post_on = timezone.now()
     self.assertTrue(self.forum.is_read)
Example #25
0
 def test_anon_empty_forum_read(self):
     """anon users content is always read"""
     forumstracker.make_read_aware(self.anon, self.forums)
     self.assertIsNone(self.forum.last_post_on)
     self.assertTrue(self.forum.is_read)
Example #26
0
 def test_anon_forum_with_recent_reply_read(self):
     """anon users content is always read"""
     forumstracker.make_read_aware(self.anon, self.forums)
     self.forum.last_post_on = timezone.now()
     self.assertTrue(self.forum.is_read)
Example #27
0
 def test_empty_forum_is_read(self):
     """empty forum is read for signed in user"""
     forumstracker.make_read_aware(self.user, self.forums)
     self.assertTrue(self.forum.is_read)
Example #28
0
def get_forums_list(user, parent=None):
    if not user.acl['visible_forums']:
        return []

    if parent:
        queryset = parent.get_descendants().order_by('lft')
    else:
        queryset = Forum.objects.all_forums()
    queryset_with_acl = queryset.filter(id__in=user.acl['visible_forums'])

    visible_forums = [f for f in queryset_with_acl]

    forums_dict = {}
    forums_list = []

    parent_level = parent.level + 1 if parent else 1

    for forum in visible_forums:
        forum.subforums = []
        forums_dict[forum.pk] = forum
        forums_list.append(forum)

        if forum.level > parent_level:
            forums_dict[forum.parent_id].subforums.append(forum)

    add_acl(user, forums_list)
    forumstracker.make_read_aware(user, forums_list)

    for forum in reversed(visible_forums):
        if forum.acl['can_browse']:
            forum_parent = forums_dict.get(forum.parent_id)
            if forum_parent:
                forum_parent.threads += forum.threads
                forum_parent.posts += forum.posts

                if forum_parent.last_post_on and forum.last_post_on:
                    parent_last_post = forum_parent.last_post_on
                    forum_last_post = forum.last_post_on
                    update_last_thead = parent_last_post < forum_last_post
                elif not forum_parent.last_post_on and forum.last_post_on:
                    update_last_thead = True
                else:
                    update_last_thead = False

                if update_last_thead:
                    forum_parent.last_post_on = forum.last_post_on
                    forum_parent.last_thread_id = forum.last_thread_id
                    forum_parent.last_thread_title = forum.last_thread_title
                    forum_parent.last_thread_slug = forum.last_thread_slug
                    forum_parent.last_poster_name = forum.last_poster_name
                    forum_parent.last_poster_slug = forum.last_poster_slug

                if not forum.is_read:
                    forum_parent.is_read = False

    flat_list = []
    for forum in forums_list:
        if forum.role != "category" or forum.subforums:
            flat_list.append(forum)

    return flat_list
Example #29
0
 def test_empty_forum_is_read(self):
     """empty forum is read for signed in user"""
     forumstracker.make_read_aware(self.user, self.forums)
     self.assertTrue(self.forum.is_read)
Example #30
0
    def test_make_read_aware_sets_unread_flag_for_forum_with_new_thread(self):
        """make_read_aware sets unread flag on forum with new thread"""
        self.forum.last_post_on = self.user.joined_on + timedelta(days=1)

        forumstracker.make_read_aware(self.user, self.forums)
        self.assertFalse(self.forum.is_read)