@classmethod
    def validate(self, user, key):
        if not SHA1_RE.search(key):
            return (False, _("%(key)s does not look like an activation key.") % {'key': key})
        try:
            ev = self.objects.get(activation_key=key)
            if user.email != ev.email:
                return (False, _("The user has updated the email since this activation key was sent."))
            if ev.date_requested+datetime.timedelta(days=3) < datetime.date.today():
                return (False, _("This activation key has expired."))
            # email validation successful
            try:
                g = Group.objects.get(name='Valid Email')
            except Group.DoesNotExist:
                logger.warn('Did not find "Valid Email" group. creating')
                g = Group.objects.create(name='Valid Email')
                g.permissions.add(Permission.objects.get(name='Can add comment'))
                g.permissions.add(Permission.objects.get(name='Can add annotation'))
                g.permissions.add(Permission.objects.get(name='Can add Topic'))
            ev.user.groups.add(g)

            p = user.get_profile()
            p.email_notification = 'D'
            p.save()

            ev.activation_key = ''
            ev.save()
            return (True, "")
        except self.DoesNotExist:
            return (False, _("Invalid activation key."))
        except Exception, e:
            exceptionType, exceptionValue, exceptionTraceback = sys.exc_info()
            logger.error("%s", ''.join(traceback.format_exception(exceptionType, exceptionValue, exceptionTraceback)))
            return (False, "Something went wrong.")
dataset/ETHPy150Open ofri/Open-Knesset/accounts/models.py/EmailValidation.validate/original