Example #1
0
def get_threads_queryset(user, categories, list_type):
    queryset = exclude_invisible_threads(user, categories, Thread.objects)

    if list_type == 'all':
        return queryset
    else:
        return filter_threads_queryset(user, categories, list_type, queryset)
Example #2
0
    def list(self, page=0):
        queryset = exclude_invisible_threads(
            self.user, self.forum, self.forum.thread_set)
        queryset = self.filter_threads(queryset)
        queryset = queryset.order_by(*self.sort_by)

        announcements_qs = queryset.filter(weight=ANNOUNCEMENT)
        threads_qs = queryset.filter(weight__lt=ANNOUNCEMENT)

        self._page = paginate(threads_qs, page, 20, 10)
        self._paginator = self._page.paginator

        threads = []
        for announcement in announcements_qs:
            threads.append(announcement)
        for thread in self._page.object_list:
            threads.append(thread)

        for thread in threads:
            thread.forum = self.forum

        self.label_threads(threads, self.forum.labels)
        self.make_threads_read_aware(threads)

        return threads
Example #3
0
def sync_record(user, forum):
    recorded_threads = forum.thread_set.filter(last_post_on__gt=user.joined_on)
    recorded_threads = exclude_invisible_threads(recorded_threads, user, forum)

    all_threads_count = recorded_threads.count()

    read_threads = user.threadread_set.filter(
        forum=forum, last_read_on__gt=user.joined_on)
    read_threads_count = read_threads.filter(
        thread__last_post_on__lte=F("last_read_on")).count()

    forum_is_read = read_threads_count == all_threads_count

    if forum_is_read:
        signals.forum_read.send(sender=user, forum=forum)

    try:
        forum_record = user.forumread_set.filter(forum=forum).all()[0]
        forum_record.last_updated_on = timezone.now()
        if forum_is_read:
            forum_record.last_cleared_on = forum_record.last_updated_on
        else:
            forum_record.last_cleared_on = user.joined_on
        forum_record.save(update_fields=['last_updated_on', 'last_cleared_on'])
    except IndexError:
        if forum_is_read:
            cleared_on = timezone.now()
        else:
            cleared_on = user.joined_on

        forum_record = user.forumread_set.create(
            forum=forum,
            last_updated_on=timezone.now(),
            last_cleared_on=cleared_on)
Example #4
0
def make_read_aware(user, categories):
    if not categories:
        return

    if not hasattr(categories, '__iter__'):
        categories = [categories]

    make_read(categories)

    if user.is_anonymous:
        return

    threads = Thread.objects.filter(category__in=categories)
    threads = exclude_invisible_threads(user, categories, threads)

    queryset = Post.objects.filter(
        category__in=categories,
        thread__in=threads,
        posted_on__gt=get_cutoff_date(user),
    ).values_list('category', flat=True).distinct()

    queryset = queryset.exclude(id__in=user.postread_set.values('post'))
    queryset = exclude_invisible_posts(user, categories, queryset)

    unread_categories = list(queryset)

    for category in categories:
        if category.pk in unread_categories:
            category.is_read = False
            category.is_new = True
Example #5
0
def get_threads_queryset(user, categories, list_type):
    queryset = exclude_invisible_threads(user, categories, Thread.objects)

    if list_type == 'all':
        return queryset
    else:
        return filter_threads_queryset(user, categories, list_type, queryset)
Example #6
0
    def get_queryset(self):
        cutoff_days = settings.MISAGO_FRESH_CONTENT_PERIOD
        cutoff_date = timezone.now() - timedelta(days=cutoff_days)
        if cutoff_date < self.user.joined_on:
            cutoff_date = self.user.joined_on

        queryset = Thread.objects.filter(started_on__gte=cutoff_date)
        queryset = queryset.select_related('forum')

        tracked_threads = self.user.threadread_set.all()
        queryset = queryset.exclude(id__in=tracked_threads.values('thread_id'))
        queryset = exclude_invisible_threads(queryset, self.user)
        return queryset
Example #7
0
    def get_queryset(self):
        cutoff_days = settings.MISAGO_FRESH_CONTENT_PERIOD
        cutoff_date = timezone.now() - timedelta(days=cutoff_days)
        if cutoff_date < self.user.joined_on:
            cutoff_date = self.user.joined_on

        queryset = Thread.objects.filter(started_on__gte=cutoff_date)
        queryset = queryset.select_related('forum')

        tracked_threads = self.user.threadread_set.all()
        queryset = queryset.exclude(id__in=tracked_threads.values('thread_id'))
        queryset = exclude_invisible_threads(queryset, self.user)
        return queryset
