Example #1
0
def edit_project2(project_id):

  if 'email' not in session:
    return redirect(url_for('home'))

  project_By_ID = project.query.filter_by(id = project_id).first_or_404()

  show_project = ProjectForm()
  show_project.set_supervisor_choices()

  show_project.setFormContentFromProject(project_By_ID)

  if request.method == 'POST':
    show_project = ProjectForm()
    show_project.set_supervisor_choices()
    if show_project.validate() == False:
      flash('Please fill out everything')
      return render_template('edit_project.html', show_project=show_project, projectByID = project_By_ID)
    else:
      project_By_ID.updateProject(show_project)
      db.session.add(project_By_ID)
      db.session.commit()
      return redirect(url_for('home'))
                     
  elif request.method == 'GET':
    return render_template('edit_project.html', show_project=show_project, projectByID = project_By_ID)
Example #2
0
def create_project():

  if 'email' not in session:
    return redirect(url_for('home'))

  show_project = ProjectForm()
  show_project.set_supervisor_choices()

  if request.method == 'POST':
    if show_project.validate() == False:
      flash('All fields are required.')
      return render_template('create_project.html', show_project=show_project)
    else:
      new_project = project(show_project, session['email'])
      db.session.add(new_project)
      db.session.commit()
      if show_project.file.data.filename:
        os.makedirs("Project/files/" + str(newuser.id))
        filename = secure_filename(show_project.file.data.filename)
        show_project.file.data.save('Project/files/' + str(newuser.id) + "/" + filename)
      flash('Project has been created')
      return redirect(url_for('create_project'))
 
  elif request.method == 'GET':
    return render_template('create_project.html', show_project=show_project)