本文整理汇总了Python中users.forms.ProfileForm类的典型用法代码示例。如果您正苦于以下问题:Python ProfileForm类的具体用法?Python ProfileForm怎么用?Python ProfileForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ProfileForm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: user_register
def user_register(request):
if request.method == "GET":
user_form = UserForm()
profile_form = ProfileForm()
elif request.method == "POST":
user_form = UserForm(request.POST)
profile_form = ProfileForm(request.POST)
if user_form.is_valid() and profile_form.is_valid():
user = user_form.save()
profile = profile_form.save(commit=False)
profile.user = user
profile.save()
password = user.password
# The form doesn't know to call this special method on user.
user.set_password(password)
user.save()
# You must call authenticate before login. :(
user = authenticate(username=user.username,
password=password)
login(request, user)
messages.add_message(
request,
messages.SUCCESS,
"Congratulations, {}, on creating your new account! You are now logged in.".format(
user.username))
return redirect('index')
return render(request, "users/register.html", {'user_form': user_form,
'profile_form': profile_form})
示例2: post
def post(self, request):
user_form = UserForm(request.POST)
profile_form = ProfileForm(request.POST)
if user_form.is_valid() and profile_form.is_valid():
user = user_form.save()
profile = profile_form.save(commit=False)
profile.user = user
profile.save()
password = user.password
user.set_password(password)
user.save()
user = authenticate(username=user.username,
password=password)
login(self.request, user)
messages.add_message(
request,
messages.SUCCESS,
"Account Successfully Created.")
return redirect("/")
else:
return render(request, "users/register.html", {"form1": user_form, "form2": profile_form})
示例3: edit_profile
def edit_profile(request):
user = request.user
users = User.objects.get(username=user)
profile = Profile.objects.get(user=user)
group = Group.objects.get(name='user')
user_members = group.user_set.all()
if user in user_members:
if request.method == 'POST':
form1 = EditUserForm(request.POST, instance=users)
form2 = ProfileForm(request.POST, instance=profile)
if form1.is_valid() and form2.is_valid():
form2.save()
form1.save()
return HttpResponseRedirect('/')
else:
form1 = EditUserForm(instance=users)
form2 = ProfileForm(instance=profile)
variables = RequestContext(request, {'user':user,'user_members':user_members,'form1': form1, 'form2':form2})
else:
if request.method == 'POST':
form1 = MerchantForm(request.POST, instance=users)
if form1.is_valid():
form1.save()
return HttpResponseRedirect('/')
else:
form1 = MerchantForm(instance=users)
variables = RequestContext(request, {'user':user,'user_members':user_members,'form1': form1})
return render_to_response('users/edit_profile.html', variables)
示例4: post
def post(self, request):
if request.GET.get('login'):
self.post_login(request)
username = request.POST.get('username')
password = request.POST.get('password')
user = authenticate(username=username, password=password)
if user:
if user.is_active:
login(request, user)
return redirect('tasks:index')
return render(request, 'users/login.html', {'user_form': UserForm(), 'profile_form': ProfileForm()})
else:
user_form = UserForm(data=request.POST)
profile_form = ProfileForm(data=request.POST)
if user_form.is_valid() and profile_form.is_valid():
with atomic():
user = user_form.save()
user.set_password(user.password)
user.save()
profile = profile_form.save(commit=False)
profile.user = user
profile.creating = True
profile.updating = True
thread = Thread()
thread.save()
profile.thread = thread
profile.save()
login(request, user)
return redirect('tasks:index')
else:
return render(request, 'users/login.html', {'user_form':user_form, 'profile_form': profile_form})
示例5: edit_profile
def edit_profile(request):
"""Edit user profile."""
try:
user_profile = request.user.get_profile()
except Profile.DoesNotExist:
# TODO: Once we do user profile migrations, all users should have a
# a profile. We can remove this fallback.
user_profile = Profile.objects.create(user=request.user)
if request.method == 'POST':
form = ProfileForm(request.POST, request.FILES, instance=user_profile)
if form.is_valid():
user_profile = form.save()
new_timezone = user_profile.timezone
if request.session.get('timezone', None) != new_timezone:
request.session['timezone'] = new_timezone
return HttpResponseRedirect(reverse('users.profile',
args=[request.user.id]))
else: # request.method == 'GET'
form = ProfileForm(instance=user_profile)
# TODO: detect timezone automatically from client side, see
# http://rocketscience.itteco.org/2010/03/13/automatic-users-timezone-determination-with-javascript-and-django-timezones/
return jingo.render(request, 'users/edit_profile.html',
{'form': form, 'profile': user_profile})
示例6: post
def post(self, *args, **kwargs):
if not self.request.user.is_authenticated():
return self.render({'error': 'Please log in before posting'})
form = ProfileForm(data=json.load(self.request), instance=self.request.user)
if form.is_valid():
form.save()
return self.get(*args, **kwargs)
else:
return self.render({'error': 'Data is invalid', 'errors_list': form.errors})
示例7: save
def save(request, user_id): # action
# saves changes to user profile
user = get_object_or_404(User, pk=user_id)
userProfile = Profile.objects.get(user=user)
if request.method == 'POST':
form = ProfileForm(request.POST,instance=userProfile)
if form.is_valid():
form.save()
return HttpResponseRedirect(reverse('users:profile', args=[user_id]))
else:
return HttpResponseRedirect(reverse('users:edit', args=[user_id]))
示例8: handle_profile_save
def handle_profile_save(request):
"""Edit or create a user profile."""
profile = request.user.get_profile()
if request.method == 'POST':
form = ProfileForm(data=request.POST,
files=request.FILES,
instance=profile)
if form.is_valid():
profile = form.save(commit=False)
profile.user = request.user
profile.save()
return form
return ProfileForm(instance=profile)
示例9: save_settings
def save_settings(request):
if not request.user.is_authenticated(): # XXX improve this
return {'error': 'Not logged in'}
from users.forms import ProfileForm
profile = request.user.get_profile()
form = ProfileForm(instance=profile, data=request.POST)
if form.is_valid():
profile = form.save(commit=False)
profile.country = form.cleaned_data['country']
profile.save()
return {'ok': True}
else:
return {'form_errors': form.errors}
示例10: edit_profile
def edit_profile(request):
profile = get_profile(request.user)
if request.method == "GET":
profile_form = ProfileForm(instance=profile)
elif request.method == "POST":
profile_form = ProfileForm(instance=profile, data=request.POST)
if profile_form.is_valid():
profile_form.save()
messages.add_message(request, messages.SUCCESS,
"Your profile has been updated.")
return render(request, "users/edit_profile.html", {"form": profile_form})
示例11: lk
def lk(request):
c = get_common_context(request)
if not request.user.is_authenticated():
return HttpResponseRedirect('/')
if request.method == 'GET':
c['form'] = ProfileForm(instance=request.user.get_profile())
else:
form = ProfileForm(request.POST, instance=request.user.get_profile())
if form.is_valid():
form.save()
return HttpResponseRedirect('/lk/')
c['form'] = form
return render_to_response('lk.html', c, context_instance=RequestContext(request))
示例12: user_edit
def user_edit(request, pk):
user = User.get(pk)
form = UserForm(request.POST or None, instance=user)
profile = ProfileForm(request.POST or None, instance=get_profile(user))
if form.is_valid() and profile.is_valid():
form.save()
profile.save()
return HttpResponseRedirect(reverse("user-list"))
return direct_to_template(request, "user_edit.html", extra_context={
"form": form,
"profile": profile,
"nav": {"selected": "users",},
})
示例13: register
def register(request):
c = get_common_context(request)
register_form = ProfileForm()
c['register_form'] = register_form
auth_form = AuthenticationForm()
c['auth_form'] = auth_form
if request.method == "POST":
if request.POST['action'] == 'register':
register_form = ProfileForm(request.POST, request.FILES)
if register_form.is_valid():
error = False
if len(User.objects.filter(username=register_form.data.get('email'))):
register_form._errors["email"] = ErrorList([u'Такой емейл уже зарегистрирован.'])
error = True
if not error:
email = register_form.data.get('email')
u = User(username= email,
email=email,
first_name=register_form.data.get('fio'))
password = password_generator()
u.set_password(password)
u.save()
p = register_form.save(commit=False)
p.user = u
p.save()
user = auth.authenticate(username=email, password=password)
auth.login(request, user)
p.send(password)
return HttpResponseRedirect('/edu/')
c['register_form'] = register_form
elif request.POST['action'] == 'auth':
auth_form = AuthenticationForm(request.POST)
if auth_form.is_valid():
pass
username = request.POST.get('username', '')
password = request.POST.get('password', '')
user = auth.authenticate(username=username, password=password)
if user is not None:
auth.login(request, user)
return HttpResponseRedirect('/edu/')
else:
auth_form._errors = {}
auth_form._errors["username"] = ErrorList([u'Неверный логин или пароль.'])
c['auth_form'] = auth_form
c['title'] = u'Регистрация'
return render_to_response('register.html', c, context_instance=RequestContext(request))
示例14: reg_page
def reg_page(request):
c = get_common_context(request)
if request.method == 'GET':
client_form = ClientForm()
profile_form = ProfileForm()
user_form = UserForm()
elif request.method == 'POST':
client_form = ClientForm(request.POST)
profile_form = ProfileForm(request.POST)
user_form = UserForm(request.POST)
if request.POST.get('confirm', None) is None:
user_form.errors['confirm'] = ErrorList([u'Необходимо согласиться с договором.'])
elif user_form.data['passwd1'] != user_form.data['passwd2']:
user_form.errors['passwd1'] = ErrorList([u'Пароли не совпадают.'])
elif not user_form.data['email']:
user_form.errors['email'] = ErrorList([u'Обязательное поле.'])
elif client_form.is_valid() and profile_form.is_valid() and user_form.is_valid():
try:
u = auth.models.User(username=user_form.data['email'],
email=user_form.data['email'],
first_name=user_form.data['first_name'],
)
u.save()
u.set_password(user_form.data['passwd1'])
u.save()
except:
u = None
user_form.errors['email'] = ErrorList([u'Пользователь с таким email уже существует'])
if u: # user saved, all is right
p = u.get_profile()
p.phone = profile_form.data['phone']
p.work_phone=profile_form.data['work_phone']
p.qiwi=profile_form.data['qiwi']
p.user = u
p.type = 'c'
p.save()
Client.add(u, client_form.data['name'])
user = auth.authenticate(username=user_form.data['email'], password=user_form.data['passwd1'])
auth.login(request, user)
messages.success(request, u'Вы успешно зарегистрировались в системе в качестве клиента.')
return HttpResponseRedirect('/cabinet')
c['client_form'] = client_form
c['profile_form'] = profile_form
c['user_form'] = user_form
return render_to_response('client/reg.html', c, context_instance=RequestContext(request))
示例15: edit_profile
def edit_profile(request):
try:
profile = Profile.objects.get(user=request.user)
except Profile.DoesNotExist:
raise Http404
if request.method == 'POST':
form = ProfileForm(data=request.POST, files=request.FILES, instance=profile)
if form.is_valid():
form.save()
return HttpResponseRedirect('/user/')
else:
print profile
form = ProfileForm(instance=profile)
return render(request, 'profiles/edit_profile.html', {"profile": profile, "form": form})