예제 #1
0
파일: routes.py 프로젝트: martinsoender/PIS
def create_supervisor():

  """
  Routing to create_supervisor.html

  Returns:
    create_supervisor.html:
      when validator fails with error message.
      when supervisor created with confirm message

  """

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

  scraper = ScraperForm()
  scraper.set_supervisor_choices()
  form = SupervisorForm()

  if form.is_submitted():
    if form.validate() == False:
      flash('Missing required fields.')
      return render_template('create_supervisor.html', scraper=scraper, form=form)
    else:
      new_Supervisor = supervisor(form)
      db.session.add(new_Supervisor)
      db.session.commit()
      flash('supervisor created')
      return redirect(url_for('create_supervisor'))

  return render_template('create_supervisor.html', scraper=scraper, form=form)
예제 #2
0
파일: routes.py 프로젝트: martinsoender/PIS
def edit_supervisor(supervisor_id):

  if 'email' not in session:
    return redirect(url_for('home'))
  
  supervisorByID = supervisor.query.filter_by(id=supervisor_id).first_or_404()

  show_supervisor = SupervisorForm()

  show_supervisor.setFormContentFromSupervisor(supervisorByID)

  if request.method == 'POST':
    show_supervisor = SupervisorForm()
    if show_supervisor.validate() == False:
      flash('Please fill out everything')
      return render_template('edit_supervisor.html', show_supervisor=show_supervisor, supervisorByID = supervisorByID)
    else:
      supervisorByID.updateSupervisor(show_supervisor)
      db.session.add(supervisorByID)
      db.session.commit()
      return redirect(url_for('admin_dashboard'))
                     
  elif request.method == 'GET':
    return render_template('edit_supervisor.html', show_supervisor=show_supervisor, supervisorByID = supervisorByID)