Esempio n. 1
0
def add_members_confirm_submit():
  """Handles new member creation."""
  # Expects new member data to be passed as a CSV string.
  new_member_data = flask.request.form.get('new_member_data', None)
  # Silently verify data. There shouldn't be any errors if everything is being
  # used as intended.
  new_member_list = member_helpers.NewMemberList()
  if new_member_list.parse_csv_string(new_member_data):
    if new_member_list.validate_data(flash_errors=False):
      new_member_list.add_members()
      return flask.redirect(flask.url_for('admin.add_members'))
  # An error happened somewhere.
  flask.flash("An unexpected error was encountered. Please find an IMSS rep.")
  return flask.redirect(flask.url_for('admin.add_members'))
Esempio n. 2
0
def add_members_multi_confirm():
    """Submission endpoint for adding multiple members at a time."""
    new_members_file = flask.request.files.get('new_members_file', None)
    if new_members_file is None:
        flask.flash("You must upload a file!")
        return flask.redirect(flask.url_for('admin.add_members'))
    # Save the file to a tempfile so we can parse it.
    f = tempfile.NamedTemporaryFile()
    f.write(new_members_file.read())
    f.flush()
    # Parse and validate the data.
    new_member_list = member_helpers.NewMemberList()
    if new_member_list.parse_csv_file(f.name):
        if new_member_list.validate_data():
            return flask.render_template('add_members_confirm.html',
                                         new_member_list=new_member_list,
                                         data_string=str(new_member_list))
    return flask.redirect(flask.url_for('admin.add_members'))
Esempio n. 3
0
def add_members_single_confirm():
  """Submission endpoint for adding a single member."""
  fname = flask.request.form.get('fname', '')
  lname = flask.request.form.get('lname', '')
  matriculate_year = flask.request.form.get('matriculate_year', '')
  grad_year = flask.request.form.get('grad_year', '')
  uid = flask.request.form.get('uid', '')
  email = flask.request.form.get('email', '')
  membership_desc = flask.request.form.get('membership_desc', '')

  # Check that data was valid.
  new_member = member_helpers.NewMember(fname, lname, matriculate_year, grad_year,
      uid, email, membership_desc)
  new_member_list = member_helpers.NewMemberList([new_member])
  if new_member_list.validate_data():
    return flask.render_template('add_members_confirm.html',
        new_member_list=new_member_list,
        data_string = str(new_member_list))
  return flask.redirect(flask.url_for('admin.add_members'))