Changeset 626 in tmcsimulator for branches/LCSv2/controllers


Ignore:
Timestamp:
08/30/2020 01:49:28 PM (6 years ago)
Author:
jdalbey
Message:

LCS Add revision number to Help page. Add resetdb page.

Location:
branches/LCSv2/controllers
Files:
2 edited

Legend:

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

    r624 r626  
    299299    return dict(form=form) 
    300300 
     301# An unlinked page to allow admin to reset the database to simulation start state 
     302def resetdb(): 
     303    form = FORM("Press this button to reset the closure database to its original state at the start of a simulation.",BR(), 
     304                "Warning: this will delete all the current closures.",BR(), 
     305                "Import filename is 'db_closures_start.csv'.",BR(), 
     306                INPUT(_value="Reset Database", _type='submit', _class="btn btn-primary btn-default")) 
     307    if form.process().accepted: 
     308        db(db.closures.id > 0).delete()   # remove all current records 
     309        with open('db_closures_start.csv', 'rb') as dumpfile: 
     310            db.closures.import_from_csv_file(dumpfile)  # import from starting state 
     311        session.flash = 'Closure database has been reset' 
     312        redirect(URL('search.html')) 
     313    return dict(form=form) 
     314 
    301315# Validation for existing closure button 
    302316# If user selected Yes (it's existing incident) then they must select a closure ID 
     
    347361            result = result + "#"+item + " " 
    348362        result = result + "of " + lanecount 
    349     return result  
     363    return result 
  • branches/LCSv2/controllers/default.py.bak

    r622 r626  
    33hwys = ['','1','5', '22', '55', '57', '73', '74', '91', '133', '142', '241', '261', '405', '605'] 
    44hwyDirections = ['','NB', 'SB', 'NB/SB','EB','WB','EB/WB'] 
     5# Names to appeaer in the username dropdown box 
     6users = [] 
    57# Show the login page 
    68def index(): 
    7     form = FORM(LABEL('Username:',_for='username', _class="label username-label"), 
    8                 INPUT(_name='username', _size='15', _style="font-size: 18px;"), BR(), 
     9    userfile = open('student_names.txt','r') 
     10    users = [line.strip() for line in userfile.readlines()] 
     11    users.insert(0,'') 
     12    form = FORM(LABEL('User:',_for='username', _class="label username-label"), 
     13                #INPUT(_name='username', _size='15', _style="font-size: 18px;"), BR(), 
     14                SELECT(users,_name='username',requires=IS_LENGTH(minsize=1,error_message='Must select a user from the list.')),BR(), 
    915                INPUT(_type='submit',_value="Log in", _class=" btn btn-primary", _style="margin-top: 3%;")) 
    1016    if form.process().accepted: 
     
    9298    count = len(hwy) 
    9399    # Show the results in table format.  Get the radio call number from supervisor name lookup 
    94     header = THEAD(TR(TH(''), TH('DTM',BR(),'Area'), TH('Closure ID/',BR(),'Log No.'),TH('Route & Dir/',BR(),'Type of Closure'),TH('Start Date/',BR(),'End Date/',BR(),'Est. Delay'),TH('Facility'),TH('Limits'),TH('Work'), TH('TMP:',BR(),'Cozeep/',BR(),'Detour'),TH('Requestor/',BR(),'Radio Call No.'))) 
     100    header = THEAD(TR(TH(''), TH('DTM',BR(),'Area'), TH('Closure ID/',BR(),'Log No.'),TH('Route & Dir/',BR(),'Type of Closure'),TH('Start Date/',BR(),'End Date/',BR(),'Est. Delay'),TH('Facility/Lanes'),TH('Limits'),TH('Work'), TH('TMP:',BR(),'Cozeep/',BR(),'Detour'),TH('Requestor/',BR(),'Radio Call No.'))) 
    95101    multiform = [] 
    96102    # Iterates over all search results 
     
    103109                          INPUT(_type='submit',_name='btn2',_value='Show Status Form',_class="submit-button" ), 
    104110                          INPUT(_type='hidden',_name='row',_value=row.closureid))), 
    105                           TD(row.closureid[0]),TD(row.closureid,HR(),row.lognum), TD(row.route,' ',row.direction,HR(),row.closuretype), TD(row.startdate,' ',formatTime(row.starttime),HR(),row.enddate,' ',formatTime(row.endtime),HR(),row.estdelay), TD(row.facility),TD(row.startlocation,HR(),row.endlocation), TD(row.worktype), TD(row.tmpcozeep,BR(),row.tmpdetour), TD(row.supervisor,HR(),db(db.supervisors.name == row.supervisor).select().first().radiocallnum) ))  
     111                          TD(row.closureid[0]),TD(row.closureid,HR(),row.lognum), TD(row.route,' ',row.direction,HR(),row.closuretype), TD(row.startdate,' ',formatTime(row.starttime),HR(),row.enddate,' ',formatTime(row.endtime),HR(),row.estdelay), TD(row.facility,HR(),row.closedlanes), 
     112TD(row.startlocation,HR(),row.endlocation), TD(row.worktype), TD(row.tmpcozeep,BR(),row.tmpdetour), TD(row.supervisor,HR(),db(db.supervisors.name == row.supervisor).select().first().radiocallnum) ))  
    106113 
    107114    session.chosenid = request.vars.row #Pass the hidden field containing the closure ID 
     
    207214        supervisors.append(row.radiocallnum + ' ' + row.name) 
    208215    crew = ['']  # List of names for the dropdown box 
     216    crewlookup = [] 
    209217    # Obtain all the crew names from the database 
    210218    for row in db().select(db.crew.ALL): 
    211219        crew.append(row.radiocallnum + ' ' + row.name) 
     220        crewlookup.append(row.radiocallnum + ' ' + row.name) 
    212221    # Build the list of street locations and a hidden cross street lookup table 
    213222    streets = [''] 
     
    248257                    TD(INPUT(_type='checkbox',_name='cozeep'),'CoZeep MaZeep/CHP',BR(),  
    249258                       INPUT(_type='checkbox', _name='detour'),'Detour Available')), 
    250                  TR(TD(DIV(LABEL("Lanes closed"),DIV(_id='boxes'),_id='lanechooser',_style='display:none')), 
     259                 TR(TD(DIV(LABEL("Lanes closed"),DIV(INPUT(_type='checkbox', _name='lanes', _id='lanes', _value=' '), _id='boxes'),_id='lanechooser',_style='display:none')), 
    251260                    TD(INPUT(_type='hidden', _name='lanecount', _id='lanecount', _value='4')), 
    252261                    TD(), 
     
    256265            TD(LABEL('Field Rep')) 
    257266            ),  
    258           TR(TD(SELECT(supervisors,_name='supervisor', requires=IS_LENGTH(minsize=1,error_message='supervisor cannot be empty'))), 
    259              TD(SELECT(crew,_name='fieldrep')), 
     267          TR(TD(SELECT(supervisors,_name='supervisor', _id='supervisorcombo', _onchange='supervisorchanged()', requires=IS_LENGTH(minsize=1,error_message='supervisor cannot be empty'))), 
     268             TD(SELECT(crew,_name='fieldrep',_id='fieldrep')), 
    260269             TD(XML("    ")), 
    261270             TD('Is this an existing incident?', 
     
    272281                  TR(TD(INPUT(_name='meeting', _size='25')),TD(INPUT(_name='reason',_size='25')),TD(INPUT(_name='remarks',_size='25'))) ), BR(),  
    273282            INPUT(_type='submit',_value='Submit Closure', _class="btn btn-primary btn-default", _style="margin:  2% 45% 2% 40%;"), 
    274             XML('\n'),SELECT(streetlookup,_name='stlookup', _id='stlookup', _class='hideme'))  
     283            XML('\n'),SELECT(streetlookup,_name='stlookup', _id='stlookup', _class='hideme'),  
     284SELECT(crewlookup,_name='crewlookup', _id='crewlookup', _class='hideme'))  
    275285 
    276286    if form.process(onvalidation=validate_existing_id).accepted: 
     
    282292        supervisor_name = form.vars.supervisor[3:] 
    283293        fieldrep_name = form.vars.fieldrep[5:] 
     294        selectedlanes = buildLanesClosedString(form.vars.lanes,form.vars.lanecount) 
    284295        # Insert the record into the database 
    285         newrec = db.closures.insert(closureid=newID, lognum=newLognum, route=form.vars.route, direction=form.vars.direction, facility=form.vars.facility, startcounty=form.vars.startcounty, endcounty=form.vars.endcounty, startlocation=form.vars.startlocation, endlocation=form.vars.endlocation, startdate=form.vars.startdate, enddate=form.vars.enddate, starttime=form.vars.starttime+form.vars.starttimemin, endtime=form.vars.endtime+form.vars.endtimemin, closuretype=form.vars.closuretype, worktype=form.vars.worktype, estdelay=form.vars.estdelay, tmpcozeep=getCheckbox(form.vars.cozeep), tmpdetour=getCheckbox(form.vars.detour), supervisor=supervisor_name, fieldrep=fieldrep_name, s1097date='', s1098date='', s1022date='' ) 
    286         session.flash = 'New lane closure added: ' + newID + ' ' + newLognum + ', ' + buildLanesClosedString(form.vars.lanes) + ':' + form.vars.lanecount 
     296        newrec = db.closures.insert(closureid=newID, lognum=newLognum, route=form.vars.route, direction=form.vars.direction, facility=form.vars.facility, startcounty=form.vars.startcounty, endcounty=form.vars.endcounty, startlocation=form.vars.startlocation, endlocation=form.vars.endlocation, startdate=form.vars.startdate, enddate=form.vars.enddate, starttime=form.vars.starttime+form.vars.starttimemin, endtime=form.vars.endtime+form.vars.endtimemin, closuretype=form.vars.closuretype, closedlanes=selectedlanes, worktype=form.vars.worktype, estdelay=form.vars.estdelay, tmpcozeep=getCheckbox(form.vars.cozeep), tmpdetour=getCheckbox(form.vars.detour), supervisor=supervisor_name, fieldrep=fieldrep_name, s1097date='', s1098date='', s1022date='' ) 
     297        session.flash = 'New lane closure added: ' + newID + ' ' + newLognum + ': ' + selectedlanes 
     298        redirect(URL('search.html')) 
     299    return dict(form=form) 
     300 
     301# An unlinked page to allow admin to reset the database to simulation start state 
     302def resetdb(): 
     303    form = FORM("Press this button to reset the closure database to its original state at the start of a simulation.",BR(), 
     304                "Warning: this will delete all the current closures.",BR(), 
     305                INPUT(_value="Reset Database", _type='submit', _class="btn btn-primary btn-default")) 
     306    if form.process().accepted: 
     307        db(db.closures.id > 0).delete()   # remove all current records 
     308        with open('db_closures_start.csv', 'rb') as dumpfile: 
     309            db.closures.import_from_csv_file(dumpfile)  # import from starting state 
    287310        redirect(URL('search.html')) 
    288311    return dict(form=form) 
     
    296319# Calculate the closure id to assign to the new closure 
    297320def calcNextClosureID(routeNum): 
    298     # Retrieve any existing closures on this route 
    299     item = db(db.closures.closureid.startswith('T'+routeNum)).select().last() # Might need to sort these 
     321    # Retrieve the last existing closure on this route 
     322    #item = db(db.closures.closureid.startswith('T'+routeNum)).select().last() # defective 
     323    item = db(db.closures.route == routeNum).select().last()  
    300324    if (item != None): 
    301325        currID = item.closureid 
     
    328352# E.g.  #1 #3 of 4 
    329353# Note: ckBoxGroup parameter contains only checked items 
    330 def buildLanesClosedString(ckBoxGroup): 
    331     result = ">" 
     354def buildLanesClosedString(ckBoxGroup,lanecount): 
     355    result = "" 
    332356    if ckBoxGroup is not None: 
    333357        # Append each checked value to a string 
    334358        for item in ckBoxGroup: 
    335             result = result + item + " " 
     359            result = result + "#"+item + " " 
     360        result = result + "of " + lanecount 
    336361    return result 
Note: See TracChangeset for help on using the changeset viewer.