diff options
author | Jeremy Kerr <jk@ozlabs.org> | 2010-08-12 12:15:48 +0800 |
---|---|---|
committer | Jeremy Kerr <jk@ozlabs.org> | 2011-04-14 16:44:53 +0800 |
commit | 56e2243f3be7e859666ce0e4e1a8b8b94444f8d4 (patch) | |
tree | 7d3cf84b990a1b732d0334c5520f3203a955df12 /apps/patchwork/models.py | |
parent | c3291f5d18445cd91b540342d31d76254b32376c (diff) | |
download | patchwork-56e2243f3be7e859666ce0e4e1a8b8b94444f8d4.tar.bz2 patchwork-56e2243f3be7e859666ce0e4e1a8b8b94444f8d4.tar.xz |
Use generic email confirmation object
Rather than having a UserPerson-specific confirmation, add an
EmailConfirmation object to allow multiple types of confirmations (eg,
opt-out requests in future).
To do this, we use a view (patchwork.views.confirm) that will call the
type-specific view with the confirmation object.
Also, add tests to check that the User/Person linkage system works.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'apps/patchwork/models.py')
-rw-r--r-- | apps/patchwork/models.py | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/apps/patchwork/models.py b/apps/patchwork/models.py index 6c8fc71..ee6748f 100644 --- a/apps/patchwork/models.py +++ b/apps/patchwork/models.py @@ -373,34 +373,29 @@ class BundlePatch(models.Model): unique_together = [('bundle', 'patch')] ordering = ['order'] -class UserPersonConfirmation(models.Model): - user = models.ForeignKey(User) +class EmailConfirmation(models.Model): + validity = datetime.timedelta(days = 30) + type = models.CharField(max_length = 20, choices = [ + ('userperson', 'User-Person association'), + ]) email = models.CharField(max_length = 200) + user = models.ForeignKey(User, null = True) key = HashField() - date = models.DateTimeField(default=datetime.datetime.now) + date = models.DateTimeField(default = datetime.datetime.now) active = models.BooleanField(default = True) - def confirm(self): - if not self.active: - return - person = None - try: - person = Person.objects.get(email__iexact = self.email) - except Exception: - pass - if not person: - person = Person(email = self.email) - - person.link_to_user(self.user) - person.save() + def deactivate(self): self.active = False self.save() + def is_valid(self): + return self.date + self.validity > datetime.datetime.now() + def save(self): max = 1 << 32 if self.key == '': str = '%s%s%d' % (self.user, self.email, random.randint(0, max)) self.key = self._meta.get_field('key').construct(str).hexdigest() - super(UserPersonConfirmation, self).save() + super(EmailConfirmation, self).save() |