Changeset 641 in tmcsimulator for branches/LCSv2/controllers/default.py


Ignore:
Timestamp:
03/13/2021 05:17:45 PM (5 years ago)
Author:
jdalbey
Message:

LCSv2.default.py modified for #254. Changed studentnames file reading.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/LCSv2/controllers/default.py

    r636 r641  
    11# added comments for testing 
    22# Constants 
    3 kLogfile = "samplelogfile.txt" 
     3kLogfile = "LCSlogfile.txt" 
    44kSimtimefile = "sim_elapsedtime.json"  #"../webapps/dynamicdata/sim_elapsed_time.json" 
    55hwys = ['','1','5', '22', '55', '57', '73', '74', '91', '133', '142', '241', '261', '405', '605'] 
     
    77# Names to appear in the username dropdown box 
    88users = [] 
     9users.append('') 
    910# Show the login page 
    1011def index(): 
    1112    userfile = open('student_names.txt','r') 
    12     users = [line.strip() for line in userfile.readlines()] 
    13     users.insert(0,'') 
     13    # read the file into a buffer 
     14    buffer = [line.strip() for line in userfile.readlines()] 
     15    # Append each name in the buffer to the users list, skipping blank lines 
     16    for item in buffer: 
     17        if len(item) > 0: 
     18            users.append(item) 
     19    # build the form 
    1420    form = FORM(LABEL('User:',_for='username', _class="label username-label"), 
    1521                #INPUT(_name='username', _size='15', _style="font-size: 18px;"), BR(), 
     
    1824    if form.process().accepted: 
    1925        # Put the username entry into the session variable 
    20         session.username = form.vars.username 
     26        session.username = reverseNameFields(form.vars.username) 
    2127        redirect(URL('home')) 
    2228    return dict(form=form) 
     
    376382        return "NO" 
    377383 
     384# Swap the fields in a name, changing lastname first to firstname first. 
     385def reverseNameFields(formattedname): 
     386    # Divide the name into last and first names 
     387    x = formattedname.split(',') 
     388    # If there isn't a comma, return the entire name 
     389    if len(x) == 1: 
     390        return x[0].strip() 
     391    else:  # return the swapped fields 
     392        return x[1].strip() + ' ' + x[0] 
     393 
    378394# Convert the lanes closed checkboxes into a human readable string 
    379395# E.g.  #1 #3 of 4 
Note: See TracChangeset for help on using the changeset viewer.