[Oi-commits] r1124 - in trunk: forum templates/forum

oi-commits at pardus.org.tr oi-commits at pardus.org.tr
Wed Mar 12 15:19:17 EET 2008


Author: jnmbk
Date: Wed Mar 12 15:19:17 2008
New Revision: 1124

Modified:
   trunk/forum/views.py
   trunk/templates/forum/forum_list.html
Log:
it works perfect in main forum page and works in forum detail with a little touch on paginator code which I'll commit soon

Modified: trunk/forum/views.py
=================================================================
--- trunk/forum/views.py	(original)
+++ trunk/forum/views.py	Wed Mar 12 15:19:17 2008
@@ -26,18 +26,28 @@
     lastvisit_control(request)
 
     categories = Category.objects.order_by('order')
+    categories = [(category, category.forum_set.all()) for category in categories]
     forums = topics = posts = 0
     for category in categories:
-        for forum in category.forum_set.all():
+        for forum in category[1]:
             forums += 1
             topics += forum.topics
             posts += forum.posts
-            if forum.forum_latest_post and \
-                    forum.forum_latest_post.edited > request.session['last_visit']\
-                    and not forum.forum_latest_post.topic.id in request.session['read_topics_set']:
-                forum.is_read = False
-            else:
-                forum.is_read = True
+
+            # read/unread stuff
+            if request.user.is_authenticated():
+                readTopics = 0
+                counter = 0
+                for topic in forum.topic_set.all():
+                    counter += 1
+                    if topic.topic_latest_post.edited > request.session['last_visit'] or\
+                            "read_topic_%s" % topic.id in request.session:
+                                readTopics += 1
+                print counter, readTopics
+                if counter == readTopics:
+                    forum.is_read = True
+                else:
+                    forum.is_read = False
 
     usercount = User.objects.count()
     currentdate = datetime.now()
@@ -51,12 +61,13 @@
     forum = get_object_or_404(Forum, slug=forum_slug)
     topics = forum.topic_set.all().order_by('-sticky', '-topic_latest_post')
 
-    for topic in topics:
-        if topic.topic_latest_post.edited > request.session['last_visit'] and \
-                not topic.id in request.session["read_topics_set"]:
-            topic.is_read = False
-        else:
-            topic.is_read = True
+    if request.user.is_authenticated():
+        for topic in topics:
+            if topic.topic_latest_post.edited > request.session['last_visit'] or\
+                    "read_topic_%s" % topic.id in request.session:
+                topic.is_read = True
+            else:
+                topic.is_read = False
 
     return object_list(request, topics,
                        template_name = 'forum/forum_detail.html',
@@ -73,11 +84,8 @@
     posts = topic.post_set.all().order_by('created')
     news_list = News.objects.filter(status=1).order_by('-update')[:3]
 
-    try:
-        request.session["read_topics_set"].add(topic.id)
-    except:
-        request.session["read_topics_set"] = set()
-        request.session["read_topics_set"].add(topic.id)
+    if request.user.is_authenticated():
+        request.session["read_topic_%s" % topic.id] = True
 
     topic.views += 1
     topic.save()
@@ -350,7 +358,6 @@
 def lastvisit_control(request):
     if not "last_visit" in request.session:
         request.session["last_visit"] = datetime.now()
-        request.session["read_topics_set"] = set()
 
 def delete_post(request,forum_slug,topic_id, post_id):
     """ The delete part should be controlled better !"""

Modified: trunk/templates/forum/forum_list.html
=================================================================
--- trunk/templates/forum/forum_list.html	(original)
+++ trunk/templates/forum/forum_list.html	Wed Mar 12 15:19:17 2008
@@ -14,7 +14,7 @@
     <div id="forum_posts">İletiler</div>
     <div id="forum_lastpost">Son İleti</div>
 </div>
-{% for category in categories %}
+{% for category, forum_list in categories %}
 
 {% if category.hidden and not perms.forum.can_see_hidden_categories %}
 {% else %}
@@ -22,7 +22,7 @@
 <div id="category" {% if category.hidden %}style="opacity: 0.5;"{% endif %}>
     <div id="category_title">{{ category.name|escape }}</div>
         <div id="category_forums">
-            {% for forum in category.forum_set.all %}
+            {% for forum in forum_list %}
             {% if forum.hidden and not perms.forum.can_see_hidden_forums %}
             {% else %}
             <div id="category_forums_item" {% if forum.hidden %}style="opacity: 0.5;"{% endif %}>


More information about the Oi-commits mailing list