# HG changeset patch # User Brian Neal # Date 1299032308 0 # Node ID d1b11096595bb018c7a704f88746627cdaa49b20 # Parent 69d0306a6fe7422221ea75a843070f089923fd89 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. diff -r 69d0306a6fe7 -r d1b11096595b gpp/accounts/admin.py --- 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" diff -r 69d0306a6fe7 -r d1b11096595b gpp/bio/admin.py --- 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): diff -r 69d0306a6fe7 -r d1b11096595b gpp/forums/signals.py --- 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') diff -r 69d0306a6fe7 -r d1b11096595b gpp/forums/templatetags/forum_tags.py --- 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 diff -r 69d0306a6fe7 -r d1b11096595b gpp/forums/tools.py --- 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) diff -r 69d0306a6fe7 -r d1b11096595b gpp/forums/views/spam.py --- 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()