refactoring post counting for user
This commit is contained in:
parent
c677af345a
commit
b7b9e7bc47
3 changed files with 8 additions and 8 deletions
|
@ -92,14 +92,12 @@ class AddPostForm(forms.ModelForm):
|
|||
post = Post(topic=topic, user=self.user, user_ip=self.ip,
|
||||
markup='bbcode',
|
||||
body=self.cleaned_data['body'])
|
||||
post.save()
|
||||
|
||||
if forum_settings.ATTACHMENT_SUPPORT:
|
||||
self.save_attachment(post, self.cleaned_data['attachment'])
|
||||
|
||||
profile = self.user.forum_profile
|
||||
profile.post_count += 1
|
||||
if commit:
|
||||
profile.save()
|
||||
post.save()
|
||||
return post
|
||||
|
||||
def save_attachment(self, post, memfile):
|
||||
|
|
|
@ -11,14 +11,18 @@ def post_saved(instance, **kwargs):
|
|||
updated_time = datetime.now()
|
||||
post.topic.updated = updated_time
|
||||
post.topic.last_post = post
|
||||
post.topic.post_count = Post.objects.filter(topic=post.topic).count()
|
||||
post.topic.post_count = post.topic.posts.count()
|
||||
post.topic.save(force_update=True)
|
||||
|
||||
post.topic.forum.updated = updated_time
|
||||
post.topic.forum.post_count = Post.objects.filter(topic__forum=post.topic.forum).count()
|
||||
post.topic.forum.post_count = post.topic.forum.posts.count()
|
||||
post.topic.forum.last_post = post
|
||||
post.topic.forum.save(force_update=True)
|
||||
|
||||
profile = post.user.forum_profile
|
||||
profile.post_count = post.user.posts.count()
|
||||
profile.save(force_update=True)
|
||||
|
||||
notify_topic_subscribers(post)
|
||||
|
||||
|
||||
|
|
|
@ -573,8 +573,6 @@ def delete_posts(request, topic_id):
|
|||
from forum.templatetags.forum_extras import forum_moderated_by
|
||||
|
||||
topic = Topic.objects.select_related().get(pk=topic_id)
|
||||
topic.views += 1
|
||||
topic.save()
|
||||
|
||||
if forum_moderated_by(topic, request.user):
|
||||
deleted = False
|
||||
|
|
Reference in a new issue