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


Python UserProfile.new方法代码示例

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


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

示例1: signup

# 需要导入模块: from core.models import UserProfile [as 别名]
# 或者: from core.models.UserProfile import new [as 别名]
def signup(request):
    """View that handles user registration."""

    if request.user.is_authenticated():
        return HttpResponseRedirect("/")

    if request.method == "GET":
        form = SignupForm()  # Create an empty form if the method is GET.
    elif request.method == "POST":
        form = SignupForm(request.POST)  # Populate the form with POST data.
        if form.is_valid():
            # Get the form data.
            username = form.cleaned_data["username"]
            email = form.cleaned_data["email"]
            password = form.cleaned_data["password"]
            first_name = form.cleaned_data["first_name"]
            last_name = form.cleaned_data["last_name"]

            # Create a new user and profile.
            user = User.objects.create_user(username, email, password)
            user.first_name = first_name
            user.last_name = last_name
            user.save()  # Save the user.

            new_profile = UserProfile()
            new_profile.new(user, form.cleaned_data["phone"], get_remote_ip(request))

            # Send an email with the confirmation link
            site = Site.objects.get_current()
            subject = "%s User Activation" % site.name
            body = (
                "Hello, %s, and thanks for signing up for an account at %s!"
                "\n\nTo activate your account, click this link within 48 hours:"
                "\n\nhttp://%s/login/%s" % (user.username, site.domain, site.domain, new_profile.activation_key)
            )
            send_mail(subject, body, "settings.EMAIL_HOST_USER", [user.email])

            # Redirect to a confirmation page.
            return HttpResponseRedirect("/signup/confirmed/")

    # Load signup.html on GET request and POST error.
    return load_page(request, "signup.html", {"form": form})
开发者ID:ianonavy,项目名称:The-Knight-Book-Market,代码行数:44,代码来源:views.py

示例2: account

# 需要导入模块: from core.models import UserProfile [as 别名]
# 或者: from core.models.UserProfile import new [as 别名]
def account(request):
    user = request.user

    try:
        profile = UserProfile.objects.get(user=request.user)
    except:
        profile = UserProfile()
        profile.new(user, ip_address=get_remote_ip(request))
        profile.save()

    form = AccountForm({"phone": profile.phone, "email": user.email})
    error = ""

    if request.method == "POST":
        form = AccountForm(request.POST)
        if form.is_valid():
            # user.email = form.cleaned_data['email']
            user.save()
            profile.phone = form.cleaned_data["phone"]
            profile.save()
            return index(request, "Your account has successfully been edited.")
        else:
            error = form.errors
    return load_page(request, "account.html", {"form": form, "error": error})
开发者ID:ianonavy,项目名称:The-Knight-Book-Market,代码行数:26,代码来源:views.py


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