[web2py] Re: variables available in view

2016-02-20 Thread Pierre
sorry that was a trivial question:

it's written in the book :

http://web2py.com/books/default/search/29?search=response._vars

globals() works too but not very 'orthodox'   :) 

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: variables available in view

2016-02-19 Thread Dave S


On Friday, February 19, 2016 at 10:13:31 AM UTC-8, Pierre wrote:
>
> hi everyone,
>
> I have a controller/function with different return cases:
> like :
>
> if condition1:
> return dict(var1=var1)
> elif condition2:
> return dict(var1=var1,var2=var2)
> .
>
> how do I know in the corresponding view which variables are accessible 
> (what's the case) ? do I have to return a case variable ?
>


Something like

{{ =var1 }}
{{ if 'var2' in globals():}} 
  {{ =var2 }}
{{ pass }}




/dps

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: variables outside any function

2015-04-16 Thread Annet
Hi Anthony,

Thanks for your reply and explanation.

I put the paramters in the response object, problem solved.


Kind regards,

Annet

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: variables outside any function

2015-04-15 Thread Anthony
The views are executed in an environment that includes anything defined in 
models as well as whatever items are passed in the dictionary from the 
controller function. Other objects defined in the controller are not 
available in the view environment. So, you must pass items directly from 
the controller functions. You could put all the parameters in a single 
dictionary or Storage object and pass that one object from each function, 
or you could consider putting the parameters in the response object. 
Another option might be to have your functions return 
response.render(globals()).

Anthony

On Wednesday, April 15, 2015 at 7:35:00 AM UTC-4, Annet wrote:

 In a controller I got functions that use the same variables.
 I want to assign a value to them outside any function:


 if request.args(0) == 'openinghours':
   rdrctUrl = URL('opening_hours')
 function_header = 'Opening hours'
 function_icon = 'fa-clock-o'
 table = db.cal_opening_hours
 elif request.args(0) == 'eventlist':
 rdrctUrl = URL('event_list')
 function_header = 'Event list'
 function_icon = 'fa-calendar-o'
 table = db.cal_event_list

 def insert():
 
 return locals()

 def update():
 
 return locals()

 def opening_hours():
 
 return locals()

 etc.


 The variables rdrctUrl en table are available in the functions, however, 
 function_header 
 and function_icon which I need in views are not available in the views. 
 Where do I store
 them to make them available in the views.

 Kind regards,

 Annet


-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Variables from url

2014-01-25 Thread Lucas Schreiber
Thanks :)
It is exactly what i needed :)

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[web2py] Re: Variables from url

2014-01-24 Thread Alan Etkin


 Hi,
 I have a question:

 For example, somebody opens this page:
 .../profile/1

 Now, in the def profile(): there shall be a variable:

 a=1

 Or, when this page gets opened:
 .../profile/12345

 I wish this variable:
 a=12345

This is discussed in detail in the web2py book:

http://www.web2py.com/books/default/chapter/29/04/the-core#Dispatching

Just an example:

if the url has this form

base address/app/controller/action/value 0/value 1/.../value n

Your action logic (i.e. a function defined at the controller file) could 
retrieve it this way:

value_1 = request.args(0)
...
value_n = request.args(n)


-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[web2py] Re: variables to determine table columns from database

