Thanks for the reply. I tried your sugestion but am still getting an error,
though a different one:
Traceback (most recent call last):
File "/home/joel/Source/web2py/gluon/restricted.py", line 205, in restricted
exec ccode in environment
File "/home/joel/Source/web2py/applications/GeorgesTV/controllers/qrinv.py"
<http://127.0.0.1:8000/admin/default/edit/GeorgesTV/controllers/qrinv.py>, line
136, in <module>
File "/home/joel/Source/web2py/gluon/globals.py", line 173, in <lambda>
self._caller = lambda f: f()
File "/home/joel/Source/web2py/applications/GeorgesTV/controllers/qrinv.py"
<http://127.0.0.1:8000/admin/default/edit/GeorgesTV/controllers/qrinv.py>, line
131, in update_inventory
record = crud.update(db.invent, row.id )
UnboundLocalError: local variable 'row' referenced before assignment
Just to be clear the page is coming up initialy. This error only happens when I
click
on the submit button. Thanks again for your help.
Joel Robinson
On Wednesday, June 6, 2012 4:14:29 PM UTC-5, Massimo Di Pierro wrote:
>
> Looks like the error is at
>
> row = rows[0]
>
> because rows is empty (no records matching query). You need a check like
>
> if rows:
> row = rows[0]
>
>
>
> On Wednesday, 6 June 2012 12:19:14 UTC-5, Joel Robinson wrote:
>>
>> First, let me give some background on what I've been trying to do. We
>> wanted to set up an inventory system using QR codes which would be put on
>> stickers on our stock and then scaned with smartphone when removing
>> inventory bring up the appropiate web page. The QR code should contain
>> something like:
>>
>> http://GeorgesTV/qrinv/update_inventory?partnum=12345
>>
>> and the following is the code I wrote for update_inventory:
>>
>> rows = db(db.invent.partnum == request.vars.partnum).select()
>> # change rows object to row object
>> row = rows[0]
>>
>> # display queried object
>> record = crud.update(db.invent, row.id)
>> return dict(record=record)
>>
>> initialy it would work fine it would run the query and pull up the
>> correct record but
>> if I tried to update the record I would get the folling error:
>>
>>
>> Traceback (most recent call last):
>> File "/home/joel/Source/web2py/gluon/restricted.py", line 205, in
>> restricted
>> exec ccode in environment
>> File
>> "/home/joel/Source/web2py/applications/GeorgesTV/controllers/qrinv.py"
>> <http://127.0.0.1:8000/admin/default/edit/GeorgesTV/controllers/qrinv.py>,
>> line 123, in <module>
>> File "/home/joel/Source/web2py/gluon/globals.py", line 173, in <lambda>
>> self._caller = lambda f: f()
>> File
>> "/home/joel/Source/web2py/applications/GeorgesTV/controllers/qrinv.py"
>> <http://127.0.0.1:8000/admin/default/edit/GeorgesTV/controllers/qrinv.py>,
>> line 116, in update_inventory
>> row = rows[0]
>> File "/home/joel/Source/web2py/gluon/dal.py", line 7755, in __getitem__
>> row = self.records[i]
>> IndexError: list index out of range
>>
>> I thought maybe the request variable wasn't getting passed correctly when
>> updated so I made the following change:
>>
>> session.partnum = request.vars.partnum
>> rows = db(db.invent.partnum == session.partnum).select()
>>
>> which didn't help either, but I then noticed that if I tried to pull up the
>> update_inventory page now without the query string
>> it would come up since session varible was already set and it would update
>> correctly!
>>
>> I was eventualy able to get it work more or less how I wanted by writing a
>> page whose only function was to take the
>> query string set a session variable and then redirect you to the
>> update_inventory page. But I worry that using session varibles
>> may cause unforseen problems eventualy.
>>
>> So what I would like to know, is this a bug I've found or am I going about
>> doing this incorrectly? Could someone explains
>> what happens when you use crud.update and why I get this error when I try to
>> use query strings?
>>
>> Thanks in advance for your help.
>>
>> Joel Robinson
>>
>>