models.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:beg-django-e-commerce 作者: Apress 项目源码 文件源码
def create_profile(self, user):
        """
        Create a ``RegistrationProfile`` for a given
        ``User``, and return the ``RegistrationProfile``.

        The activation key for the ``RegistrationProfile`` will be a
        SHA1 hash, generated from a combination of the ``User``'s
        username and a random salt.

        """
        salt = sha.new(str(random.random())).hexdigest()[:5]
        activation_key = sha.new(salt+user.username).hexdigest()
#        prepend "key_" to the key_name, because key_names can't start with numbers     
        registrationprofile = RegistrationProfile(user=user, activation_key=activation_key, key_name="key_"+activation_key)
        registrationprofile.put()
        return registrationprofile
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号