def read_category(user, category): from misago.core import deprecations deprecations.warn("categoriestracker.read_category has been deprecated") categories = [category.pk] if not category.is_leaf_node(): categories += category.get_descendants().filter( id__in=user.acl_cache['visible_categories'], ).values_list( 'id', flat=True, ) user.categoryread_set.filter(category_id__in=categories).delete() user.threadread_set.filter(category_id__in=categories).delete() now = timezone.now() new_reads = [] for category in categories: new_reads.append( CategoryRead( user=user, category_id=category, last_read_on=now, )) if new_reads: CategoryRead.objects.bulk_create(new_reads) signals.category_read.send(sender=user, category=category)
def start_record(user, category): from misago.core import deprecations deprecations.warn("categoriestracker.start_record has been deprecated") user.categoryread_set.create( category=category, last_read_on=user.joined_on, )
def test_deprecations_warn(self): """deprecation utility raises warning""" with warnings.catch_warnings(record=True) as warning: warn("test warning") self.assertEqual(len(warning), 1) self.assertEqual(str(warning[0].message), "test warning") self.assertTrue(issubclass(warning[0].category, RemovedInMisagoWarning))
def test_deprecations_warn(self): """deprecation utility raises warning""" with warnings.catch_warnings(record=True) as warning: warn("test warning") self.assertEqual(len(warning), 1) self.assertEqual(six.text_type(warning[0].message), "test warning") self.assertTrue(issubclass(warning[0].category, RemovedInMisagoWarning))
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)
def __init__(self, *args, **kwargs): from misago.core import deprecations deprecations.warn("ThreadRead has been deprecated") super(ThreadRead, self).__init__(*args, **kwargs)