本文整理汇总了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})
示例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})