def edit(request): args = {} user = auth.get_user(request) args.update(csrf(request)) user_change_form = UserChangeForm(instance=request.user) user_change_form.avatar = user.avatar args['form'] = user_change_form args['userreg'] = user.region_id args['header'] = 'Редактирование информации - %s' % user.username args['regions_list'] = Regions.objects.all() if request.method == 'POST': form = UserChangeForm(request.POST, request.FILES, instance=request.user) if form.is_valid(): form.save() user = User.objects.get(id=auth.get_user(request).id) user.region_id = request.POST.get('region_select') f = open(create_image(user.username, user.username), 'rb') username_image = File(f) user.username_image.save(user.username + '.png', username_image) user.avatar = form.cleaned_data['avatar'] user.save() args = {} args['user'] = auth.get_user(request) f.close() return redirect('/account/%s/' % auth.get_user(request).username, args) else: args['form'] = UserChangeForm(request.POST) args['form'] = form return render(request, 'edit.html', args)
def change(request): if request.method == 'POST': form = UserChangeForm(request.POST, instance=request.user) if form.is_valid(): form.save() return HttpResponseRedirect(reverse('task_list')) else: form = UserChangeForm(instance=request.user) return render_to_response('registration/registration_change.html', {'form':form, 'user':request.user}, context_instance=RequestContext(request))
def editUser_view(request): form = UserChangeForm(request.POST or None) if form.is_valid(): form.save() return redirect('/RateMyServices/professional_profile.html') context = { 'form': form, } return render(request, 'RateMyServices/edit_profile.html', context)
def update_account(request, template_name): if request.method == 'POST': form = UserChangeForm(request.POST, instance=request.user) if form.is_valid(): form.save() return HttpResponseRedirect( reverse('accounts:profile-update-done')) else: form = UserChangeForm(instance=request.user) return render(request, template_name, {'form': form})
def edit_profile(request): if request.method == 'POST': form = UserChangeForm(request.POST, instance=request.user) if form.is_valid(): form.save() return redirect( reverse('accounts:profile', kwargs={'slug': 'self'})) else: form = UserChangeForm(instance=request.user) args = {'form': form} return render(request, 'account/edit.html', args)
def change(request): if request.method == 'POST': form = UserChangeForm(request.POST, instance=request.user) if form.is_valid(): form.save() return HttpResponseRedirect(reverse('task_list')) else: form = UserChangeForm(instance=request.user) return render(request, 'registration/registration_change.html', { 'form': form, 'user': request.user })
def profile_edit(request): if request.method == 'POST': form = UserChangeForm(request.POST, instance=request.user) if request.user.role == 1: profile_form = TAProfileChangeForm(request.POST, instance=request.user.ta_profile) elif request.user.role == 2: profile_form = TAProfileChangeForm(request.POST, instance=request.user.teacher_profile) elif request.user.role == 3: profile_form = TAProfileChangeForm(request.POST, instance=request.user.admin_profile) if form.is_valid() and profile_form.is_valid(): user_form = form.save() custom_form = profile_form.save(False) custom_form.user = user_form custom_form.save() return redirect('/accounts/profile/view') else: form = UserChangeForm(instance=request.user) if request.user.role == 1: profile_form = TAProfileChangeForm(instance=request.user.ta_profile) elif request.user.role == 2: profile_form = TeacherProfileChangeForm(instance=request.user.teacher_profile) elif request.user.role == 3: profile_form = AdminProfileChangeForm(instance=request.user.admin_profile) args = {'form': form, 'profile_form': profile_form} return render(request, 'accounts/profile_edit.html', args)
def user_edit(request, user_id): user = get_object_or_404(User, pk=user_id) if request.method == 'POST': form = UserChangeForm(request.POST, instance=user) if form.is_valid(): user = form.save(commit=False) user.save() return redirect('chat:user_detail', theme_id=user.id) else: form = UserForm(instance=user)
def edit_profile(request, username): ''' Allow user to edit their details as well as upload a new profile image ''' username = User.objects.get(username=request.user.username) if request.method == 'POST': edit_form = UserChangeForm(request.POST, instance=request.user) upload_img_form = UploadFileForm(request.POST, request.FILES, instance=request.user.userprofile) if edit_form.is_valid() and upload_img_form.is_valid(): upload_img_form.save() edit_form.save() messages.success( request, 'Your profile has been successfully \ updated!') return redirect('profile', username) else: edit_form = UserChangeForm(instance=request.user) upload_img_form = UploadFileForm(instance=request.user.userprofile) context = {'edit_form': edit_form, 'upload_img_form': upload_img_form} return render(request, 'edit_profile.html', context)
def settings(request): message = '' if request.method == 'POST': user_form = UserChangeForm(request.POST, instance=request.user) user_form.initForm() if user_form.is_valid(): user_form = user_form.save() return HttpResponseRedirect("/") else: message = "设置密码出错, 请重试." else: user_form = UserChangeForm(instance=request.user) return render_to_response('accounts/settings.html', { 'user_form':user_form, 'msg':message}, context_instance=RequestContext(request))