fixes bug from empty topics (not sure why I have this problem, might be from cacheing of a topic that was deleted)

This commit is contained in:
Chinua Shaw 2012-12-17 04:15:13 -05:00
parent 4438b50f74
commit 2cc0d21786

View file

@ -133,7 +133,8 @@ def has_unreads(topic, user):
return False
else:
if isinstance(user.posttracking.topics, dict):
if topic.last_post_id > user.posttracking.topics.get(str(topic.id), 0):
posttracking = user.posttracking.topics.get(str(topic.id), -1)
if topic.last_post_id > posttracking and posttracking > -1:
return True
else:
return False
@ -146,8 +147,11 @@ def forum_unread_link(topic, user):
"""
if not isinstance(user.posttracking.topics, dict):
return topic.get_absolute_url()
pk = user.posttracking.topics.get(str(topic.id), 0)
return Post.objects.filter(topic=topic).filter(pk__gt=pk).order_by('pk')[0].get_absolute_url()
pk = user.posttracking.topics.get(str(topic.id), -1)
if pk > -1:
return Post.objects.filter(topic=topic).filter(pk__gt=pk).order_by('pk')[0].get_absolute_url()
else:
return None
@register.filter
def forum_unreads(forum, user):
@ -162,7 +166,8 @@ def forum_unreads(forum, user):
if user.posttracking.last_read:
topics = topics.filter(updated__gte=user.posttracking.last_read)
for topic in topics:
if topic.last_post_id > user.posttracking.topics.get(str(topic.id), 0):
posttracking = user.posttracking.topics.get(str(topic.id), -1)
if topic.last_post_id > posttracking and posttracking > -1:
return True
return False