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


Python UserProfile.create_from_existing_user方法代码示例

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


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

示例1: register_new_user

# 需要导入模块: from accounts.models import UserProfile [as 别名]
# 或者: from accounts.models.UserProfile import create_from_existing_user [as 别名]
def register_new_user(donor, really_send_email=False):
    email = str(donor["email"])
    user_exists = User.objects.filter(email=email).count() != 0
    members_blogs = Blog.objects.filter(member_blog=True)
    if user_exists and really_send_email:
        return DUPLICATE_ERROR

    try:
        if not user_exists:
            password = User.objects.make_random_password(6)
            if really_send_email:
                user = User()
                user.username = email
                user.email = email
                user.password = password
                first_name = unicode.encode(donor["first"], "utf-8")
                last_name = unicode.encode(donor["last"], "utf-8")
                user.first_name = first_name
                user.last_name = last_name
                user.save()
                user_profile = UserProfile.create_from_existing_user(user)
                user_profile.save()
                user_profile.create_member_from_litrom(donor)
                member = user_profile.create_member_from_litrom(donor)
                member.save()
                for b in members_blogs:
                    member.blog_set.add(b)
                member.save()
        else:
            user = User.objects.get(email=email)
            password = "user already exists - hope you know it!"

        t = loader.get_template("accounts/litrom_newuser_email.txt")
        site = Site.objects.get_current().name
        c = Context(
            {"site": site, "first": user.first_name, "last": user.last_name, "email": email, "password": password}
        )
        subject = u"תודה שאמרת כן להצעת החברות שלנו!"
        message = t.render(c)

        if not really_send_email:
            email = "[email protected]"

        send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [email], fail_silently=False)
    except BadHeaderError:
        return EMAIL_ERROR
    if not really_send_email:
        send_mail("got one", email, settings.DEFAULT_FROM_EMAIL, ["[email protected]"], fail_silently=True)
    if really_send_email:
        return SUCCESS_ERROR
    return DEMO_ERROR
开发者ID:shula,项目名称:citytree,代码行数:53,代码来源:register_utils.py


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