I have records that I want users to be able to update simultaneously
on the same webpage. I currently have a system that works by using
standard HTML forms to submit the values through the URL and in my
controller, I manually update the records by parsing out request.vars.
This works nicely, however, if I want to go "back" on my browser,
after making changes more than once (which is something I can imagine
a user doing), it will reset the records to older values because the
URL goes back to what it was. Does anyone know a way to "safeguard"
against this? I tried removing the request.vars entries after parsing
out its content in the controller in the hopes that the URL would
remain the same, but this doesn't work. My code is below:
Default Controller:
def lists():
thisTargetList =
db(db.targetList.title==request.args(0).replace('_', ' ')).select()[0]
if not thisTargetList:
redirect(URL(r=request, f='index'))
thisTargetListTargets =
db(db.target.targetList_id==thisTargetList.title).select(db.target.ALL,
orderby=db.target.pctObs)
ptySortedTargets =
db((db.target.targetList_id==thisTargetList.title) &
(db.target.priority > 0)).select(db.target.ALL,
orderby=db.target.priority)
thisTargetListCount =
db(db.target.targetList_id==thisTargetList.title).count()
thisP1Count = db((db.target.targetList_id==thisTargetList.title) &
(db.target.priority==1)).count()
thisP2Count = db((db.target.targetList_id==thisTargetList.title) &
(db.target.priority==2)).count()
thisP3Count = db((db.target.targetList_id==thisTargetList.title) &
(db.target.priority==3)).count()
if request.vars.pty_update:
for targ in thisTargetListTargets:
if request.vars.has_key('id%i_pty' % targ.id):
targ.update_record(priority=request.vars['id%i_pty'%
targ.id])
thisP1Count =
db((db.target.targetList_id==thisTargetList.title) &
(db.target.priority==1)).count()
thisP2Count =
db((db.target.targetList_id==thisTargetList.title) &
(db.target.priority==2)).count()
thisP3Count =
db((db.target.targetList_id==thisTargetList.title) &
(db.target.priority==3)).count()
ptySortedTargets =
db((db.target.targetList_id==thisTargetList.title) &
(db.target.priority > 0)).select(db.target.ALL,
orderby=db.target.priority)
thisTargetListTargets =
db(db.target.targetList_id==thisTargetList.title).select(db.target.ALL,
orderby=db.target.pctObs)
response.flash='Priorities Changed Successfully!'
return dict(targetList=thisTargetList,
targets=thisTargetListTargets, targetCount=thisTargetListCount,
p1Count=thisP1Count, p2Count=thisP2Count, p3Count=thisP3Count,
ptyTargets=ptySortedTargets)
View:
{{extend 'layout.html'}}
<p><font size="6">{{=targetList.title}}</font></p>
[{{=A('Edit this target list', _href=URL(r=request,
f='EditTargetList', args=request.args))}}
| {{=A('Add a new target to this list', _href=URL(r=request,
f='AddNewTarget', args=request.args))}}]<br />
<p>There is a total of {{=targetCount}} targets in this list.</p>
<p>Priority 1: {{=p1Count}}</p>
<p>Priority 2: {{=p2Count}}</p>
<p>Priority 3: {{=p3Count}}</p><br />
<form>
<input type='hidden' name='pty_update' value="true" />
<table>
<thead class="menuBackG">
<tr>
<th>Priority</th>
<th>New Priority</th>
<th>PCT</th>
<th>Name</th>
<th>Last Obs</th>
<th>Status</th>
<th>RA</th>
<th>Dec</th>
<th>Vmag</th>
<th>[Fe/H]</th>
<th>M*</th>
<th>B-V</th>
<th>Vrot</th>
<th>Num Obs</th>
<th>Template</th>
<th>Comments</th>
</tr>
</thead>
{{
for targ in targets:
<tr>
<td>{{=targ.priority}}</td>
<td>
{{if targ.priority == 0:}}
<select name="id{{=targ.id}}_pty">
<option selected="selected">0</option>
<option>1</option>
<option>2</option>
<option>3</option>
</select>
{{elif targ.priority == 1:}}
<select name="id{{=targ.id}}_pty">
<option>0</option>
<option selected="selected">1</option>
<option>2</option>
<option>3</option>
</select>
{{elif targ.priority == 2:}}
<select name="id{{=targ.id}}_pty">
<option>0</option>
<option>1</option>
<option selected="selected">2</option>
<option>3</option>
</select>
{{elif targ.priority == 3:}}
<select name="id{{=targ.id}}_pty">
<option>0</option>
<option>1</option>
<option>2</option>
<option selected="selected">3</option>
</select>
{{pass}}
</td>
<td>{{=targ.pctObs}}</td>
<td><a
href="{{=URL(r=request,f='targets',args=targ.name)}}">{{=targ.name}}</
a></td>
<td>{{=targ.lastObs}}</td>
<td class="LaL">{{=targ.status}}</td>
<td>{{=targ.ra}}</td>
<td>{{=targ.dec}}</td>
<td>{{=targ.Vmag}}</td>
<td>{{=targ.FeH}}</td>
<td>{{=targ.MStar}}</td>
<td>{{=targ.BdashV}}</td>
<td>{{=targ.Vrot}}</td>
<td>{{=targ.numObs}}</td>
<td>{{=targ.tmplt}}</td>
<td class="LaL">{{=targ.comment}}</td>
</tr>
{pass}}
</table>
<button type="submit" class="menuBackG"><font size="2"><b>Update
Priorities</b></font></button><br /><br />
Any ideas would be appreciated. Thanks!