def project_edit(project_id): proj = Project.query.get(project_id) if not proj: abort(404) if g.user.is_superuser(): form = AdminProjectForm(obj=proj) else: form = ProjectForm(obj=proj) if form.validate_on_submit(): form.populate_obj(proj) for assoc in proj.user_assoc: if not assoc.created_by: assoc.created_by = g.user try: db.session.commit() flash("Sucess: Project Modified") except: raise flash("Failed to update database") db.session.rollback() return render_template('project_edit.html', form=form, project=proj, user_add_form=UserSelector())
def project_list(): if request.method == 'POST': form = AdminProjectForm(request.form) proj = Project() form.populate_obj(proj) if not g.user.is_superuser(): proj.pi = g.user proj.is_active = False if form.validate(): try: db.session.add(proj) db.session.commit() if g.user.is_superuser(): flash("Sucess: Project Created") else: flash("Sucess: Project Requested") return redirect(url_for('.project_list')) except: flash("Failed to update database") db.session.rollback() return render_template('project_edit.html', form=form, proj=proj) return render_template('project_edit.html', form=form, proj=proj) if g.user.is_superuser(): form = AdminProjectForm() else: form = ProjectForm() projects = Project.query.order_by(Project.name) if g.user.is_superuser() else Project.query.filter(Project.pi==g.user).order_by(Project.name) active = projects.filter(Project.is_active==True) inactive = projects.filter(Project.is_active==False) return render_template('project_list.html', projects=projects, form=form, active=active, inactive=inactive)