comparison gpp/accounts/models.py @ 259:75ea1a8be7f2

Fix some old import problems where I used 'from django.contrib import auth' instead of 'from django.contrib.auth.models import User'. Also some formatting changes while I was in there.
author Brian Neal <bgneal@gmail.com>
date Tue, 21 Sep 2010 23:49:05 +0000
parents dbd703f7d63a
children
comparison
equal deleted inserted replaced
258:f9a9b4014d5b 259:75ea1a8be7f2
5 import string 5 import string
6 import hashlib 6 import hashlib
7 import base64 7 import base64
8 8
9 from django.db import models 9 from django.db import models
10 from django.contrib import auth 10 from django.contrib.auth.models import User
11 from django.conf import settings 11 from django.conf import settings
12 12
13 13
14 class IllegalUsername(models.Model): 14 class IllegalUsername(models.Model):
15 """model to represent the list of illegal usernames""" 15 """model to represent the list of illegal usernames"""
16 username = models.CharField(max_length = 30, db_index = True) 16 username = models.CharField(max_length=30, db_index=True)
17 17
18 def __unicode__(self): 18 def __unicode__(self):
19 return self.username 19 return self.username
20 20
21 class Meta: 21 class Meta:
22 ordering = ('username', ) 22 ordering = ('username', )
23 23
24 24
25 class IllegalEmail(models.Model): 25 class IllegalEmail(models.Model):
26 """model to represent the list of illegal/restricted email addresses""" 26 """model to represent the list of illegal/restricted email addresses"""
27 email = models.EmailField(db_index = True) 27 email = models.EmailField(db_index=True)
28 28
29 def __unicode__(self): 29 def __unicode__(self):
30 return self.email 30 return self.email
31 31
32 class Meta: 32 class Meta:
39 create_count = 0 39 create_count = 0
40 40
41 def create_pending_user(self, username, email, password): 41 def create_pending_user(self, username, email, password):
42 '''creates a new pending user and saves it to the database''' 42 '''creates a new pending user and saves it to the database'''
43 43
44 temp_user = auth.models.User() 44 temp_user = User()
45 temp_user.set_password(password) 45 temp_user.set_password(password)
46 46
47 now = datetime.datetime.now() 47 now = datetime.datetime.now()
48 pending_user = self.model(None, 48 pending_user = self.model(None,
49 username, 49 username,
56 self.create_count += 1 56 self.create_count += 1
57 return pending_user 57 return pending_user
58 58
59 59
60 def purge_expired(self): 60 def purge_expired(self):
61 expire_time = datetime.datetime.now() - datetime.timedelta(days = 1) 61 expire_time = datetime.datetime.now() - datetime.timedelta(days=1)
62 expired_pending_users = self.filter(date_joined__lt = expire_time) 62 expired_pending_users = self.filter(date_joined__lt=expire_time)
63 expired_pending_users.delete() 63 expired_pending_users.delete()
64 64
65 65
66 def _make_key(self): 66 def _make_key(self):
67 s = ''.join(random.sample(string.printable, 8)) 67 s = ''.join(random.sample(string.printable, 8))
75 75
76 76
77 class PendingUser(models.Model): 77 class PendingUser(models.Model):
78 """model for holding users while they go through the email registration cycle""" 78 """model for holding users while they go through the email registration cycle"""
79 79
80 username = models.CharField(max_length = 30, db_index = True) 80 username = models.CharField(max_length=30, db_index=True)
81 email = models.EmailField() 81 email = models.EmailField()
82 password = models.CharField(max_length = 128) 82 password = models.CharField(max_length=128)
83 date_joined = models.DateTimeField(default = datetime.datetime.now, db_index = True) 83 date_joined = models.DateTimeField(default=datetime.datetime.now, db_index=True)
84 key = models.CharField(max_length = 20, editable = True) 84 key = models.CharField(max_length=20, editable=True)
85 85
86 objects = PendingUserManager() 86 objects = PendingUserManager()
87 87
88 def __unicode__(self): 88 def __unicode__(self):
89 return self.username 89 return self.username