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)
def sync_record(user, thread, last_read_reply): read_replies = count_read_replies(user, thread, last_read_reply) if thread.read_record: thread.read_record.read_replies = read_replies thread.read_record.last_read_on = last_read_reply.updated_on thread.read_record.save(update_fields=['read_replies', 'last_read_on']) else: user.threadread_set.create( forum=thread.forum, thread=thread, read_replies=read_replies, last_read_on=last_read_reply.updated_on) if last_read_reply.updated_on == thread.last_post_on: forumstracker.sync_record(user, thread.forum)
def sync_record(user, thread, last_read_reply): read_replies = count_read_replies(user, thread, last_read_reply) if thread.read_record: thread.read_record.read_replies = read_replies thread.read_record.last_read_on = last_read_reply.posted_on thread.read_record.save(update_fields=['read_replies', 'last_read_on']) else: user.threadread_set.create(forum=thread.forum, thread=thread, read_replies=read_replies, last_read_on=last_read_reply.posted_on) signals.thread_tracked.send(sender=user, thread=thread) if last_read_reply.posted_on == thread.last_post_on: signals.thread_read.send(sender=user, thread=thread) forumstracker.sync_record(user, thread.forum)
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)
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)
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)
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)
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)
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)
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)
def sync_record(user, thread, last_read_reply): notification_triggers = ['read_thread_%s' % thread.pk] read_replies = count_read_replies(user, thread, last_read_reply) if thread.read_record: thread.read_record.read_replies = read_replies thread.read_record.last_read_on = last_read_reply.posted_on thread.read_record.save(update_fields=['read_replies', 'last_read_on']) else: user.threadread_set.create(forum=thread.forum, thread=thread, read_replies=read_replies, last_read_on=last_read_reply.posted_on) signals.thread_tracked.send(sender=user, thread=thread) notification_triggers.append('see_thread_%s' % thread.pk) if last_read_reply.posted_on == thread.last_post_on: signals.thread_read.send(sender=user, thread=thread) forumstracker.sync_record(user, thread.forum) read_user_notifications(user, notification_triggers, False)
def sync_record(user, thread, last_read_reply): notification_triggers = ['read_thread_%s' % thread.pk] read_replies = count_read_replies(user, thread, last_read_reply) if thread.read_record: thread.read_record.read_replies = read_replies thread.read_record.last_read_on = last_read_reply.posted_on thread.read_record.save(update_fields=['read_replies', 'last_read_on']) else: user.threadread_set.create( forum=thread.forum, thread=thread, read_replies=read_replies, last_read_on=last_read_reply.posted_on) signals.thread_tracked.send(sender=user, thread=thread) notification_triggers.append('see_thread_%s' % thread.pk) if last_read_reply.posted_on == thread.last_post_on: signals.thread_read.send(sender=user, thread=thread) forumstracker.sync_record(user, thread.forum) read_user_notifications(user, notification_triggers, False)