Changeset 612 in tmcsimulator for branches


Ignore:
Timestamp:
04/02/2020 09:36:50 AM (6 years ago)
Author:
jdalbey
Message:

LCS Add special validation check to Search form (for lognum validation)

Location:
branches/LCSv1/controllers
Files:
2 edited

Legend:

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

    r610 r612  
    4343                INPUT(_name='enddate',_class='date'),BR(), 
    4444                INPUT(_value="Search", _type='submit', _class="btn btn-primary btn-default", _style="margin:  7% 45% 2% 40%;")) 
    45     if form.process().accepted: 
     45    if form.process(onvalidation=special_validation).accepted: 
    4646        # Put the form fields into the session variables 
    4747        session.closureid = form.vars.closureid 
     
    5353        redirect(URL('results')) 
    5454    return dict(form=form) 
     55# Search Form: Special validation check to reject lognum without closureID 
     56def special_validation(form): 
     57    # Error if a lognum was given and no closure id 
     58    if (len(form.vars.lognum) > 0 and len(form.vars.closureid) == 0): 
     59       form.errors.lognum = 'Must provide a closureID when specifying a log number' 
    5560# Show the item that was found in the search 
    5661def results(): 
  • branches/LCSv1/controllers/default.py.bak

    r593 r612  
     1# added comments for testing 
    12# Constants 
    23hwys = ['','1','5', '22', '55', '57', '73', '74', '91', '133', '142', '241', '261', '405', '605'] 
     
    45# Show the login page 
    56def index(): 
    6     form = FORM(LABEL('Username:',_for='username', _class="label"), 
    7                 INPUT(_name='username',_size='10'),BR(), 
    8                 INPUT(_type='submit', _class="submit-button btn btn-primary")) 
     7    form = FORM(LABEL('Username:',_for='username', _class="label username-label"), 
     8                INPUT(_name='username', _size='15', _style="font-size: 18px;"), BR(), 
     9                INPUT(_type='submit',_value="Log in", _class=" btn btn-primary", _style="margin-top: 3%;")) 
    910    if form.process().accepted: 
    1011        # Put the username entry into the session variable 
     
    2829# Display a search form 
    2930def search(): 
    30     form = FORM(LABEL('ClosureID/Log:',_for='closureid', _class="label"), INPUT(_name='closureid',_size='7'),INPUT(_name='lognum',_size='3'),XML('   '), LABEL('Route: ',_for='route', _class="label"), SELECT(hwys,_name='route'), XML('   '), LABEL('Direction: ',_for='direction', _class="label"), SELECT(hwyDirections,_name='direction'), BR(),BR(),LABEL('Dates:',_for='startdate', _class="label") ,INPUT(_name='startdate',_class='date'), XML('   '), LABEL('  to:',_for='enddate', _class="label"), INPUT(_name='enddate'),'(MMDDYYYY)',BR(),BR(),INPUT(_type='submit', _class="submit-button btn btn-primary")) 
    31     if form.process().accepted: 
     31    form = FORM(LABEL('ClosureID/Log:',_for='closureid', _class="label"),  
     32                INPUT(_name='closureid',_size='7', _style="margin-right: 5px;"), 
     33                INPUT(_name='lognum',_size='3'), 
     34                XML('   '),  
     35                LABEL('Route: ',_for='route', _class="label"),  
     36                SELECT(hwys,_name='route'), XML('   '),  
     37                LABEL('Direction: ',_for='direction', _class="label"), 
     38                SELECT(hwyDirections,_name='direction'), BR(),BR(),  
     39                LABEL('Dates:',_for='startdate', _class="label"),  
     40                INPUT(_name='startdate',_class='date'),  
     41                XML('   '),  
     42                LABEL('  to:',_for='enddate', _class="label"),  
     43                INPUT(_name='enddate',_class='date'),BR(), 
     44                INPUT(_value="Search", _type='submit', _class="btn btn-primary btn-default", _style="margin:  7% 45% 2% 40%;")) 
     45    if form.process(onvalidation=special_validation).accepted: 
    3246        # Put the form fields into the session variables 
    3347        session.closureid = form.vars.closureid 
     
    3953        redirect(URL('results')) 
    4054    return dict(form=form) 
     55# Search Form: Special validation check to reject lognum without closureID 
     56def special_validation(form): 
     57    # Error if a lognum was given and no closure id 
     58    if (len(form.vars.lognum) > 0 and len(form.vars.closureid = 0)): 
     59       form.errors.lognum = 'Must provide a closureID when specifying a log number' 
    4160# Show the item that was found in the search 
    4261def results(): 
     62    # query object is equivalent to the where clause in query  
     63    query = True 
     64    msg = "" 
    4365    if (len(session.closureid) != 0): 
    44         hwy = db(db.closures.closureid == session.closureid).select()  
    45         msg = "Closure ID = " + session.closureid 
    46     elif (len(session.route) != 0): 
    47         hwy = db(db.closures.route == session.route).select()  
    48         msg = "route = " + session.route 
    49     elif (len(session.startdate) == 10): 
    50         hwy = db(db.closures.startdate >= session.startdate).select() 
    51         msg = "Start Date >= " + session.startdate 
    52     else: 
     66        query = (db.closures.closureid == session.closureid) 
     67        msg += " Closure ID = " + session.closureid     
     68    if (len(session.lognum) != 0): 
     69        query = query & (db.closures.lognum == session.lognum) 
     70        msg += " Log number = " + session.lognum     
     71    if (len(session.route) != 0): 
     72        query = query & (db.closures.route == session.route) 
     73        msg += " Route = " + session.route 
     74    if (len(session.direction) != 0): 
     75        query = query & (db.closures.direction == session.direction) 
     76        msg += " Route = " + session.route 
     77    if (len(session.startdate) != 0): 
     78        query = query & (db.closures.startdate >= session.startdate) 
     79        msg += "Start date = " + session.startdate 
     80    if (len(session.enddate) != 0): 
     81        query = query & (db.closures.startdate <= session.enddate) 
     82        msg += "End date = " + session.enddate 
     83     
     84    # if no restrictions entered then get all entries  
     85    if query == True : 
    5386        hwy = db().select(db.closures.ALL) 
    5487        msg = "ALL" 
     88    else: 
     89        # get entries with the matching requirements 
     90        hwy = db(query).select() 
     91 
    5592    count = len(hwy) 
    5693    # Show the results in table format.  Get the radio call number from supervisor name lookup 
    5794    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.'))) 
    5895    multiform = [] 
     96    # Iterates over all search results 
    5997    for row in hwy: 
    6098        statusfields = row.closureid +','+ row.lognum + ',1097,' + str(row.s1097user) +','+ str(row.startdate) + ',' + formatTime(row.starttime) +','+str(row.s1097date)+','+ formatTime(row.s1097time) + ',1098,' + str(row.s1098user) +','+ str(row.s1098date)+','+ formatTime(row.s1098time)+ ',1022,' + str(row.s1022user) +','+ str(row.s1022date)+','+ formatTime(row.s1022time) 
    6199        # Each row contains a form with two buttons and columns with fields from database 
    62100        multiform.append(TR(TD( 
    63                     XML("<button onclick=showPopup(\'"),statusfields,XML("\')>View History</button>"),BR(), 
     101                    XML("<button class='submit-button' onclick=showPopup(\'"),statusfields,XML("\')>View History</button>"),BR(), 
    64102                    FORM( 
    65                           INPUT(_type='submit',_name='btn2',_value='Show Status Form'), 
     103                          INPUT(_type='submit',_name='btn2',_value='Show Status Form',_class="submit-button" ), 
    66104                          INPUT(_type='hidden',_name='row',_value=row.closureid))), 
    67105                          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) ))  
     
    70108    if request.vars.btn2: 
    71109        redirect(URL('statuslist')) 
    72  
    73110    return dict(msg=msg, count=count, highways=hwy, table=header, multiform=multiform) 
    74111 
     
    87124 
    88125        form = FORM(BR(),  
    89                 TABLE(THEAD(TR(TH('Closure ID/',BR(),'Log No.'),TH('Route & Dir',BR(),'Type of Closure'),TH('Start Date/',BR(),'End Date/',BR(),'Est. Delay'),TH('Requestor/',BR(),'Radio Call No.'),TH('Status'))), 
     126                TABLE(THEAD(TR(TH('Closure ID/',BR(),'Log No.'), TH('Route & Dir',BR(),'Type of Closure'),TH('Start Date/',BR(),'End Date/',BR(),'Est. Delay'),TH('Requestor/',BR(),'Radio Call No.'),TH('Status'))), 
    90127                    [TR(TD(row.closureid,HR(),row.lognum),TD(row.route,' ',row.direction,HR(),row.closuretype),TD(row.startdate,HR(),row.enddate,HR(),row.estdelay),TD(row.supervisor,BR(),db(db.supervisors.name == row.supervisor).select().first().radiocallnum),TD(LABEL('1097'), INPUT(_type='checkbox', _name='statustype', _value='1097'+row.closureid),LABEL('1098'), INPUT(_type='checkbox', _name='statustype', _value='1098'+row.closureid),LABEL('1022'), INPUT(_type='checkbox', _name='statustype', _value='1022'+row.closureid),BR(), LABEL('Statuser:'),INPUT(_name='statuser',_size='9'))) for row in closedItems], 
    91                     _border='1', _cellpadding='5'),INPUT(_type='submit',_value="submit status form"),) 
     128                    _border='1', _cellpadding='5'),INPUT(_type='submit',_value="submit status form",_class="submit-button"),) 
    92129         
    93130    else: 
     
    125162    return dict(msg=msg) 
    126163# Utility functions for formatting 
    127 def formatDate(msg): 
    128     if (msg): 
    129         return msg[4:6]+"/"+msg[6:8]+"/"+msg[0:4] 
    130     else: 
    131         return "" 
    132164def formatTime(msg): 
    133165    if (msg): 
     
    157189           LABEL('*Direction',_for='direction'), SELECT(hwyDirections,_name='direction', requires=IS_LENGTH(minsize=1,error_message='direction cannot be empty')), XML('&nbsp;&nbsp;&nbsp;'),  
    158190           LABEL('*Facility',_for='facility'), SELECT(facilities,_name='facility', requires=IS_LENGTH(minsize=1,error_message='facility cannot be empty')), BR(),BR(),  
    159            TABLE(TR(TD(),TD('*County'),TD('*Location')),TR(TD('BEGIN='),TD(SELECT('ORA',_name='startcounty')),TD(SELECT(streets,_name='startlocation',_id='startlocation')), 
    160            TR(TD('END='),TD(SELECT('ORA',_name='endcounty')),TD(SELECT(streets,_name='endlocation',_id='endlocation'))))),BR(), 
    161            'Date Range:',BR(), 
     191           TABLE(TR(TD(),TD(LABEL('*County')),TD(LABEL('*Location'))), 
     192                TR(TD(LABEL('BEGIN=')),TD(SELECT('ORA',_name='startcounty')), 
     193                TD(SELECT(streets,_name='startlocation',_id='startlocation')), 
     194           TR(TD(LABEL('END=')),TD(SELECT('ORA',_name='endcounty')),TD(SELECT(streets,_name='endlocation',_id='endlocation'))))),BR(), 
     195           LABEL('Date Range:'),BR(), 
    162196           LABEL('From',_for='startdate'),INPUT(_name='startdate',_size='8',_class='date'), XML('&nbsp;&nbsp;&nbsp;'),  
    163            LABEL('to:',_for='enddate'), INPUT(_name='enddate',_size='8',_class='date'),'(MMDDYYYY)',XML('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'),  
     197           LABEL('to:',_for='enddate'), INPUT(_name='enddate',_size='8',_class='date'),XML('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'),  
    164198           LABEL('Times',_for='starttime'),SELECT(hournames,_name='starttime'),  
    165199           LABEL(':',_for='starttimemin'),SELECT('','00','15','30','45','59',_name='starttimemin'), XML('&nbsp;&nbsp;'),  
    166200           LABEL('to:',_for='endtime'),SELECT(hournames,_name='endtime'),  
    167201           LABEL(':',_for='endtimemin'),SELECT('','00','15','30','45','59',_name='endtimemin'), BR(),BR(),  
    168            TABLE(TR(TD('*Type of Closure'),TD('*Type of Work'),TD('Estimated Delay'),TD('TMP Details')),  
     202           TABLE(TR(TD(LABEL('*Type of Closure') ), 
     203                    TD(LABEL('*Type of Work')), 
     204                    TD(LABEL('Estimated Delay')), 
     205                    TD(LABEL('TMP Details'))),  
    169206                 TR(TD(SELECT(closuretypes,_name='closuretype',requires=IS_LENGTH(minsize=1,error_message='type of closure cannot be empty'))),  
    170207                    TD(SELECT(worktypes,_name='worktype', requires=IS_LENGTH(minsize=1,error_message='type of work cannot be empty'))),  
     
    173210                       INPUT(_type='checkbox', _name='detour'),'Detour Available')),  
    174211                 _width='100%' ), 
    175     TABLE(TR(TD('*Supervisor'),TD('Field Rep')),  
     212    TABLE(TR(TD(LABEL('*Supervisor')), 
     213            TD(LABEL('Field Rep'))),  
    176214                  TR(TD(SELECT(supervisors,_name='supervisor', requires=IS_LENGTH(minsize=1,error_message='supervisor cannot be empty'))), 
    177215                     TD(SELECT(supervisors,_name='fieldrep')))), 
    178     TABLE(TR(TD('Meeting Place/CHP Contact'),TD('Reason for Closure'),TD('Additional Remarks / Detour ')),  
    179                   TR(TD(INPUT(_name='meeting')),TD(INPUT(_name='reason')),TD(INPUT(_name='remarks',_size='40'))) ), BR(),  
    180             INPUT(_type='submit',_value='Submit Closure'),XML('\n'),SELECT(streetlookup,_name='stlookup', _id='stlookup', _class='hideme'))  
     216    TABLE(TR(TD( LABEL('Meeting Place/CHP Contact')), 
     217            TD(LABEL('Reason for Closure')), 
     218            TD(LABEL('Additional Remarks / Detour '))),  
     219                  TR(TD(INPUT(_name='meeting', _size='25')),TD(INPUT(_name='reason',_size='25')),TD(INPUT(_name='remarks',_size='25'))) ), BR(),  
     220            INPUT(_type='submit',_value='Submit Closure', _class="btn btn-primary btn-default", _style="margin:  2% 45% 2% 40%;"), 
     221            XML('\n'),SELECT(streetlookup,_name='stlookup', _id='stlookup', _class='hideme'))  
     222 
    181223    if form.process().accepted: 
    182224        newID = calcNextClosure(form.vars.route) 
Note: See TracChangeset for help on using the changeset viewer.