def test_UserForm_invalid(self): form = UserForm(data={ "username": '', "first_name": '', "last_name": 'testlname' }) self.assertFalse(form.is_valid())
def test_UserForm_valid(self): form = UserForm( data={ "username": '******', "first_name": 'testname', "last_name": 'testlname' }) self.assertTrue(form.is_valid())
def register(request): registered = True user_form = UserForm() profile_form = UserProfileInfoForm() context = {'user_form': user_form, 'profile_form': profile_form, 'registered': registered} return render(request, 'registration/formregis.html', context)
def signup(): # Check if current user is anonymous, else send to index page if not current_user.is_anonymous: return redirect(url_for('home.index')) # Use the defined UserForm form = UserForm() if form.validate_on_submit(): # Add user to database if validate user = User(name=form.name.data, email=form.email.data, password=form.password.data, picture=form.picture.data) db.session.add(user) db.session.commit() if app.debug: app.logger.debug("User {} signed up!".format( (user.id, user.name))) flash("You are now signed up. Please login to your account", category='success') return redirect(url_for('home.index')) return render_template('home/signup.html', action="Sign up", form_action='home.signup', form=form)
def update_profile(request): if request.method == 'POST': user_form = UserForm(request.POST, instance=request.user) if user_form.is_valid(): user_form.save() return redirect('profile') else: user_form = UserForm(instance=request.user) return render(request, 'update_profile.html', {'user_form': user_form})
def create_user(request): if request.method == 'POST': form = UserForm(request.POST) if form.is_valid(): # email = form.cleaned_data['email'] # subject = 'FirstPick account created' # message = 'Welcome to FirstPick, go shopping online now!!!!' # sender = '*****@*****.**' # send_mail(subject, message,sender,[email]) form.save() return HttpResponseRedirect('/') else: form = UserForm() return render(request, 'create_user.html', {'forms': form})