Anonymous avatar Anonymous committed b0ffb3f

fixed since last visit bug

Comments (0)

Files changed (3)


 from django.contrib.auth.models import User
 from djangobb_forum.models import Category, Forum, Topic, Post, Profile, Reputation,\
-    Report, Ban, Label, ProfileLabel
+    Report, Ban, Label, ProfileLabel, PostTracking
 class CategoryAdmin(admin.ModelAdmin):, BanAdmin), LabelAdmin)
-'delete_selected')  #disabled, because delete_selected ignoring delete model method


     def update_read(self, user):
         tracking = user.posttracking
+        #always update the time, it is used to filter since_last_read
+        tracking.last_read =
         #if last_read > last_read - don't check topics
         if tracking.last_read and (tracking.last_read > self.last_post.created):
             #clear topics if len > 5Kb and set last_read to current time
             if len(tracking.topics) > 5120:
                 tracking.topics = None
-                tracking.last_read =
             #update topics if exist new post or does't exist in dict
             if > tracking.topics.get(str(, 0):


         action = request.GET['action']
         if action == 'show_24h':
             date = - timedelta(1)
-            topics = Topic.objects.filter(created__gte=date).order_by('created')
+            topics = Topic.objects.filter(created__gte=date).order_by('-created')
         elif action == 'show_new':
-            #TODO: FIXME
-            #must be filter topic.last_post > tracking.last_read and exclude tracking.topics
-            topics = Topic.objects.all().order_by('created')
-            topics = [topic for topic in topics if forum_extras.has_unreads(topic, request.user)] 
+            last_read = PostTracking.objects.get(user=request.user).last_read
+            if last_read:
+                topics = Topic.objects.filter(last_post__created__gte=last_read).all()
+            else: # if no last_read is there then the user did not read anything yet
+                topics = Topic.objects.all().order_by('-last_post__created')
         elif action == 'show_unanswered':
             topics = Topic.objects.filter(post_count=1)
         elif action == 'show_subscriptions':
             return {'posts': posts,
                     'keywords': keywords,
                     'TEMPLATE': 'forum/search_posts.html'}
-        return {'posts': posts}
+        return {'topics': topics}
         form = PostSearchForm()
         return {'categories': Category.objects.all(),
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.