Mercurial > public > sg101
changeset 348:d1b11096595b
Fix #168; when nailing a spammer, clear their profile text fields. Guard against topics and forums that don't exist when deleting posts in the signal handler. Make the forum stats template tag only display the latest active users.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 02 Mar 2011 02:18:28 +0000 |
parents | 69d0306a6fe7 |
children | a43add8af83d |
files | gpp/accounts/admin.py gpp/bio/admin.py gpp/forums/signals.py gpp/forums/templatetags/forum_tags.py gpp/forums/tools.py gpp/forums/views/spam.py |
diffstat | 6 files changed, 32 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/gpp/accounts/admin.py Wed Mar 02 01:11:32 2011 +0000 +++ b/gpp/accounts/admin.py Wed Mar 02 02:18:28 2011 +0000 @@ -19,6 +19,8 @@ for pending_user in qs: create_new_user(pending_user, admin_activation=True) + self.message_user(request, "%s accounts activated" % qs.count()) + activate_account.short_description = "Activate accounts for selected users"
--- a/gpp/bio/admin.py Wed Mar 02 01:11:32 2011 +0000 +++ b/gpp/bio/admin.py Wed Mar 02 02:18:28 2011 +0000 @@ -98,6 +98,12 @@ for profile in qs: Comment.objects.filter(user=profile.user).delete() delete_user_posts(profile.user) + profile.location = '' + profile.occupation = '' + profile.interests = '' + profile.profile_text = '' + profile.signature = '' + profile.save() mark_spammer.short_description = "Mark selected users as spammers" def mark_stranger(self, request, qs):
--- a/gpp/forums/signals.py Wed Mar 02 01:11:32 2011 +0000 +++ b/gpp/forums/signals.py Wed Mar 02 02:18:28 2011 +0000 @@ -4,7 +4,7 @@ from django.db.models.signals import post_save from django.db.models.signals import post_delete -from forums.models import Topic, Post +from forums.models import Forum, Topic, Post from forums.views.subscriptions import notify_topic_subscribers @@ -41,12 +41,18 @@ post = kwargs['instance'] # update the topic - post.topic.post_count_update() - post.topic.save() - - # update the forum - post.topic.forum.post_count_update() - post.topic.forum.save() + try: + post.topic.post_count_update() + post.topic.save() + except Topic.DoesNotExist: + pass + else: + # update the forum + try: + post.topic.forum.post_count_update() + post.topic.forum.save() + except Forum.DoesNotExist: + pass post_save.connect(on_topic_save, sender=Topic, dispatch_uid='forums.signals')
--- a/gpp/forums/templatetags/forum_tags.py Wed Mar 02 01:11:32 2011 +0000 +++ b/gpp/forums/templatetags/forum_tags.py Wed Mar 02 02:18:28 2011 +0000 @@ -167,7 +167,8 @@ user_count = User.objects.all().count() if user_count > 0: - latest_user = User.objects.values_list('username', flat=True).order_by('-date_joined')[0] + latest_user = User.objects.filter(is_active=True).values_list( + 'username', flat=True).order_by('-date_joined')[0] else: latest_user = None
--- a/gpp/forums/tools.py Wed Mar 02 01:11:32 2011 +0000 +++ b/gpp/forums/tools.py Wed Mar 02 02:18:28 2011 +0000 @@ -52,7 +52,7 @@ else: forum.last_post = None forum.save() - + # Delete pending topics now because forums have just adjusted their # foreign keys into Post if pending_delete: @@ -63,7 +63,7 @@ for forum in forums: forum.topic_count = Topic.objects.filter(forum=forum).count() forum.save() - + # All foreign keys are accounted for, we can now delete the posts in bulk. # Since some posts in our original queryset may have been deleted already, # run a new query (although it may be ok)
--- a/gpp/forums/views/spam.py Wed Mar 02 01:11:32 2011 +0000 +++ b/gpp/forums/views/spam.py Wed Mar 02 02:18:28 2011 +0000 @@ -28,7 +28,8 @@ def deactivate_spammer(user): """This function deactivate's the user, marks them as a spammer, then - deletes the user's comments and forum posts. + deletes the user's comments and forum posts. The spammer's profile is + cleared so any spam links won't show up anymore. """ user.is_active = False user.save() @@ -36,6 +37,11 @@ profile = user.get_profile() profile.status = bio.models.STA_SPAMMER profile.status_date = datetime.datetime.now() + profile.location = '' + profile.occupation = '' + profile.interests = '' + profile.profile_text = '' + profile.signature = '' profile.save() Comment.objects.filter(user=user).delete()