def project_add(): project_form = ProjectForm(request.form) if project_form.validate_on_submit(): project = Project() project_form.populate_obj(project) project.image = get_image_from_file_field(project_form.image, request) db.session.add(project) projects = Project.query.all() return render_template('projects/add.html', projects=projects, form=project_form)
def project_edit(project_id): project = Project.query.get(project_id) if request.method == 'POST': project_form = ProjectForm(request.form) project_form.populate_obj(project) project.image = get_image_from_file_field(project_form.image, request) db.session.commit() return render_template('projects/edit.html', project=project)
def project_edit(project_id): project = Project.query.get(project_id) form = ProjectForm(obj=project) if form.validate_on_submit(): form.populate_obj(project) project.image = get_image_from_file_field(form.image, request) db.session.commit() flash('Project edited', 'success') return redirect(url_for('web.project_index')) return render_template('projects/edit.html', form=form, project_id=project_id)
def project_add(): project_form = ProjectForm(request.form) if project_form.validate_on_submit(): project = Project() project_form.populate_obj(project) project.image = get_image_from_file_field(project_form.image, request) db.session.add(project) db.session.commit() flash('Project created', 'success') return redirect(url_for('web.project_index')) return render_template('projects/add.html', form=project_form)
def project_add(): # Don't pass request.form as flask_wtf do it automatically, and # if request.form is passed it won't load the images!!!! project_form = ProjectForm() if project_form.validate_on_submit(): project = Project() project_form.populate_obj(project) project.image = get_image_from_file_field(project_form.image, request) db.session.add(project) db.session.commit() flash('Project created', 'success') return redirect(url_for('web.project_index')) return render_template('projects/add.html', form=project_form)
def project_form(): """ Returns a Project Form with valid data populated. """ values = {'name': "Proyecto de testing", 'description': "Este es un proyecto de prueba para test", 'start_date': "24-01-2015", 'end_date': "24-02-2015", 'location': "Prueba a ver si lo encuentras", 'contact_phone': "987654321", 'image': None } return ProjectForm(data=values)
def test_should_throw_exception_when_is_empty(project_form): fixture = {} project = ProjectForm(data=fixture) assert not project.validate()
def test_should_throw_exception_when_is_empty(project_form): from autoconstruccion.web.forms import ProjectForm fixture = {} project = ProjectForm(data=fixture) assert not project.validate()