changeset 363:9d470c7a2b93

Following up on #168; redo some code to make it more DRY. Added a function on the profile to reset the text fields.
author Brian Neal <bgneal@gmail.com>
date Sat, 05 Mar 2011 04:03:30 +0000 (2011-03-05)
parents c5ae0a276e33
children 3cf18e6002dd
files gpp/bio/admin.py gpp/bio/models.py gpp/forums/views/spam.py
diffstat 3 files changed, 14 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/gpp/bio/admin.py	Sat Mar 05 03:43:32 2011 +0000
+++ b/gpp/bio/admin.py	Sat Mar 05 04:03:30 2011 +0000
@@ -98,11 +98,7 @@
         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.reset_text_fields()
             profile.save()
     mark_spammer.short_description = "Mark selected users as spammers"
 
--- a/gpp/bio/models.py	Sat Mar 05 03:43:32 2011 +0000
+++ b/gpp/bio/models.py	Sat Mar 05 04:03:30 2011 +0000
@@ -126,6 +126,18 @@
     user_is_active.boolean = True
     user_is_active.short_description = "Is Active"
 
+    def reset_text_fields(self):
+        """
+        Reset profile text fields to empty defaults.
+        This function is useful when a spammer is identified.
+
+        """
+        self.location = ''
+        self.occupation = ''
+        self.interests = ''
+        self.profile_text = ''
+        self.signature = ''
+
     def search_title(self):
         full_name = self.user.get_full_name()
         if full_name:
--- a/gpp/forums/views/spam.py	Sat Mar 05 03:43:32 2011 +0000
+++ b/gpp/forums/views/spam.py	Sat Mar 05 04:03:30 2011 +0000
@@ -37,11 +37,7 @@
     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.reset_text_fields()
     profile.save()
 
     Comment.objects.filter(user=user).delete()