2012-08-07 Thread Anthony
rows = db(db[request.args(0)][request.args(2)] == request.args(1)).select
(

Anthony

On Tuesday, August 7, 2012 2:15:09 PM UTC-4, Larry Wapnitsky wrote:

 from a web page, i'm able to successfully query my database using the 
 following:

 rows = db(db[request.args(0)].id == request.args(1)).select(


 What I'm having trouble with is passing another argument that specifies 
 another column other than id.  I've tried the following with no success:

 rows = db(db[request.args(0)].[request.args(2)] == request.args(1)).select
 (


 rows = db(db[request.args(0)].request.args(2) == request.args(1)).select
 (



-- 





[web2py] Re: variables to determine table columns from database

2012-08-07 Thread Larry Wapnitsky
damned periods! :)  Thanks, Anthony

On Tuesday, August 7, 2012 2:49:53 PM UTC-4, Anthony wrote:

 rows = db(db[request.args(0)][request.args(2)] == request.args(1)).select
 (

 Anthony

 On Tuesday, August 7, 2012 2:15:09 PM UTC-4, Larry Wapnitsky wrote:

 from a web page, i'm able to successfully query my database using the 
 following:

 rows = db(db[request.args(0)].id == request.args(1)).select(


 What I'm having trouble with is passing another argument that specifies 
 another column other than id.  I've tried the following with no success:

 rows = db(db[request.args(0)].[request.args(2)] == request.args(1)).
 select(


 rows = db(db[request.args(0)].request.args(2) == request.args(1)).select
 (



-- 





[web2py] Re: Variables in javascript function.

2011-04-22 Thread annet
Hi Ron,

Thanks for your reply, problem solved.


Kind regards,

Annet.


[web2py] Re: Variables in javascript function.

2011-04-22 Thread ron_m
Try changing

name=window.open(url,name,'toolbar=yes,location=yes,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=width,height=height');
 


to have the variables width and height not inside the string literal quotes, 
something like this

name=window.open(url,name,'toolbar=yes,location=yes,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width='+width+',height='+height);
 




[web2py] Re: Variables in queries

2011-02-22 Thread mart
Apologies if a repeat post (my mac is in the shop and working with
this ... laptop... and nothing about it seems to work :(

Anyways, my attempt at replying was something like, using dots after
brackets should be fine, i do things like this and have no problems:

'''--- select from tables ---'''
def select(self,tbl,var):
db= self.db
for mTbl in db.tables:
if tbl in mTbl:
if mTbl.startswith(tbl):
for row in db(db[mTbl].name==var).select():
if row.name == var:
return row.value


The idea is make sure you mean var for object table and not variable
for the name for object table when talking to db about an un-named
table (alright, probably my wost sentence in English ever, but the
examples says it better ;)

Mart :)

On Feb 22, 11:37 am, Richard Vézina ml.richard.vez...@gmail.com
wrote:
 No, it works...

 I do not know if it should be like this and if it will be always the case...

 Richard

 On Tue, Feb 22, 2011 at 10:48 AM, Ross Peoples ross.peop...@gmail.comwrote:







  something like this should work:

  my_object = db(db[table_name]['id']==my_id).select().first()

  If you use brackets instead of dot notation for table names, you may not be
  able to use dot notation for the field name. I don't know for sure, but
  instead of doing this:

  db[key].id

  Try this instead:

  db[key]['id']

  I'm new to all of this, so I hope this helps.


[web2py] Re: Variables in queries

2011-02-22 Thread mart
i think it should be ok to use dots after a var in brackets For
example, I can do this, and all is fine:

def select(self,tbl,var):
db= self.db
for mTbl in db.tables:
if tbl in mTbl:
if mTbl.startswith(tbl):
for row in db(db[mTbl].name==var).select():
if row.name == var:
return row.value

Mart :)

On Feb 22, 10:48 am, Ross Peoples ross.peop...@gmail.com wrote:
 something like this should work:

 my_object = db(db[table_name]['id']==my_id).select().first()

 If you use brackets instead of dot notation for table names, you may not be
 able to use dot notation for the field name. I don't know for sure, but
 instead of doing this:

 db[key].id

 Try this instead:

 db[key]['id']

 I'm new to all of this, so I hope this helps.


[web2py] Re: Variables in queries

2011-02-22 Thread LightOfMooN
Thx!

On 22 фев, 01:34, Bruno Rocha rochacbr...@gmail.com wrote:
 Yes, this is used in crud and appadmin

 db['tablename']['fieldname']

 
 keys = ['table1','table2','table3']
 mydict = {}
 for key in keys:
    mydict[key] = db(*db[key]['id']*=='some_id').select()
 

 --
 Bruno Rocha
 [ About me:http://zerp.ly/rochacbruno]

 2011/2/21 LightOfMooN vladsale...@yandex.ru







  Is there a way to use variables in queries as table names?
  For example, something like this:

  keys = ['table1','table2','table3']
  mydict = {}
  for key in keys:
     mydict[key] = db(db.KEY.id=='some_id').select()

  where key is a name of table.


[web2py] Re: variables

2010-12-18 Thread Rick
Perhaps there is a way to get different variable values depending on
what address you load??? For example:
http:...default/index.html...something...n=1,m=0

On Dec 18, 4:07 am, Luther Goh Lu Feng elf...@yahoo.com wrote:
 You can use javascript or jquery(since web2py includes jquery) to do
 this:

 ==javascript==
 $('#some_id).click(function()
   {
      $('#target).val( ($('#target).val()+1) );
   }
 )

 ==html==
 span id=some_ida href=# Click me/a/span

 span id=target2/span

 This should more or less work.

 On Dec 18, 10:02 am, Rick sababa.sab...@gmail.com wrote:







  Thanks for the replies! The variable that I'm operating with is python
  type, not javascript. Mdipierro, your solution looks nice, but i can't
  get it working. The value of the variable doesn't seem to change. Here
  is my code:

  from views/default/index.html:
  {{n=1}}
  a href=# onclick=ajax('{{=URL('plus_n')}}',[],':eval');return
  falseplus/a
  {{=n}}

  controller.py
  def plus_n():
      # check this was called by the ajax post
      if request.env.request_method=='POST':
          # do anything you need to do
          session.n=session.n+1
          # optional return instructions in JS
          return $('.flash').html('n was incremented').slideDown();

  On Dec 18, 2:26 am, pbreit pbreitenb...@gmail.com wrote:

   I don't really understand the question. Do you want to change a JavaScript
   variable? Or a variable in your web2py code? I don't think you would be 
   able
   to modify a web2py variable as the result of a click. By the time the suer
   views your page, all the web2py code has been rendered into HTML. You'll
   either need to code some JavaScript or perform some sort of Ajax call back
   to your server.

   What exactly are you trying to do?


[web2py] Re: variables

2010-12-18 Thread Rick
If n would be a global variable in a controller file, can I use
something like this then?

div id=the_id{{=n}}/div
a href=# onclick=ajax('{{=URL('index')}}',[n=n+1],'the_id');return
falseplus/a



On Dec 18, 4:23 pm, Rick sababa.sab...@gmail.com wrote:
 Perhaps there is a way to get different variable values depending on
 what address you load??? For example:
 http:...default/index.html...something...n=1,m=0

 On Dec 18, 4:07 am, Luther Goh Lu Feng elf...@yahoo.com wrote:







  You can use javascript or jquery(since web2py includes jquery) to do
  this:

  ==javascript==
  $('#some_id).click(function()
    {
       $('#target).val( ($('#target).val()+1) );
    }
  )

  ==html==
  span id=some_ida href=# Click me/a/span

  span id=target2/span

  This should more or less work.

  On Dec 18, 10:02 am, Rick sababa.sab...@gmail.com wrote:

   Thanks for the replies! The variable that I'm operating with is python
   type, not javascript. Mdipierro, your solution looks nice, but i can't
   get it working. The value of the variable doesn't seem to change. Here
   is my code:

   from views/default/index.html:
   {{n=1}}
   a href=# onclick=ajax('{{=URL('plus_n')}}',[],':eval');return
   falseplus/a
   {{=n}}

   controller.py
   def plus_n():
       # check this was called by the ajax post
       if request.env.request_method=='POST':
           # do anything you need to do
           session.n=session.n+1
           # optional return instructions in JS
           return $('.flash').html('n was incremented').slideDown();

   On Dec 18, 2:26 am, pbreit pbreitenb...@gmail.com wrote:

I don't really understand the question. Do you want to change a 
JavaScript
variable? Or a variable in your web2py code? I don't think you would be 
able
to modify a web2py variable as the result of a click. By the time the 
suer
views your page, all the web2py code has been rendered into HTML. You'll
either need to code some JavaScript or perform some sort of Ajax call 
back
to your server.

What exactly are you trying to do?


[web2py] Re: variables

2010-12-18 Thread weheh
I seriously doubt this would work. The [] where you have [n=n+1] is
supposed to be a list of html targets whose values will be passed back
to the controller URL('index'). The proper ajax call would be
onclick=ajax('index',[],':eval');return false;. In this case,
index is defined in the controller callback routine, index.

On Dec 18, 11:56 am, Rick sababa.sab...@gmail.com wrote:
 If n would be a global variable in a controller file, can I use
 something like this then?

 div id=the_id{{=n}}/div
 a href=# onclick=ajax('{{=URL('index')}}',[n=n+1],'the_id');return
 falseplus/a

 On Dec 18, 4:23 pm, Rick sababa.sab...@gmail.com wrote:

  Perhaps there is a way to get different variable values depending on
  what address you load??? For example:
  http:...default/index.html...something...n=1,m=0

  On Dec 18, 4:07 am, Luther Goh Lu Feng elf...@yahoo.com wrote:

   You can use javascript or jquery(since web2py includes jquery) to do
   this:

   ==javascript==
   $('#some_id).click(function()
     {
        $('#target).val( ($('#target).val()+1) );
     }
   )

   ==html==
   span id=some_ida href=# Click me/a/span

   span id=target2/span

   This should more or less work.

   On Dec 18, 10:02 am, Rick sababa.sab...@gmail.com wrote:

Thanks for the replies! The variable that I'm operating with is python
type, not javascript. Mdipierro, your solution looks nice, but i can't
get it working. The value of the variable doesn't seem to change. Here
is my code:

from views/default/index.html:
{{n=1}}
a href=# onclick=ajax('{{=URL('plus_n')}}',[],':eval');return
falseplus/a
{{=n}}

controller.py
def plus_n():
    # check this was called by the ajax post
    if request.env.request_method=='POST':
        # do anything you need to do
        session.n=session.n+1
        # optional return instructions in JS
        return $('.flash').html('n was incremented').slideDown();

On Dec 18, 2:26 am, pbreit pbreitenb...@gmail.com wrote:

 I don't really understand the question. Do you want to change a 
 JavaScript
 variable? Or a variable in your web2py code? I don't think you would 
 be able
 to modify a web2py variable as the result of a click. By the time the 
 suer
 views your page, all the web2py code has been rendered into HTML. 
 You'll
 either need to code some JavaScript or perform some sort of Ajax call 
 back
 to your server.

 What exactly are you trying to do?




[web2py] Re: variables

2010-12-17 Thread pbreit
I don't really understand the question. Do you want to change a JavaScript 
variable? Or a variable in your web2py code? I don't think you would be able 
to modify a web2py variable as the result of a click. By the time the suer 
views your page, all the web2py code has been rendered into HTML. You'll 
either need to code some JavaScript or perform some sort of Ajax call back 
to your server.

What exactly are you trying to do?


[web2py] Re: variables

2010-12-17 Thread Rick
Thanks for the replies! The variable that I'm operating with is python
type, not javascript. Mdipierro, your solution looks nice, but i can't
get it working. The value of the variable doesn't seem to change. Here
is my code:

from views/default/index.html:
{{n=1}}
a href=# onclick=ajax('{{=URL('plus_n')}}',[],':eval');return
falseplus/a
{{=n}}

controller.py
def plus_n():
# check this was called by the ajax post
if request.env.request_method=='POST':
# do anything you need to do
session.n=session.n+1
# optional return instructions in JS
return $('.flash').html('n was incremented').slideDown();


On Dec 18, 2:26 am, pbreit pbreitenb...@gmail.com wrote:
 I don't really understand the question. Do you want to change a JavaScript
 variable? Or a variable in your web2py code? I don't think you would be able
 to modify a web2py variable as the result of a click. By the time the suer
 views your page, all the web2py code has been rendered into HTML. You'll
 either need to code some JavaScript or perform some sort of Ajax call back
 to your server.

 What exactly are you trying to do?


[web2py] Re: variables

2010-12-17 Thread Luther Goh Lu Feng
You can use javascript or jquery(since web2py includes jquery) to do
this:

==javascript==
$('#some_id).click(function()
  {
 $('#target).val( ($('#target).val()+1) );
  }
)

==html==
span id=some_ida href=# Click me/a/span

span id=target2/span


This should more or less work.

On Dec 18, 10:02 am, Rick sababa.sab...@gmail.com wrote:
 Thanks for the replies! The variable that I'm operating with is python
 type, not javascript. Mdipierro, your solution looks nice, but i can't
 get it working. The value of the variable doesn't seem to change. Here
 is my code:

 from views/default/index.html:
 {{n=1}}
 a href=# onclick=ajax('{{=URL('plus_n')}}',[],':eval');return
 falseplus/a
 {{=n}}

 controller.py
 def plus_n():
     # check this was called by the ajax post
     if request.env.request_method=='POST':
         # do anything you need to do
         session.n=session.n+1
         # optional return instructions in JS
         return $('.flash').html('n was incremented').slideDown();

 On Dec 18, 2:26 am, pbreit pbreitenb...@gmail.com wrote:







  I don't really understand the question. Do you want to change a JavaScript
  variable? Or a variable in your web2py code? I don't think you would be able
  to modify a web2py variable as the result of a click. By the time the suer
  views your page, all the web2py code has been rendered into HTML. You'll
  either need to code some JavaScript or perform some sort of Ajax call back
  to your server.

  What exactly are you trying to do?


[web2py] Re: variables turning into lists

2010-06-03 Thread Andrew Buchan
Iceberg,

Thanks, you were right. I didn't think I had to know/care about
whether requests were POST or GET with web2py (and indeed had to
refresh my memory of what the difference was - I'm new to this whole
interweb thing), as far as I was concerned I was just calling
functions within controllers.

Turns out that the function with a self-submitting form is called
using GET when first called, then POST on clicking submit (I don't
remember reading this anywhere). The addition of a field in the form
with the same name as a variable passed in the GET request variables
resulted in those two variables 'merging' into a list as far as
request.vars was concerned. A tad evil I say, but I'm sure it was the
best design option available at the time :-)

I'm now questioning whether I'd ever want to use request.vars instead
of explicitly specifying request.get_vars and request.post_vars, I'll
look out for whether I can/should apply this as I go...


On Jun 2, 4:13 pm, Iceberg iceb...@21cn.com wrote:
 Did not look into your code. But this kind of situation usually is
 caused by a form receives variables from both GET and POST. In this
 case, request.vars.myvar=['blah', 'blah'], but
 request.get_vars.myvar='blah', and request.post_vars.myvar='blah'.  So
 you can choose to use only one of it.

 On Jun2, 9:15pm, Andrew Buchan andyha...@gmail.com wrote:



  Hello,

  I've had this issue before, where a string which is passed as part of
  request.vars somehow becomes a list when the form is submitted. The
  way I got round it at the time was by doing:

  if isinstance(thread_id, list):
      thread_id = thread_id[0]

  However, that just doesn't feel right, and will only work where the
  value never changes (i.e. I can assume that all items in the list have
  the same value so [0] is as good as any), and more to the point, it
  doesn't address why this is happening in the first place.

  I tried the suggestion in post 17355 of this mailing group which seems
  to suggest explicitly passing the vars on submit by adding the
  following to the submit button:

   _action=URL(r=request,args=request.args)

  However, that doesn't work either.

  I've posted some code below where this is happening to the variable
  thread_id, if you look at the 8th  9th line of function
  addreplacementpage() you'll see that I test whether the variable is a
  list or not, and it proves positive only when the form is submitted,
  i.e. the function goes round the loop a second time (self-submitting
  form).

  Has anyone else experienced this or have a solution to the problem, or
  even better: advice on how to figure out what's going on in these kind
  of situations?
  Also, feel free to bash the code, constructively...

  regards,

  Andy.
  -

  def addreplacement():
      #Call this function from other pages, it will initialise the
  PartLists and SelectedParts session
      #variables if required, generate a thread_id and then redirect to
  addreplacementpage function below.
      #These two session variables store the partlist and currently-
  selected-item-in-partlist(for delete/edit purposes)
      #for the replacement currently being worked on (either newly
  raised or amended)
      #The 'thread_id' var is used to allow multiple replacements to be
  edited within the same session,
      #so for the replacement currently being edited use
  session.PartLists[thread_id] to obtain prt list
      #and session.SelectedParts[thread_id] to obtain selected part.
      Complaint_Base_id  = request.vars.record
      title = 'Complaint Raised'
      if not (Complaint_Base_id ):
          return ComplaintSystem.__ShowSimplePage(globals(),
  dict(message = Record id was not supplied with request. ,
  title=title))
      thread_id = int(uuid.uuid4())
      if not session.PartLists:
          session.PartLists = dict()
      session.PartLists[thread_id] = dict()
      if not session.SelectedParts:
          session.SelectedParts = dict()
      session.SelectedParts[thread_id] = -1
      redirect(URL(r=request, f='addreplacementpage',
  vars={'record':Complaint_Base_id, 'thread_id':thread_id}))

  def addreplacementpage():
      #This must only ever be called by function 'addreplacement'
      title = 'Complaint Raised'
      Complaint_Base_id  = request.vars.record
      thread_id = request.vars.thread_id
      assert(Complaint_Base_id )
      assert(thread_id)
      if isinstance(thread_id, list):
          return 'its a list!'
      response.view = 'Complaints/AddReplacement.html'
      response.title = title
      Table = db.Replacement
      form = GenerateReplacementForm( thread_id = thread_id )
      if form.accepts(request.vars, session):
          FieldValues = dict()
          for f in Table.fields:
              if form.vars.has_key(f):
                  FieldValues[f] = form.vars[f]
          FieldValues['Complaint_Base_id'] = Complaint_Base_id
          ReplacementId = Table.insert(**FieldValues)
          for key, value in 

[web2py] Re: variables turning into lists

2010-06-02 Thread Iceberg
Did not look into your code. But this kind of situation usually is
caused by a form receives variables from both GET and POST. In this
case, request.vars.myvar=['blah', 'blah'], but
request.get_vars.myvar='blah', and request.post_vars.myvar='blah'.  So
you can choose to use only one of it.

On Jun2, 9:15pm, Andrew Buchan andyha...@gmail.com wrote:
 Hello,

 I've had this issue before, where a string which is passed as part of
 request.vars somehow becomes a list when the form is submitted. The
 way I got round it at the time was by doing:

 if isinstance(thread_id, list):
     thread_id = thread_id[0]

 However, that just doesn't feel right, and will only work where the
 value never changes (i.e. I can assume that all items in the list have
 the same value so [0] is as good as any), and more to the point, it
 doesn't address why this is happening in the first place.

 I tried the suggestion in post 17355 of this mailing group which seems
 to suggest explicitly passing the vars on submit by adding the
 following to the submit button:

  _action=URL(r=request,args=request.args)

 However, that doesn't work either.

 I've posted some code below where this is happening to the variable
 thread_id, if you look at the 8th  9th line of function
 addreplacementpage() you'll see that I test whether the variable is a
 list or not, and it proves positive only when the form is submitted,
 i.e. the function goes round the loop a second time (self-submitting
 form).

 Has anyone else experienced this or have a solution to the problem, or
 even better: advice on how to figure out what's going on in these kind
 of situations?
 Also, feel free to bash the code, constructively...

 regards,

 Andy.
 -

 def addreplacement():
     #Call this function from other pages, it will initialise the
 PartLists and SelectedParts session
     #variables if required, generate a thread_id and then redirect to
 addreplacementpage function below.
     #These two session variables store the partlist and currently-
 selected-item-in-partlist(for delete/edit purposes)
     #for the replacement currently being worked on (either newly
 raised or amended)
     #The 'thread_id' var is used to allow multiple replacements to be
 edited within the same session,
     #so for the replacement currently being edited use
 session.PartLists[thread_id] to obtain prt list
     #and session.SelectedParts[thread_id] to obtain selected part.
     Complaint_Base_id  = request.vars.record
     title = 'Complaint Raised'
     if not (Complaint_Base_id ):
         return ComplaintSystem.__ShowSimplePage(globals(),
 dict(message = Record id was not supplied with request. ,
 title=title))
     thread_id = int(uuid.uuid4())
     if not session.PartLists:
         session.PartLists = dict()
     session.PartLists[thread_id] = dict()
     if not session.SelectedParts:
         session.SelectedParts = dict()
     session.SelectedParts[thread_id] = -1
     redirect(URL(r=request, f='addreplacementpage',
 vars={'record':Complaint_Base_id, 'thread_id':thread_id}))

 def addreplacementpage():
     #This must only ever be called by function 'addreplacement'
     title = 'Complaint Raised'
     Complaint_Base_id  = request.vars.record
     thread_id = request.vars.thread_id
     assert(Complaint_Base_id )
     assert(thread_id)
     if isinstance(thread_id, list):
         return 'its a list!'
     response.view = 'Complaints/AddReplacement.html'
     response.title = title
     Table = db.Replacement
     form = GenerateReplacementForm( thread_id = thread_id )
     if form.accepts(request.vars, session):
         FieldValues = dict()
         for f in Table.fields:
             if form.vars.has_key(f):
                 FieldValues[f] = form.vars[f]
         FieldValues['Complaint_Base_id'] = Complaint_Base_id
         ReplacementId = Table.insert(**FieldValues)
         for key, value in session.PartLists[thread_id].items():
             db.Replacement_Part.insert(Replacement_id=ReplacementId,
 Row_Index=key, Part_Number=value[0], Description=value[1],
 Cost=value[2], Quantity=value[3])
         return ComplaintSystem.__ShowSimplePage(globals(),
 dict(message='New record created', title='Record Created', links =
 links))
     return dict(form = form, id = Complaint_Base_id )

 def GenerateReplacementForm( thread_id , Rec_ID = None):
     Table = db.Replacement
     Fields = list(db.Replacement.fields)
     for i in ['Complaint_Base_id', 'Status', 'Date_Authorised',
 'Project_Coordinator']:
         Fields.remove(i)
     if Rec_ID :
         form = SQLFORM(Table, record = Rec_ID , showid=False, fields =
 Fields)
     else:
         form = SQLFORM(Table, fields = Fields)

     form.custom.submit = INPUT(_type=submit, _value=Submit,
 _action=URL(r=request,args=request.args))

     ajaxAddPart = ajax('%s', %s, 'partfielderrors');ajax('%s',
 %s,'target'); % \
         (URL(r=request,f='validatepart'), PartFieldsString,
 URL(r=request, f='addpart'),