def add_project(): error = None form = AddProjectForm() form.client.choices = get_client_select_group() if form.validate_on_submit(): p = Project() p.title = form.title.data p.description = form.description.data p.client_id = form.client.data p.start_date = form.start_date.data if form.due_date.data: p.due_date = form.due_date.data db.session.add(p) db.session.commit() return redirect(url_for('project_list')) return render_template("project/addproject.html", error=error, form=form)
def edit_project(project_id): error = None theProj = Project.query.get_or_404(project_id) form = EditProjectForm(obj=theProj) form.client.choices = get_client_select_group() if request.method == 'GET': form.client.data = theProj.client_id if form.validate_on_submit(): theProj.start_date = form.start_date.data theProj.description = form.description.data theProj.due_date = form.due_date.data theProj.title = form.title.data theProj.percent_complete = form.percent_complete.data theProj.client_id = form.client.data msg = "{0} updated!".format(theProj.title) flash(msg) db.session.commit() return redirect(url_for('project_view', project_id=theProj.id)) return render_template("project/editproject.html", form=form, theProj=theProj)