Commit 08a6dc8cc1748f0d84f6061d6e89ae08b589e0e3

  • avatar
  • asmanur
  • Sat May 07 17:42:58 CEST 2011
home: now displays the number of unread post in new threads if the user is logged in.
  
3131 creation = models.DateTimeField(auto_now_add=True)
3232 is_postit = models.BooleanField()
3333 is_closed = models.BooleanField()
34
34
35 def first_post(self):
36 return Post.objects.filter(topic=self)[0]
3537 def last_read_post(self):
3638 read = TopicRead.objects.select_related(
3739 ).filter(topic=self, user=get_current_user()
38 ).latest('post__creation')
39 return read.post
40 )
41 if len(read) == 0:
42 return self.first_post()
43 else:
44 return read[0].post
4045
4146 @models.permalink
4247 def get_absolute_url(self):
9999 return Post.objects.filter(topic=id).order_by('creation')[0]
100100
101101def mark_read(topic):
102 t = TopicRead(post=topic.last_post, topic=topic, user=get_current_user())
103 t.save()
102 TopicRead.objects.filter(topic=topic,user=get_current_user()).delete()
103 t = TopicRead(post=topic.last_post, topic=topic, user=get_current_user())
104 t.save()
104105
105def list_last_topics(nb,private):
106def list_last_topics(nb,private,auth):
106107 topics = Topic.objects.annotate(models.Count('post'))
107108 if not private:
108109 topics = topics.filter(forum__staff_only = False)
109110
110 return topics.order_by('-last_post__creation')[:nb]
111 topics = list(topics.order_by('-last_post__creation')[:nb])
112 if auth:
113 for topic in topics:
114 p = topic.last_read_post().creation
115 topic.post__count -= Post.objects.filter(topic = topic, creation__lt=p).count() + 1
116
117 return topics
111118
112119def set_last_post(forum_id):
113120 forum = Forum.objects.get(pk=forum_id)
  
1414 big_tuts = tuts[0:3]
1515 small_tuts = tuts[3:]
1616
17 last_topics = list_last_topics(6, request.user.is_staff)
17 last_topics = list_last_topics(6, request.user.is_staff, request.user.is_authenticated())
1818
1919 return render_to_response('home.html', {'big_news':big_news, 'small_news':small_news,
2020 'big_tuts':big_tuts, 'small_tuts':small_tuts,