当前位置: 首页>>代码示例>>Python>>正文


Python User.name方法代码示例

本文整理汇总了Python中mongoengine.django.auth.User.name方法的典型用法代码示例。如果您正苦于以下问题:Python User.name方法的具体用法?Python User.name怎么用?Python User.name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mongoengine.django.auth.User的用法示例。


在下文中一共展示了User.name方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_new_observer

# 需要导入模块: from mongoengine.django.auth import User [as 别名]
# 或者: from mongoengine.django.auth.User import name [as 别名]
 def create_new_observer(self, email, name, surname, affiliation, password):
     """
     Create a new, inactive ``Observer``, generates a
     ``profile`` and emails its activation key,
     returning the new ``Observer``.
     
     """
     new_observer = RegisteredObserver()
     user = User()
     user.email = email
     user.username = email
     user.is_active = False
     new_observer.name = name
     new_observer.surname = surname
     user.name = name + surname
     new_observer.affiliation = affiliation
     user.set_password(password)
     new_observer.set_password(password)
     new_observer.approved = False
     new_observer.registration_confirmed = False
     sha1 = hashlib.sha1()
     sha1.update(str(random.random()))
     salt = sha1.hexdigest()[:5]
     sha1 = hashlib.sha1()
     sha1.update(salt.encode('ascii', 'ignore') + email.encode('ascii', 'ignore') + name.encode('ascii', 'ignore') + affiliation.encode('ascii', 'ignore'))
     new_observer.activation_key = sha1.hexdigest()
     user.save()
     new_observer.user = user
     new_observer.save()
     
     from django.core.mail import send_mail
     subject = "Registration activation request for NZDIS: Tobacco Free"
     
     # Email subject *must not* contain newlines
     subject = ''.join(subject.splitlines())
         
     message = render_to_string('activation_email.txt',
                                { 'activation_key': new_observer.activation_key,
                                  'name': new_observer.name, 
                                 })
     logger.debug("Trying to email this:\n" + message)
     try:
         send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [new_observer.user.email])
     except:
         pass
         # TODO what should we do if the email connection fails?
         # should never happen on the server
     return new_observer
开发者ID:NZDIS,项目名称:TobaccoFree,代码行数:50,代码来源:models.py


注:本文中的mongoengine.django.auth.User.name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。