comparison gpp/bio/models.py @ 215:8c1832b9d815

Implement #84; additional checks on spammers; implement stranger status.
author Brian Neal <bgneal@gmail.com>
date Sat, 29 May 2010 04:51:28 +0000
parents b4305e18d3af
children cd4124b19196
comparison
equal deleted inserted replaced
214:28988cce138b 215:8c1832b9d815
10 from django.conf import settings 10 from django.conf import settings
11 from django.core.cache import cache 11 from django.core.cache import cache
12 12
13 from core.markup import SiteMarkup 13 from core.markup import SiteMarkup
14 14
15 15 # These are the secondary user status enumeration values.
16 (STA_ACTIVE, STA_RESIGNED, STA_REMOVED, STA_SUSPENDED, STA_SPAMMER) = range(5) 16 (STA_ACTIVE, # User is a full member in good standing.
17 STA_RESIGNED, # User has voluntarily asked to be removed.
18 STA_REMOVED, # User was removed for bad behavior.
19 STA_SUSPENDED, # User is temporarily suspended; e.g. a stranger tripped
20 # the spam filter.
21 STA_SPAMMER, # User has been removed for spamming.
22 STA_STRANGER, # New member, isn't fully trusted yet. Their comments and
23 # forum posts are scanned for spam. They can have their
24 # accounts deactivated by moderators for spamming.
25 ) = range(6)
17 26
18 USER_STATUS_CHOICES = ( 27 USER_STATUS_CHOICES = (
19 (STA_ACTIVE, "Active"), 28 (STA_ACTIVE, "Active"),
20 (STA_RESIGNED, "Resigned"), 29 (STA_RESIGNED, "Resigned"),
21 (STA_REMOVED, "Removed"), 30 (STA_REMOVED, "Removed"),
22 (STA_SUSPENDED, "Suspended"), 31 (STA_SUSPENDED, "Suspended"),
23 (STA_SPAMMER, "Spammer"), 32 (STA_SPAMMER, "Spammer"),
33 (STA_STRANGER, "Stranger")
24 ) 34 )
25 35
26 36
27 class Badge(models.Model): 37 class Badge(models.Model):
28 """This model represents badges that users can earn.""" 38 """This model represents badges that users can earn."""
74 avatar = models.ImageField(upload_to=avatar_file_path, blank=True) 84 avatar = models.ImageField(upload_to=avatar_file_path, blank=True)
75 time_zone = models.CharField(max_length=64, blank=True, 85 time_zone = models.CharField(max_length=64, blank=True,
76 default='US/Pacific') 86 default='US/Pacific')
77 use_24_time = models.BooleanField(default=False) 87 use_24_time = models.BooleanField(default=False)
78 forum_post_count = models.IntegerField(default=0) 88 forum_post_count = models.IntegerField(default=0)
79 status = models.IntegerField(default=STA_ACTIVE, 89 status = models.IntegerField(default=STA_STRANGER,
80 choices=USER_STATUS_CHOICES) 90 choices=USER_STATUS_CHOICES)
81 status_date = models.DateTimeField(auto_now_add=True) 91 status_date = models.DateTimeField(auto_now_add=True)
82 badges = models.ManyToManyField(Badge, through="BadgeOwnership") 92 badges = models.ManyToManyField(Badge, through="BadgeOwnership")
83 93
84 def __unicode__(self): 94 def __unicode__(self):
102 if hasattr(self, '_badges'): 112 if hasattr(self, '_badges'):
103 return self._badges 113 return self._badges
104 self._badges = BadgeOwnership.objects.filter(profile=self).select_related( 114 self._badges = BadgeOwnership.objects.filter(profile=self).select_related(
105 "badge") 115 "badge")
106 return self._badges 116 return self._badges
117
118 def is_stranger(self):
119 """Returns True if this user profile status is STA_STRANGER."""
120 return self.status == STA_STRANGER
121
122 def user_is_active(self):
123 """Returns the profile's user is_active status. This function exists
124 for the admin.
125 """
126 return self.user.is_active
127 user_is_active.boolean = True
128 user_is_active.short_description = "Is Active"
107 129
108 130
109 class UserProfileFlag(models.Model): 131 class UserProfileFlag(models.Model):
110 """This model represents a user flagging a profile as inappropriate.""" 132 """This model represents a user flagging a profile as inappropriate."""
111 user = models.ForeignKey(auth.models.User) 133 user = models.ForeignKey(auth.models.User)