本文整理汇总了Python中accounts.models.UserProfile类的典型用法代码示例。如果您正苦于以下问题:Python UserProfile类的具体用法?Python UserProfile怎么用?Python UserProfile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserProfile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register
def register(request):
print 'register started in views.py'
if request.method == 'POST':
form = UserCreationForm(request.POST)
print 'were in post'
print 'email valid: '
print form.is_valid()
if form.is_valid():
print 'form first name %s'%form.cleaned_data['first_name']
user = User.objects.create_user(form.cleaned_data['email'], form.cleaned_data['email'],form.cleaned_data['password1'] )
user.first_name = form.cleaned_data['first_name']
user.last_name = form.cleaned_data['last_name']
user.save()
profile = UserProfile(user=user)
profile.save()
print 'logging user in'
user = authenticate(username=request.POST['email'],password=request.POST['password1'])
if user is not None:
# the password verified for the user
if user.is_active:
print("User is valid, active and authenticated")
else:
print("The password is valid, but the account has been disabled!")
else:
# the authentication system was unable to verify the username and password
print("The username and password were incorrect.")
auth_login (request,user)
print 'form being submitted'
return HttpResponseRedirect(reverse('news'))
else:
form = UserCreationForm()
print 'form created'
return render(request, 'accounts/register.html',{'form':form})
示例2: signup
def signup(request, **kwargs):
form_class = kwargs.pop("form_class", SignupForm)
template_name = kwargs.pop("template_name", "account/signup.html")
redirect_field_name = kwargs.pop("redirect_field_name", "next")
success_url = kwargs.pop("success_url", None)
if success_url is None:
success_url = get_default_redirect(request, redirect_field_name)
if request.method == "POST":
form = form_class(request.POST)
if form.is_valid():
user = form.save(request=request)
# Begin default profile creation
profile = UserProfile(user=user)
profile.save()
# End default profile creation
return complete_signup(request, user, success_url)
else:
form = form_class()
ctx = {"signuppage": True,
"form": form,
"login_url": passthrough_login_redirect_url(request,
reverse("account_login")),
"redirect_field_name": redirect_field_name,
"redirect_field_value": request.REQUEST.get(redirect_field_name) }
return render_to_response(template_name, RequestContext(request, ctx))
示例3: register
def register(self, request, **kwargs):
if Site._meta.installed:
site = Site.objects.get_current()
else:
site = RequestSite(request)
print site
user = User()
user.username = kwargs["username"]
user.email = kwargs["email"]
password = kwargs["password1"]
user.set_password(password)
user.first_name = kwargs["first_name"]
user.last_name = kwargs["last_name"]
user.is_active = False
user.save()
profile_user = UserProfile()
# Любое совпадение наименования полей и аргументов- случайно :), так
# проще не ошибиться
profile_user.country = kwargs["country"]
profile_user.city = kwargs["city"]
profile_user.company = kwargs["company"]
# profile_user.dokladchik = kwargs['dokladchik']
profile_user.surname = kwargs["surname"]
profile_user.job = kwargs["job"]
profile_user.accepted_eula = kwargs["accepted_eula"]
profile_user.user = user
profile_user.save()
prof = RegistrationProfile.objects.create_profile(user)
prof.send_activation_email(site)
return user
示例4: retrieve
def retrieve(request):
try:
profile = request.user.get_profile()
except UserProfile.DoesNotExist:
profile = UserProfile(user=request.user)
profile.save()
return profile
示例5: save
def save(self, commit=True):
user = super(UserCreateForm, self).save(commit=False)
user.email = self.cleaned_data["email"]
user.first_name = self.cleaned_data["first_name"]
user.last_name = self.cleaned_data["last_name"]
if commit:
domain = settings.BASE_URL
user.is_active = False # not active until he opens activation link
user.save()
username = user.username
email = user.email
random_string = str(random.random()).encode("utf8")
salt = hashlib.sha1(random_string).hexdigest()[:5]
salted = (salt + email).encode("utf8")
activation_key = hashlib.sha1(salted).hexdigest()
key_expires = datetime.datetime.today() + datetime.timedelta(2)
# Create and save user profile
new_profile = UserProfile(user=user, activation_key=activation_key, key_expires=key_expires)
new_profile.save()
# Send email with activation key
email_subject = "Account confirmation"
email_body = (
"Hey %s, thanks for signing up. To activate your account, click this link within 48 hours: %saccounts/confirm/%s/"
% (user.first_name, domain, activation_key)
)
send_mail(email_subject, email_body, settings.EMAIL_HOST_EMAIL, [user.email], fail_silently=False)
return user
示例6: detail
def detail(request, poll_id):
print 'exec detail'
p = get_object_or_404(Poll, pk=poll_id)
user = request.user
hasVoted = True
print 'has_voted_one:'
try:
profile = UserProfile.objects.get(userObject=user)
except ObjectDoesNotExist:
profile = UserProfile(userObject=user)
profile.save()
print 'created profile for user'
#hasVotedOnPoll = p in pollsVoted.objects.get(pk=1)
print profile.pollsVoted.all()
hasVotedOnPoll = True
try:
profile.pollsVoted.get(pk=poll_id)
except ObjectDoesNotExist:
hasVotedOnPoll=False
print 'caught exc and hasvoted=false'
print 'hasVotedOnPoll'
print hasVotedOnPoll
try:
poll = Poll.objects.get(pk=poll_id)
except Poll.DoesNotExist:
raise Http404
return render(request, 'polls/detail.html', {'poll': poll, 'hasAlreadyVoted':hasVotedOnPoll})
示例7: register
def register(request):
if request.user != None and request.user.is_authenticated():
return redirect('/')
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
#Create the user
email = form.cleaned_data.get('email')
passwd = form.cleaned_data.get('password1')
user = User(email=email)
user.set_password(passwd)
user.save()
user.username = user.pk
user.save()
user_profile = UserProfile(user=user)
user_profile.save()
user.backend='user_backends.email_username.EmailOrUsernameModelBackend'
#logs the new user
login(request,user)
return redirect('/')
else:
form = RegistrationForm()
return locals()
示例8: signup
def signup(request):
context = {}
context['title'] = _('Register')
user = User()
if request.user.is_authenticated():
return redirect('accounts_accounts')
userProfile = UserProfile()
if request.method == 'POST':
userForm = UserForm(request.POST, instance=user)
userProfileForm = UserProfileForm(request.POST, instance=userProfile)
if userForm.is_valid() and userProfileForm.is_valid():
userData = userForm.cleaned_data
user.username = userData['username']
user.first_name = userData['first_name']
user.last_name = userData['last_name']
user.email = userData['email']
user.set_password(userData['password'])
user.save()
userProfile = user.get_profile()
userProfileData = userProfileForm.cleaned_data
userProfile.gender = userProfileData['gender']
userProfile.birthday = userProfileData['birthday']
userProfile.save()
user = authenticate(username=userData['username'], password=userData['password'])
login(request, user)
return redirect('accounts_accounts')
else:
userForm = UserForm(instance=user)
userProfileForm = UserProfileForm(instance=userProfile)
context['userForm'] = userForm
context['userProfileForm'] = userProfileForm
return render_to_response('accounts/register.html', context, context_instance=RequestContext(request))
示例9: create_user
def create_user(request):
"""
PUT http://localhost:8000/api/v1/accounts/user/
"""
data = json.loads(request.body.decode("utf-8"))
new_user = UserProfile(
email=data['email'],
password=make_password(data['password']),
first_name=data['first_name'],
last_name=data['last_name'],
phone=data['phone'],
school=data['school'],
rating=0
)
new_user.save()
dataresult = {
'status': str(HTTP_201_CREATED),
'user_id': str(new_user.id),
'email': new_user.email,
'first_name': new_user.first_name,
'last_name': new_user.last_name,
'phone': new_user.phone,
'school': new_user.school,
'rating': str(new_user.rating)
}
return JsonResponse(dataresult, status=HTTP_201_CREATED)
示例10: active_user
def active_user(request, uidb36=None, token=None,
template_name='register/activation_confirm.html',
token_generator=default_token_generator,
current_app=None, extra_context=None):
"""
View that checks the hash in a active user link and make user to be active
"""
assert uidb36 is not None and token is not None # checked by URLconf
try:
uid_int = base36_to_int(uidb36)
user = User.objects.get(id=uid_int)
except (ValueError, User.DoesNotExist):
user = None
if user is not None and token_generator.check_token(user, token):
validlink = True
user.is_active = True
user.save()
#初始化userprofile
profile_count = UserProfile.objects.filter(user=user).count()
if profile_count == 0:
profile = UserProfile()
profile.user = user
profile.song_ord_filed = 'post_datetime'
profile.save()
else:
validlink = False
context = {
'validlink': validlink,
}
context.update(extra_context or {})
return render_to_response(template_name, context,
context_instance=RequestContext(request, current_app=current_app))
示例11: setup
def setup(request):
u = User.objects.create_user(username='jsmith', email='[email protected]', password='password')
u.save()
prof = UserProfile.create(user=u)
color = Color.create(50, 50, 50)
color.save()
prof.color = color
prof.save()
u = User.objects.create_user(username='jsmith2', email='[email protected]', password='password')
u.save()
prof = UserProfile.create(user=u)
color = Color.create(100, 100, 100)
color.save()
prof.color = color
prof.save()
u = User.objects.create_user(username='jsmith3', email='[email protected]', password='password')
u.save()
prof = UserProfile.create(user=u)
color = Color.create(200, 200, 200)
color.save()
prof.color = color
prof.save()
project = Project.create('project-x')
project.save()
project.users.add(UserProfile.objects.get(user=User.objects.get(username='jsmith')))
project.users.add(UserProfile.objects.get(user=User.objects.get(username='jsmith2')))
project.users.add(UserProfile.objects.get(user=User.objects.get(username='jsmith3')))
project.save()
return HttpResponse('Successful database setup')
示例12: retrieve
def retrieve(request):
''' note that this requires an authenticated user before we try calling it '''
try:
profile = request.user.get_profile()
except UserProfile.DoesNotExist:
profile = UserProfile(user=request.user)
profile.save()
return profile
示例13: retrieve
def retrieve(request):
""" gets the UserProfile instance for a user, creates one if it does not exist """
try:
profile = request.user.get_profile()
except UserProfile.DoesNotExist:
profile = UserProfile(user=request.user)
profile.save()
return profile
示例14: add
def add(request):
if request.method == 'POST':
user = UserProfile(username=request.POST.get('username'),
birthday=request.POST.get('birthday'))
user.save()
return redirect('/')
return render(request, 'accounts/add.html')
示例15: save
def save(self, commit=True):
user = super(UserCreationForm, self).save(commit=False)
user.set_password(self.cleaned_data["password1"])
user.email = self.cleaned_data["email"]
nickname = self.cleaned_data["nickname"]
if commit:
user.save()
user_profile = UserProfile(nickname=nickname, user=user)
user_profile.save()
return user