def signup(request): context = {'user_form': UserForm, 'profile_form': ProfileForm} if 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(commit=False) user.password = make_password(user.password) profile = profile_form.save(commit=False) group_role = Role.objects.get(id=profile.role.id) if group_role.description == 'Arrendatario': user.is_staff = True user.save() group = Group.objects.get(name='Arrendador') group.user_set.add(user) user.save() profile.user = user profile.save() return redirect('login') else: messages.error( request, 'Uno o mas campos requeridos no fueron enviados, completa los campos requeridos' ) return render(request, 'signup.html', context) return render(request, 'signup.html', context)
def post(self, request, user_id, *args, **kwargs): profileInstance = get_object_or_404(Profile, id=user_id) userInstance = get_object_or_404(get_user_model(), id=profileInstance.user.id) if userInstance.is_superuser and request.user.is_superuser == False: return render(request, 'users/authentication_message.html') userForm = MyUserUpdateForm(request.POST or None, instance=userInstance) profileForm = ProfileForm(request.POST or None, request.FILES or None, instance=profileInstance) if userForm.is_valid() and profileForm.is_valid(): user = userForm.save() profile = profileForm.save() messages.add_message( request, messages.INFO, 'User %s updated successfully' % (user.first_name)) return redirect('user-home') return render_to_response('users/user/user_form.html', context_instance=RequestContext( request, { 'userForm': userForm, 'profileForm': profileForm }))
def post(self, request, user_id, *args, **kwargs ): profileInstance = get_object_or_404(Profile, id=user_id) userInstance = get_object_or_404(get_user_model(), id=profileInstance.user.id) if userInstance.is_superuser and request.user.is_superuser == False: return render(request,'users/authentication_message.html') userForm = MyUserUpdateForm(request.POST or None, instance=userInstance ) profileForm = ProfileForm(request.POST or None, request.FILES or None, instance=profileInstance ) if userForm.is_valid() and profileForm.is_valid(): user = userForm.save() profile = profileForm.save() messages.add_message(request, messages.INFO, 'User %s updated successfully' % ( user.first_name ) ) return redirect('user-home') return render_to_response('users/user/user_form.html',context_instance= RequestContext(request, { 'userForm': userForm, 'profileForm': profileForm }))
def post(self,request,*args,**kwargs): userForm = MyUserCreationForm(request.POST) profileForm = ProfileForm(request.POST, request.FILES) if userForm.is_valid() and profileForm.is_valid(): specific_user = userForm.save() #print "u id >>>" #print specific_user.id userInstance = get_object_or_404(get_user_model(), id=specific_user.id) userForm2 = MyUserUpdateForm(request.POST or None, instance=userInstance ) specific_user = userForm2.save() #specific_user.groups.add(Group.objects.get(name='THCC SYSTEM USERS')) print "user created ok" #USER_PROFILE_SYNC(request) profile_instance = get_object_or_404(Profile, id=specific_user.profile.id) profileForm = ProfileForm(request.POST, request.FILES,instance=profile_instance) specific_profile = profileForm.save(commit=False) #specific_profile.id = specific_user.id specific_profile.user = specific_user specific_profile.save() #print "u id >>>" #print specific_profile.id messages.add_message(request, messages.INFO, 'User %s created successfully' % ( specific_user.first_name ) ) return redirect('user-home') return render_to_response('users/user/user_form.html', RequestContext(request, { 'userForm':userForm, 'profileForm':profileForm }))
def get(self, request, user_id, *args, **kwargs): aProfile = Profile.objects.get(id=user_id) aUser = User.objects.get(id=aProfile.user.id) if aUser.is_superuser and request.user.is_superuser == False: return render(request, 'users/authentication_message.html') userForm = MyUserUpdateForm(instance=aUser) profileForm = ProfileForm(instance=aProfile) return render_to_response( 'users/user/user_form.html', RequestContext(request, { 'userForm': userForm, 'profileForm': profileForm }))
def get(self, request, *args, **kwargs): current_user_group = self.request.user.groups.all() if self.request.user.is_superuser: userForm = MyUserCreationForm() elif current_user_group[0].name == "Admin User": userForm = MyUserCreationForm() elif current_user_group[0].name == "Standard User": userForm = MyUserCreationForm1() profileForm = ProfileForm() return render_to_response( 'users/user/user_form.html', RequestContext(request, { 'userForm': userForm, 'profileForm': profileForm }))
def update_profile(request): if request.method == 'POST': user_form = SignUpForm(request.POST, instance=request.user) profile_form = ProfileForm(request.POST, instance=request.user.profile) if user_form.is_valid() and profile_form.is_valid(): user_form.save() profile_form.save() messages.success(request, _('Your profile was successfully updated!')) return redirect('settings:profile') else: messages.error(request, _('Please correct the error below.')) else: user_form = SignUpForm(instance=request.user) profile_form = ProfileForm(instance=request.user.profile) return render(request, 'profiles/profile.html', { 'user_form': user_form, 'profile_form': profile_form })
async def patch(self, *args, **kwargs): """ 修改个人信息 部分更新(密码和账号不能修改) :param args: :param kwargs: :return: """ req_data = self.request.body.decode("utf-8") req_data = json.loads(req_data) profile_form = ProfileForm.from_json(req_data) res_data = {} if profile_form.validate(): self.current_user.nick_name = profile_form.nick_name.data self.current_user.gender = profile_form.gender.data self.current_user.address = profile_form.address.data self.current_user.description = profile_form.description.data await self.application.objects.update(self.current_user) else: self.set_status(400) for field in profile_form.errors: res_data[field] = profile_form.errors[field][0] self.finish(res_data)
def post(self, request, *args, **kwargs): userForm = MyUserCreationForm(request.POST) profileForm = ProfileForm(request.POST, request.FILES) if userForm.is_valid() and profileForm.is_valid(): specific_user = userForm.save() #print "u id >>>" #print specific_user.id userInstance = get_object_or_404(get_user_model(), id=specific_user.id) userForm2 = MyUserUpdateForm(request.POST or None, instance=userInstance) specific_user = userForm2.save() #specific_user.groups.add(Group.objects.get(name='THCC SYSTEM USERS')) print "user created ok" #USER_PROFILE_SYNC(request) profile_instance = get_object_or_404(Profile, id=specific_user.profile.id) profileForm = ProfileForm(request.POST, request.FILES, instance=profile_instance) specific_profile = profileForm.save(commit=False) #specific_profile.id = specific_user.id specific_profile.user = specific_user specific_profile.save() #print "u id >>>" #print specific_profile.id messages.add_message( request, messages.INFO, 'User %s created successfully' % (specific_user.first_name)) return redirect('user-home') return render_to_response( 'users/user/user_form.html', RequestContext(request, { 'userForm': userForm, 'profileForm': profileForm }))