def user_edit(user_id): user = User.query.get(user_id) form = UserForm(request.form, user) if request.method == 'POST': if form.validate(): form.populate_obj(user) db.session.commit() flash('Data saved successfully', 'success') return redirect(url_for('web.user_index')) flash('Data not valid, please review the fields') return render_template('users/edit.html', form=form, user_id=user_id)
def user_add(): form = UserForm(request.form) if request.method == 'POST': if form.validate(): user = User() form.populate_obj(user) user.store_password_hashed(form.password.data) db.session.add(user) db.session.commit() flash('Data saved successfully', 'success') return redirect(url_for('web.user_index')) flash('Data not valid, please review the fields') return render_template('users/add.html', form=form)
def project_join(project_id): project = Project.query.get(project_id) form = UserForm(request.form) if form.validate_on_submit(): user = User() form.populate_obj(user) db.session.add(user) db.session.commit() user.projects.append(project) db.session.commit() flash('Success', 'success') return redirect(url_for('web.project_view', project_id=project_id)) return render_template('projects/join.html', project=project, form=form)
def user_account(): user_id = current_user.get_id() user = User.query.get(user_id) if not user: raise Exception('User not found') form = UserForm(request.form, user) if request.method == 'POST': if form.validate(): form.populate_obj(user) user.store_password_hashed(form.password.data) db.session.commit() flash('Data saved successfully', 'success') return redirect(url_for('web.user_index')) flash('Data not valid, please review the fields') return render_template('users/account.html', form=form, user_id=user_id)
def user_form(request_ctx): """ Returns a Project Form with valid data populated. """ from autoconstruccion.web.forms import UserForm values = { 'full_name': "Pepe Pérez Mengano", 'email': "*****@*****.**", 'password': "******", 'phone_number': "654321987", 'abilities': "Hago de todo..", 'availability': "24/7", 'tools': "", 'materials': "", 'is_admin': False, } return UserForm(data=values)
def test_fail_when_email_not_compilance(self): self.fixture['email'] = 'memememe' user = UserForm(data=self.fixture) assert not user.email.validate(user)
def test_fail_when_email_is_empty(self): self.fixture['email'] = '' user = UserForm(data=self.fixture) assert not user.email.validate(user)
def test_fail_when_full_name_is_empty(self): self.fixture['full_name'] = '' user = UserForm(data=self.fixture) assert not user.full_name.validate(user)
def test_user_valid_must_be_valid(self): user = UserForm(data=self.fixture) assert user.validate()