Example #8
0
    def get_queryset(self):
        cutoff_days = settings.MISAGO_FRESH_CONTENT_PERIOD
        cutoff_date = timezone.now() - timedelta(days=cutoff_days)
        if cutoff_date < self.user.joined_on:
            cutoff_date = self.user.joined_on

        queryset = Thread.objects.filter(last_post_on__gte=cutoff_date)
        queryset = queryset.select_related('forum')
        queryset = queryset.filter(threadread__user=self.user)
        queryset = queryset.filter(
            threadread__last_read_on__lt=F('last_post_on'))
        queryset = exclude_invisible_threads(queryset, self.user)
        return queryset
Example #9
0
    def get_queryset(self):
        cutoff_days = settings.MISAGO_FRESH_CONTENT_PERIOD
        cutoff_date = timezone.now() - timedelta(days=cutoff_days)
        if cutoff_date < self.user.joined_on:
            cutoff_date = self.user.joined_on

        queryset = Thread.objects.filter(last_post_on__gte=cutoff_date)
        queryset = queryset.select_related('forum')
        queryset = queryset.filter(threadread__user=self.user)
        queryset = queryset.filter(
            threadread__last_read_on__lt=F('last_post_on'))
        queryset = exclude_invisible_threads(queryset, self.user)
        return queryset
Example #10
0
def sync_record(user, category):
    cutoff_date = user.joined_on

    try:
        category_record = user.categoryread_set.get(category=category)
        if category_record.last_read_on > cutoff_date:
            cutoff_date = category_record.last_read_on
    except CategoryRead.DoesNotExist:
        category_record = None

    recorded_threads = category.thread_set.filter(last_post_on__gt=cutoff_date)
    recorded_threads = exclude_invisible_threads(
        user, [category], recorded_threads)

    all_threads_count = recorded_threads.count()

    read_threads = user.threadread_set.filter(
        category=category,
        last_read_on__gt=cutoff_date
    )
    read_threads_count = read_threads.filter(
        thread__last_post_on__lte=F("last_read_on")
    ).count()

    category_is_read = read_threads_count == all_threads_count

    if category_is_read:
        signals.category_read.send(sender=user, category=category)

    if category_record:
        if category_is_read:
            category_record.last_read_on = timezone.now()
        else:
            category_record.last_read_on = cutoff_date
        category_record.save(update_fields=['last_read_on'])
    else:
        if category_is_read:
            last_read_on = timezone.now()
        else:
            last_read_on = cutoff_date

        category_record = user.categoryread_set.create(
            category=category,
            last_read_on=last_read_on
        )
Example #11
0
def sync_record(user, category):
    from misago.core import deprecations
    deprecations.warn("categoriestracker.sync_record has been deprecated")

    cutoff_date = get_cutoff_date()
    if user.joined_on > cutoff_date:
        cutoff_date = user.joined_on

    try:
        category_record = user.categoryread_set.get(category=category)
        if category_record.last_read_on > cutoff_date:
            cutoff_date = category_record.last_read_on
    except CategoryRead.DoesNotExist:
        category_record = None

    all_threads = category.thread_set.filter(last_post_on__gt=cutoff_date)
    all_threads_count = exclude_invisible_threads(user, [category],
                                                  all_threads).count()

    read_threads_count = user.threadread_set.filter(
        category=category,
        thread__in=all_threads,
        last_read_on__gt=cutoff_date,
        thread__last_post_on__lte=F("last_read_on"),
    ).count()

    category_is_read = read_threads_count == all_threads_count

    if category_is_read:
        signals.category_read.send(sender=user, category=category)

    if category_record:
        if category_is_read:
            category_record.last_read_on = timezone.now()
        else:
            category_record.last_read_on = cutoff_date
        category_record.save(update_fields=['last_read_on'])
    else:
        if category_is_read:
            last_read_on = timezone.now()
        else:
            last_read_on = cutoff_date
        category_record = user.categoryread_set.create(
            category=category, last_read_on=last_read_on)
