Changeset 621 in tmcsimulator for branches/LCSv2/controllers/default.py.bak
- Timestamp:
- 08/19/2020 08:18:24 AM (6 years ago)
- File:
-
- 1 edited
-
branches/LCSv2/controllers/default.py.bak (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/LCSv2/controllers/default.py.bak
r620 r621 19 19 # List all the current records in the database - remove in final application 20 20 def list(): 21 highways = db().select(db.closures.ALL, orderby=db.closures. lognum)21 highways = db().select(db.closures.ALL, orderby=db.closures.closureid) 22 22 return dict(highways = highways) 23 23 # Show details of a single record - remove in final application … … 110 110 return dict(msg=msg, count=count, highways=hwy, table=header, multiform=multiform) 111 111 112 # Show the status box next to each search result112 # Show a selected closure with a status update form 113 113 def statuslist(): 114 114 closedItems = [] … … 122 122 retrieved = db(db.closures.closureid == item).select().first() 123 123 closedItems.append(retrieved) 124 124 # Build the table rows 125 tblrows = TR() 126 for row in closedItems: 127 # Construct the status radio buttons; disable if date already in database 128 statusflags = "disabled" if row.s1097date == "" else "" 129 if row.s1097date == "": 130 btn = LABEL('1097'), INPUT(_type='radio', _name='statustype', _value='1097'+row.closureid) 131 else: 132 btn = LABEL('1097 ○',_class='labelgray'), 133 btngroup = btn 134 if row.s1098date == "": 135 btn = LABEL('1098'), INPUT(_type='radio', _name='statustype', _value='1098'+row.closureid) 136 else: 137 btn = LABEL('1098 ○',_class='labelgray'), 138 btngroup += btn 139 if row.s1022date == "": 140 btn = LABEL('1022'), INPUT(_type='radio', _name='statustype', _value='1022'+row.closureid) 141 else: 142 btn = LABEL('1022 ○',_class='labelgray'), 143 btngroup += btn 144 145 if row.s1097date != "" and row.s1098date != "" and row.s1022date != "": 146 btngroup += BR(),LABEL('Statuser:', _class='labelgray') 147 else: 148 btngroup += BR(),LABEL('Statuser:'),INPUT(_name='statuser',_size='9'),BR(),BR(),INPUT(_type='submit',_value="submit status update",_class="submit-button") 149 # LABEL('1097 ○',_class='colorgray'), INPUT(_type='radio', _name='statustype', _value='1097'+row.closureid),LABEL('1098'), INPUT(_type='radio', _name='statustype', _value='1098'+row.closureid),LABEL('1022'), INPUT(_type='radio', _name='statustype', _value='1022'+row.closureid),BR(), LABEL('Statuser:'),INPUT(_name='statuser',_size='9') 150 tblrows += 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(btngroup)) 125 151 form = FORM(BR(), 126 152 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'))), 127 [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], 128 _border='1', _cellpadding='5'),INPUT(_type='submit',_value="submit status form",_class="submit-button"),) 153 tblrows, 154 155 _border='1', _cellpadding='5', _width="70%")) 129 156 130 157 else: … … 152 179 now = datetime.datetime.today() 153 180 fieldname = "s"+session.statustype[0:4]+"date" 154 db(db.closures.closureid == session.statustype[4:]).update(**{fieldname:now.strftime("%Y %m%d")})181 db(db.closures.closureid == session.statustype[4:]).update(**{fieldname:now.strftime("%Y-%m-%d")}) 155 182 fieldname = "s"+session.statustype[0:4]+"time" 156 183 db(db.closures.closureid == session.statustype[4:]).update(**{fieldname:now.strftime("%H%M")}) … … 167 194 else: 168 195 return "" 196 169 197 # Create a new record 170 198 def submit(): … … 188 216 streets.append(row.street) 189 217 streetlookup.append(row.route + ',' + row.street) 190 218 # Build the list of existing closures 219 existingclosures = [] 220 existingclosures.append("") 221 for row in db().select(db.closures.ALL, orderby=db.closures.closureid): 222 existingclosures.append(row.closureid) 223 191 224 form = FORM( 192 225 LABEL('*Route',_for='route'), SELECT(hwys,_name='route', _id='routecombo', _onchange='routechanged()', requires=IS_LENGTH(minsize=1,error_message='route cannot be empty')), XML(' '), … … 210 243 TR(TD(SELECT(closuretypes,_name='closuretype',requires=IS_LENGTH(minsize=1,error_message='type of closure cannot be empty'))), 211 244 TD(SELECT(worktypes,_name='worktype', requires=IS_LENGTH(minsize=1,error_message='type of work cannot be empty'))), 212 TD(INPUT(_name='estdelay',_size='4' ,requires=IS_INT_IN_RANGE(1, 1440)),'minutes'),245 TD(INPUT(_name='estdelay',_size='4'),'minutes'), 213 246 TD(INPUT(_type='checkbox',_name='cozeep'),'CoZeep MaZeep/CHP',BR(), 214 247 INPUT(_type='checkbox', _name='detour'),'Detour Available')), 215 248 _width='100%' ), 216 249 TABLE(TR(TD(LABEL('*Supervisor')), 217 TD(LABEL('Field Rep'))), 218 TR(TD(SELECT(supervisors,_name='supervisor', requires=IS_LENGTH(minsize=1,error_message='supervisor cannot be empty'))), 219 TD(SELECT(crew,_name='fieldrep')))), 250 TD(LABEL('Field Rep')) 251 ), 252 TR(TD(SELECT(supervisors,_name='supervisor', requires=IS_LENGTH(minsize=1,error_message='supervisor cannot be empty'))), 253 TD(SELECT(crew,_name='fieldrep')), 254 TD(XML(" ")), 255 TD('Is this an existing incident?', 256 INPUT(_type='radio',_name='existing',_value='No',_onclick='radioclicked()'), 257 'No', 258 INPUT(_type='radio',_name='existing',_value='Yes',value='Yes',_onclick='radioclicked()'), 259 'Yes' 260 ) 261 ), 262 TR(TD(),TD(),TD(), TD(' Select closure ID:',SELECT(existingclosures,_name='existingid'),_id='closureselect'))), 220 263 TABLE(TR(TD( LABEL('Meeting Place/CHP Contact')), 221 264 TD(LABEL('Reason for Closure')), … … 225 268 XML('\n'),SELECT(streetlookup,_name='stlookup', _id='stlookup', _class='hideme')) 226 269 227 if form.process().accepted: 228 newID = calcNextClosure(form.vars.route) 270 if form.process(onvalidation=validate_existing_id).accepted: 271 newLognum = calcNextLogNum(form.vars.existingid) 272 if newLognum == '1': 273 newID = calcNextClosureID(form.vars.route) 274 else: 275 newID = form.vars.existingid 276 supervisor_name = form.vars.supervisor[3:] 277 fieldrep_name = form.vars.fieldrep[5:] 229 278 # Insert the record into the database 230 newrec = db.closures.insert(closureid=newID, lognum= '1', 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=form.vars.supervisor, fieldrep=form.vars.fieldrep,)231 session.flash = 'New lane closure added: ' + newID 279 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='' ) 280 session.flash = 'New lane closure added: ' + newID + ' ' + newLognum 232 281 redirect(URL('search.html')) 233 282 return dict(form=form) 234 283 284 # Validation for existing closure button 285 # If user selected Yes (it's existing incident) then they must select a closure ID 286 def validate_existing_id(form): 287 if form.vars.existing == 'Yes' and form.vars.existingid == '': 288 form.errors.existingid = "Existing incidents require selecting an existing closure ID" 289 235 290 # Calculate the closure id to assign to the new closure 236 def calcNextClosure (routeNum):291 def calcNextClosureID(routeNum): 237 292 # Retrieve any existing closures on this route 238 293 item = db(db.closures.closureid.startswith('T'+routeNum)).select().last() # Might need to sort these … … 245 300 else: 246 301 return 'T'+routeNum+'AA' # For a non-existing route 302 303 # If existing incident closure ID is provided, increment the log number by 1 304 def calcNextLogNum(existingid): 305 if existingid != '': 306 item = db(db.closures.closureid.startswith(existingid)).select().last() 307 prevLog = int(item.lognum) 308 nextLog = prevLog + 1 309 return str(nextLog) 310 else: 311 return '1' 312 247 313 248 314 # Convert checkbox value to YES/NO
Note: See TracChangeset
for help on using the changeset viewer.
