def update(self, project): form = EditProjectForm(csrf_enabled=False) if form.validate(): form.update(project) db.session.commit() return 200, "UPDATED" return 400, form.errors
def editProject(pid): project = Project.query.filter_by(id=pid).first() user = User.query.filter_by(id=session.get('user_id')).first() form = EditProjectForm(request.form) if request.method == 'POST' and form.validate(): if user == project.author: if form.title.data: project.title = form.title.data if form.status.data: project.public = not project.public if form.tags.data: newTags = form.tags.data newTags = newTags.split(',') oldTags = Tag.query.filter_by(project_id=project.id).all() for tag in oldTags: db_session.delete(tag) for tag in newTags: if tag.strip() != "": tag = Tag(tag.strip(), project.id) db_session.add(tag) db_session.add(project) db_session.commit() return redirect(url_for('project', pid=project.id)) return redirect(url_for('index')) return render_template('edit.html', form=form, project=project)
def edit_project(): form = EditProjectForm() if request.method == "POST": if form.validate(): project = form.update(g.project) db.session.commit() session[project.id] = project.password return redirect(url_for(".list_bills")) else: form.name.data = g.project.name form.password.data = g.project.password form.contact_email.data = g.project.contact_email return render_template("edit_project.html", form=form)