Example #12
0
def sync_record(user, forum):
    cutoff_date = user.reads_cutoff

    try:
        forum_record = user.forumread_set.get(forum=forum)
        if forum_record.last_read_on > cutoff_date:
            cutoff_date = forum_record.last_read_on
    except ForumRead.DoesNotExist:
        forum_record = None

    recorded_threads = forum.thread_set.filter(last_post_on__gt=cutoff_date)
    recorded_threads = exclude_invisible_threads(recorded_threads, user, forum)

    all_threads_count = recorded_threads.count()

    read_threads = user.threadread_set.filter(
        forum=forum, last_read_on__gt=cutoff_date)
    read_threads_count = read_threads.filter(
        thread__last_post_on__lte=F("last_read_on")).count()

    forum_is_read = read_threads_count == all_threads_count

    if forum_is_read:
        signals.forum_read.send(sender=user, forum=forum)

    if forum_record:
        if forum_is_read:
            forum_record.last_read_on = forum_record.last_read_on
        else:
            forum_record.last_read_on = cutoff_date
        forum_record.save(update_fields=['last_read_on'])
    else:
        if forum_is_read:
            last_read_on = timezone.now()
        else:
            last_read_on = cutoff_date

        forum_record = user.forumread_set.create(
            forum=forum,
            last_read_on=last_read_on)
Example #13
0
def sync_record(user, category):
    cutoff_date = user.joined_on

    try:
        category_record = user.categoryread_set.get(category=category)
        if category_record.last_read_on > cutoff_date:
            cutoff_date = category_record.last_read_on
    except CategoryRead.DoesNotExist:
        category_record = None

    recorded_threads = category.thread_set.filter(last_post_on__gt=cutoff_date)
    recorded_threads = exclude_invisible_threads(user, [category],
                                                 recorded_threads)

    all_threads_count = recorded_threads.count()

    read_threads = user.threadread_set.filter(category=category,
                                              last_read_on__gt=cutoff_date)
    read_threads_count = read_threads.filter(
        thread__last_post_on__lte=F("last_read_on")).count()

    category_is_read = read_threads_count == all_threads_count

    if category_is_read:
        signals.category_read.send(sender=user, category=category)

    if category_record:
        if category_is_read:
            category_record.last_read_on = category_record.last_read_on
        else:
            category_record.last_read_on = cutoff_date
        category_record.save(update_fields=['last_read_on'])
    else:
        if category_is_read:
            last_read_on = timezone.now()
        else:
            last_read_on = cutoff_date

        category_record = user.categoryread_set.create(
            category=category, last_read_on=last_read_on)
Example #14
0
def sync_record(user, forum):
    cutoff_date = user.reads_cutoff

    try:
        forum_record = user.forumread_set.get(forum=forum)
        if forum_record.last_read_on > cutoff_date:
            cutoff_date = forum_record.last_read_on
    except ForumRead.DoesNotExist:
        forum_record = None

    recorded_threads = forum.thread_set.filter(last_post_on__gt=cutoff_date)
    recorded_threads = exclude_invisible_threads(recorded_threads, user, forum)

    all_threads_count = recorded_threads.count()

    read_threads = user.threadread_set.filter(forum=forum,
                                              last_read_on__gt=cutoff_date)
    read_threads_count = read_threads.filter(
        thread__last_post_on__lte=F("last_read_on")).count()

    forum_is_read = read_threads_count == all_threads_count

    if forum_is_read:
        signals.forum_read.send(sender=user, forum=forum)

    if forum_record:
        if forum_is_read:
            forum_record.last_read_on = forum_record.last_read_on
        else:
            forum_record.last_read_on = cutoff_date
        forum_record.save(update_fields=['last_read_on'])
    else:
        if forum_is_read:
            last_read_on = timezone.now()
        else:
            last_read_on = cutoff_date

        forum_record = user.forumread_set.create(forum=forum,
                                                 last_read_on=last_read_on)
Example #15
0
 def get_queryset(self):
     queryset = Thread.objects.filter(has_moderated_posts=True)
     queryset = queryset.select_related("forum")
     queryset = exclude_invisible_threads(queryset, self.user)
     return queryset
Example #16
0
 def get_threads_queryset(self, request, threads_categories, profile):
     return exclude_invisible_threads(
         request.user, threads_categories, profile.thread_set)
Example #17
0
 def get_queryset(self):
     queryset = Thread.objects.filter(has_moderated_posts=True)
     queryset = queryset.select_related('forum')
     queryset = exclude_invisible_threads(queryset, self.user)
     return queryset
Example #18
0
 def get_threads_queryset(self, request, threads_categories, profile):
     return exclude_invisible_threads(
         request.user, threads_categories, Thread.objects)
Example #19
0
 def get_queryset(self):
     queryset = exclude_invisible_threads(self.forum.thread_set, self.user,
                                          self.forum)
     return self.filter_threads(queryset)
Example #20
0
 def get_queryset(self):
     queryset = exclude_invisible_threads(
         self.forum.thread_set, self.user, self.forum)
     return self.filter_threads(queryset)