From 075f15899967a822ff03b3a32e943dc56f0be5c4 Mon Sep 17 00:00:00 2001 From: alafin Date: Mon, 19 Jan 2009 21:23:53 +0200 Subject: [PATCH] add post_count in profile --- apps/forum/forms.py | 3 +++ apps/forum/models.py | 2 +- .../templates/forum/profile/profile_essentials.html | 2 +- apps/forum/templates/forum/topic.html | 2 +- apps/forum/templates/forum/user.html | 2 +- apps/forum/templates/forum/users.html | 2 +- apps/forum/views.py | 11 +++++++++-- settings.py | 1 + 8 files changed, 18 insertions(+), 7 deletions(-) diff --git a/apps/forum/forms.py b/apps/forum/forms.py index e985cb6..3c53e5d 100644 --- a/apps/forum/forms.py +++ b/apps/forum/forms.py @@ -75,6 +75,9 @@ class AddPostForm(forms.ModelForm): markup='bbcode', body=self.cleaned_data['body']) post.save() + profile = get_object_or_404(Profile, user=self.user) + profile.post_count += 1 + profile.save() return post class EssentialsProfileForm(forms.ModelForm): diff --git a/apps/forum/models.py b/apps/forum/models.py index 9c81d12..e5f32aa 100644 --- a/apps/forum/models.py +++ b/apps/forum/models.py @@ -269,6 +269,7 @@ class Profile(models.Model): show_signatures = models.BooleanField(_('Show signatures'), blank=True, default=True) privacy_permission = models.IntegerField(_('Privacy permission'), choices=PRIVACY_CHOICES, default=1) markup = models.CharField(_('Default markup'), max_length=15, default=forum_settings.DEFAULT_MARKUP, choices=MARKUP_CHOICES) + post_count = models.IntegerField(_('Post count'), blank=True, default=0) class Meta: verbose_name = _('Profile') @@ -333,7 +334,6 @@ class Report(models.Model): return u'%s %s' % (self.reported_by ,self.zapped) class PrivateMessage(models.Model): - dst_user = models.ForeignKey(User, verbose_name=_('Recipient'), related_name='dst_users') src_user = models.ForeignKey(User, verbose_name=_('Author'), related_name='src_users') read = models.BooleanField(_('Read'), blank=True, default=False) diff --git a/apps/forum/templates/forum/profile/profile_essentials.html b/apps/forum/templates/forum/profile/profile_essentials.html index bf35f4b..5fa9ae1 100644 --- a/apps/forum/templates/forum/profile/profile_essentials.html +++ b/apps/forum/templates/forum/profile/profile_essentials.html @@ -63,7 +63,7 @@

{% trans "Registered:" %} {{ profile.date_joined|date:"Y-m-d" }}

{% trans "Last post:" %} {{ profile.forum_profile.last_post }}

-
diff --git a/apps/forum/templates/forum/topic.html b/apps/forum/templates/forum/topic.html index 2236502..f408304 100644 --- a/apps/forum/templates/forum/topic.html +++ b/apps/forum/templates/forum/topic.html @@ -44,7 +44,7 @@
{% trans "From:" %} {{ post.user.forum_profile.location }}
{% endif %}
{% trans "Registered:" %} {{ post.user.date_joined|date:"Y-m-d" }}
-
{% trans "Posts:" %} {{ post.user.posts.count }}
+
{% trans "Posts:" %} {{ post.user.forum_profile.post_count }}
{% if moderator %}
{% trans "IP:" %} {{ post.user_ip }}
{% endif %} diff --git a/apps/forum/templates/forum/user.html b/apps/forum/templates/forum/user.html index 6cdd2a4..afed412 100644 --- a/apps/forum/templates/forum/user.html +++ b/apps/forum/templates/forum/user.html @@ -125,7 +125,7 @@
{% trans "Posts:" %}
-
{{ profile.posts.all.count }} - Показать все сообщения
+
{{ profile.forum_profile.post_count }} - Показать все сообщения
{% trans "Last post:" %}
{% if profile.forum_profile.last_post %}
{{ profile.forum_profile.last_post }}
diff --git a/apps/forum/templates/forum/users.html b/apps/forum/templates/forum/users.html index 99b70ae..65f6e37 100644 --- a/apps/forum/templates/forum/users.html +++ b/apps/forum/templates/forum/users.html @@ -57,7 +57,7 @@ {{ profile|profile_link }} {{ profile.forum_profile.status }} - {{ profile.posts.count }} + {{ profile.forum_profile.post_count }} {{ profile.date_joined|date:"d-m-Y" }} {% endfor %} diff --git a/apps/forum/views.py b/apps/forum/views.py index 8fd6656..5e79ef5 100644 --- a/apps/forum/views.py +++ b/apps/forum/views.py @@ -579,12 +579,19 @@ def delete_post(request, post_id): return HttpResponseRedirect(post.get_absolute_url()) topic = post.topic - forum = post.topic.forum topic.post_count -= 1 + topic.save() + forum = post.topic.forum forum.post_count -= 1 forum.save() - topic.save() + + profile = get_object_or_404(Profile, user=post.user) + profile.post_count -= 1 + profile.save() + post.delete() + + try: Topic.objects.get(pk=topic.id) diff --git a/settings.py b/settings.py index 707971a..f7f8b77 100644 --- a/settings.py +++ b/settings.py @@ -89,6 +89,7 @@ INSTALLED_APPS = ( 'apps.account', 'apps.captcha', 'apps.forum', + 'django_evolution', ) FORCE_SCRIPT_NAME = ''