X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=apps%2Fpatchwork%2Fmodels.py;h=d70fdb208eab49a29eb62daf1487c38db03993ab;hb=b261b3cff0c7f4aacb6c9bda5f5491d340b1af17;hp=226a69c3a4037d64afbb3684189a2d446df8d3a5;hpb=0deabd4014cbc9419d203356786e966c4f803ea3;p=patchwork diff --git a/apps/patchwork/models.py b/apps/patchwork/models.py index 226a69c..d70fdb2 100644 --- a/apps/patchwork/models.py +++ b/apps/patchwork/models.py @@ -129,35 +129,6 @@ class UserProfile(models.Model): def __str__(self): return self.name() -def _confirm_key(): - allowedchars = string.ascii_lowercase + string.digits - str = '' - for i in range(1, 32): - str += random.choice(allowedchars) - return str; - -class UserPersonConfirmation(models.Model): - user = models.ForeignKey(User) - email = models.CharField(max_length = 200) - key = models.CharField(max_length = 32, default = _confirm_key) - 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 = self.email) - except Exception: - pass - if not person: - person = Person(email = self.email) - - person.link_to_user(self.user) - person.save() - self.active = False - class State(models.Model): name = models.CharField(max_length = 100) ordering = models.IntegerField(unique = True) @@ -249,7 +220,7 @@ class Patch(models.Model): def mbox(self): comment = None try: - comment = Comment.objects.get(msgid = self.msgid) + comment = Comment.objects.get(patch = self, msgid = self.msgid) except Exception: pass @@ -316,3 +287,34 @@ class Bundle(models.Model): return '\n'.join([p.mbox().as_string(True) \ for p in self.patches.all()]) +class UserPersonConfirmation(models.Model): + user = models.ForeignKey(User) + email = models.CharField(max_length = 200) + key = HashField() + 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 = self.email) + except Exception: + pass + if not person: + person = Person(email = self.email) + + person.link_to_user(self.user) + person.save() + self.active = False + self.save() + + 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() + +