Changeset 153:29e8f38274e2


Ignore:
Timestamp:
Oct 21, 2009 2:35:14 PM (4 years ago)
Author:
slav0nic <slav0nic0@…>
Branch:
default
Message:

fix topic removing

Location:
apps/forum
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • apps/forum/models.py

    r152 r153  
    217217    def delete(self, *args, **kwargs): 
    218218        self_id = self.id 
    219         head_post_id = self.topic.posts.latest().id 
     219        head_post_id = self.topic.posts.order_by('created')[0].id 
     220        forum = self.topic.forum 
     221        topic = self.topic 
    220222        self.last_topic_post.clear() 
    221223        self.last_forum_post.clear() 
    222224        super(Post, self).delete(*args, **kwargs) 
    223  
    224225        #if post was last in topic - remove topic 
    225226        if self_id == head_post_id: 
    226             self.topic.delete() 
     227            topic.delete() 
     228        else: 
     229            try: 
     230                topic.last_post = Post.objects.filter(topic=topic).latest() 
     231            except Post.DoesNotExist: 
     232                topic.last_post = None 
     233            topic.post_count = Post.objects.filter(topic=topic).count() 
     234            topic.save() 
     235        try: 
     236            forum.last_post = Post.objects.filter(topic__forum=forum).latest() 
     237        except Post.DoesNotExist: 
     238            forum.last_post = None 
     239        forum.post_count = Post.objects.filter(topic__forum=forum).count() 
     240        forum.topic_count = Topic.objects.filter(forum=forum).count() 
     241        forum.save() 
     242 
    227243 
    228244 
  • apps/forum/signals.py

    r149 r153  
    2323 
    2424 
    25 def post_deleted(instance, **kwargs): 
    26     post = instance 
    27     post.topic.post_count = Post.objects.filter(topic=post.topic).count() 
    28     post.topic.last_post = Post.objects.filter(topic=post.topic).latest() 
    29     post.topic.save() 
    30     post.topic.forum.post_count = Post.objects.filter(topic__forum=post.topic.forum).count() 
    31     post.topic.forum.last_post = Post.objects.filter(topic__forum=post.topic.forum).latest() 
    32     post.topic.forum.save() 
    33  
    34  
    3525def pm_saved(instance, **kwargs): 
    3626    notify_pm_recipients(instance)  
     
    4838post_save.connect(pm_saved, sender=PrivateMessage) 
    4939post_save.connect(topic_saved, sender=Topic) 
    50  
    51 post_delete.connect(post_deleted, sender=Post) 
Note: See TracChangeset for help on using the changeset viewer.