I've been working loosely with web2py for a couple of years.  Love it, love 
python.

I recently bought the book Web2py Application Development Cookbook and 
started working with the wizard recipe.  It seems fairly simple and easy to 
understand.

I ran the project and getting an error that I can't figure out and looking 
for someone with outside eyes to help me figure this one out.  I checked 
the book errata and nothing.

Seems like the wizard page runs the way it's supposed to but the last page 
fails out (when it's supposed to be 'done'.

My controller code:
























*# -*- coding: utf-8 -*-# try something likedef wizard():    # 
Field('ruleNumber','integer'),    #           
Field('ruleStatement','string'),    #           
Field('ruleParms','string'),    STEPS = {0: 
('srcFile','ruleParms2'),             1: ('ruleStatement', 
'ruleParms'),             2: URL('done')}    step = int(request.args(0) or 
0)    if not step in STEPS: redirect(URL(args=0))    fields = 
STEPS[step]    if step == 0:        session.wizard = {}    if 
isinstance(fields, tuple):        form = SQLFORM.factory(*[f for f in 
db.columnSourceToDestMapDetail if f.name in fields])    if 
form.accepts(request, session):        
session.wizard.update(form.vars)        redirect(URL(args=step+1))    
else:        db.columnSourceToDestMapDetail.insert(**session.wizard)        
session.flash = T('wizard completed')        #redirect(fields)    return 
dict(form=form, step=step)*

my view (wizard.html): 

{{extend 'layout.html'}}
<h1>Wizard Step {{=step}}</h1>
{{=form}}

my view (done.html):

{{extend 'layout.html'}}
<h1>This is the done.html template</h1>
{{=BEAUTIFY(response._vars)}}

my model: 

tableName = 'columnSourceToDestMapDetail'
db.define_table(tableName,
               Field('srcFile','string'),
               Field('ruleNumber','integer'),
               Field('ruleStatement','string'),
               Field('ruleParms','string'),
               Field('ruleParms2','string')
               )

Finally, my error:  (sorry so long):

Error ticket for "NG_MappingConversion" Ticket ID 

127.0.0.1.2016-01-26.08-43-19.f513d99f-1f18-4317-9c38-7fd9dd2b709d
<type 'exceptions.UnboundLocalError'> local variable 'form' referenced 
before assignment Version 
web2py™ Version 2.12.3-stable+timestamp.2015.08.19.00.18.03 
Python Python 2.7.8: C:\Python27\python.exe (prefix: C:\Python27) Traceback 

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.

Traceback (most recent call last):
  File "C:\Users\benninsc\Documents\web2py\gluon\restricted.py", line 227, in 
restricted
    exec ccode in environment
  File 
"C:/Users/benninsc/Documents/web2py/applications/NG_MappingConversion/controllers/wizard.py"
 
<http://127.0.0.1:8000/admin/default/edit/NG_MappingConversion/controllers/wizard.py>,
 line 26, in <module>
  File "C:\Users\benninsc\Documents\web2py\gluon\globals.py", line 412, in 
<lambda>
    self._caller = lambda f: f()
  File 
"C:/Users/benninsc/Documents/web2py/applications/NG_MappingConversion/controllers/wizard.py"
 
<http://127.0.0.1:8000/admin/default/edit/NG_MappingConversion/controllers/wizard.py>,
 line 17, in wizard
    if form.accepts(request, session):
UnboundLocalError: local variable 'form' referenced before assignment

Error snapshot [image: help] 
<http://127.0.0.1:8000/admin/default/ticket/NG_MappingConversion/127.0.0.1.2016-01-26.08-43-19.f513d99f-1f18-4317-9c38-7fd9dd2b709d#>
 

<type 'exceptions.UnboundLocalError'>(local variable 'form' referenced 
before assignment) 

inspect attributes 
Frames 
   
   - 
   
   *File C:\Users\benninsc\Documents\web2py\gluon\restricted.py in 
   restricted at line 227* code arguments variables 
   - 
   
   *File 
   
C:\Users\benninsc\Documents\web2py\applications\NG_MappingConversion\controllers\wizard.py
 
   in <module> at line 26* code arguments variables 
   - 
   
   *File C:\Users\benninsc\Documents\web2py\gluon\globals.py in <lambda> at 
   line 412* code arguments variables 
   - 
   
   *File 
   
C:\Users\benninsc\Documents\web2py\applications\NG_MappingConversion\controllers\wizard.py
 
   in wizard at line 17* code arguments variables 
   Function argument list 
   
   ()
   Code listing 
   
   12.
   13.
   14.
   15.
   16.
   17.
   
   18.
   19.
   20.
   21.
   
       fields = STEPS[step]
       if step == 0:
           session.wizard = {}
       if isinstance(fields, tuple):
           form = SQLFORM.factory(*[f for f in db.columnSourceToDestMapDetail 
if f.name in fields])
       if form.accepts(request, session):
   
           session.wizard.update(form.vars)
           redirect(URL(args=step+1))
       else:
           db.columnSourceToDestMapDetail.insert(**session.wizard)
   
   Variables 
   global request <Storage {'_vars': None, 'function': 'wizard', 
   '...\\web2py\\applications\\NG_MappingConversion\\'}> 
   global session <Storage {'flash': None, 'wizard': 
   {'ruleStateme...357ec', 'ee50f7e5-3ac4-4bd3-946a-68e743cb8fde']}> 
   form undefined 
   
Context 

locals request session response 
In file: 
C:\Users\benninsc\Documents\web2py\applications\NG_MappingConversion\controllers/wizard.py
 

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.

# -*- coding: utf-8 -*-
# try something like
def wizard():
    # Field('ruleNumber','integer'),
    #           Field('ruleStatement','string'),
    #           Field('ruleParms','string'),
    STEPS = {0: ('srcFile','ruleParms2'),
             1: ('ruleStatement', 'ruleParms'),
             2: URL <http://127.0.0.1:8000/examples/global/vars/URL>('done')}
    step = int(request 
<http://127.0.0.1:8000/examples/global/vars/request>.args(0) or 0)
    if not step in STEPS: redirect 
<http://127.0.0.1:8000/examples/global/vars/redirect>(URL 
<http://127.0.0.1:8000/examples/global/vars/URL>(args=0))
    fields = STEPS[step]
    if step == 0:
        session <http://127.0.0.1:8000/examples/global/vars/session>.wizard = {}
    if isinstance(fields, tuple):
        form = SQLFORM 
<http://127.0.0.1:8000/examples/global/vars/SQLFORM>.factory(*[f for f in 
db.columnSourceToDestMapDetail if f.name in fields])
    if form.accepts(request 
<http://127.0.0.1:8000/examples/global/vars/request>, session 
<http://127.0.0.1:8000/examples/global/vars/session>):
        session 
<http://127.0.0.1:8000/examples/global/vars/session>.wizard.update(form.vars)
        redirect <http://127.0.0.1:8000/examples/global/vars/redirect>(URL 
<http://127.0.0.1:8000/examples/global/vars/URL>(args=step+1))
    else:
        db.columnSourceToDestMapDetail.insert(**session 
<http://127.0.0.1:8000/examples/global/vars/session>.wizard)
        session <http://127.0.0.1:8000/examples/global/vars/session>.flash = T 
<http://127.0.0.1:8000/examples/global/vars/T>('wizard completed')
        #redirect(fields)
    return dict(form=form, step=step)

response <http://127.0.0.1:8000/examples/global/vars/response>._vars=response 
<http://127.0.0.1:8000/examples/global/vars/response>._caller(wizard)


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to