Esempio n. 1
0
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)
Esempio n. 2
0
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)
Esempio n. 3
0
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)
Esempio n. 4
0
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)
Esempio n. 5
0
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)
Esempio n. 6
0
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)
Esempio n. 7
0
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)
Esempio n. 8
0
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)
Esempio n. 9
0
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)
Esempio n. 10
0
 def test_fail_when_email_not_compilance(self):
     self.fixture['email'] = 'memememe'
     user = UserForm(data=self.fixture)
     assert not user.email.validate(user)
Esempio n. 11
0
 def test_fail_when_email_is_empty(self):
     self.fixture['email'] = ''
     user = UserForm(data=self.fixture)
     assert not user.email.validate(user)
Esempio n. 12
0
 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)
Esempio n. 13
0
 def test_user_valid_must_be_valid(self):
     user = UserForm(data=self.fixture)
     assert user.validate()
Esempio n. 14
0
 def test_user_valid_must_be_valid(self):
     user = UserForm(data=self.fixture)
     assert user.validate()