[web2py] Re: Subfolders in models

2012-12-11 Thread Joel Samuelsson
I'm not sure if we're using the same web2py version. I am using the current 
stable release (2.2.1). The call to listdir looks like this (just 
downloaded a fresh copy and double-checked):
models = listdir(path, '^\w+\.py$', 0, sort=False)
I.e. sort=False. Otherwise, what you describe is true. With sort=False 
though, sort order is not alphabetical and what you describe does not work 
since you can't know in what order models are run.

/Joel


Den måndagen den 10:e december 2012 kl. 17:10:43 UTC+1 skrev Anthony:

 I've been testing the way you described above and it works, to a point. 
 The models are not imported in alphabetical order. This seems to be 
 controlled by this line (521):

 models = listdir(path, '^\w+\.py$', 0, sort=False) in compileapp.py
 listdir is essentially os.walk with a regexp for filtering and os.walk 
 doesn't give any guarantees for ordering at all from what I understand.


 Note, it is not os.listdir -- it is the listdir function from 
 gluon/fileutils.py, which does sort the files alphabetically: 
 http://code.google.com/p/web2py/source/browse/gluon/fileutils.py#88.
  

 Later in compileapp, the models found with listdir are looped through, 
 once (not dependant on the regexp) which gives changing the regexp between 
 models limited use.


 It loops through the files alphabetically -- within any given file, 
 response.models_to_run can be changed, which can affect whether models that 
 come *later* in alphabetical order get run (obviously it cannot cause 
 models that come earlier in alphabetical order to be run). Using 
 response.models_to_run does not change the order in which models are run, 
 nor the ability of later models to affect earlier ones. It merely controls 
 which models get run, with some ability for earlier models to make dynamic 
 changes that affect later ones.
  

 To explain my issue, I'll try to use an example. Please bear with me!
 Let's say I have the following models:

 dbInterface/someDbFile.py

 anotherInterface/someAnotherInterface.py

 __init__.py
 logic.py


 Now let's assume that listdir lists the models root dir first, then 
 anotherInterface dir and then dbInterface dir.


 That should be exactly how listdir lists the models.
  

 I want the dbInterface to load before anotherInterface since 
 anotherInterface is dependant on dbInterface.


 Very simple -- just change the names so dbInterface comes before 
 anotherInterface.
  

 Is there any way I can control the order things are imported from 
 subfolders without changing web2py? I am aware that just setting sort to 
 true in the listdir-call will fix my issue but I would like to be able to 
 update web2py without having to make that change each time, if possible.


 As noted, sort is already True, so you should be OK. There is no way to 
 change the order in which web2py executes the models, though (other than to 
 generate your folder and file names to produce the order you desire).
  
 Anthony


-- 





[web2py] Re: Shared tables and enable_record_versioning dilemma. Two apps trying to create archive table.

2012-12-11 Thread Niphlod
yep

On Tuesday, December 11, 2012 3:06:35 AM UTC+1, Cliff Kachinske wrote:

 Thank you. 

 I think it should work as you described.

 Should I submit a bug report? 



-- 





[web2py] Default value for reference type

2012-12-11 Thread Kostas M
I try to define a lab_members table:

from gluon import current
current.auth = auth

db.define_table('lab_members', 
Field('lab', db.auth_group, label='Lab Name',
  represent=lambda id,row: str(row.role)+' Lab',
  default=db.auth_group(current.auth.user_id)  ),
Field('member',db.auth_user'),
)

But the default value doesn't work. I have tried also the default= 
auth.user_group(auth.user_id) with no luck either.
What I would like to have, is the  lab field pre-completed with the current 
user group, and to be writable=False.

The error is: 
type 'exceptions.TypeError' unsupported operand type(s) for %: 'bool' and 
'Row'


If I put default= db.auth_group(2),writable=False, there is no error, and 
a user group is selected in the drop-down selection, but it is still 
selectable by the user.


Any hints?

-- 





[web2py] Re: Add button to form access from view

2012-12-11 Thread Daniele
Ok. What's the correct way of associating an action to the HTML button with 
web2py?

On Tuesday, December 11, 2012 12:30:34 AM UTC, Massimo Di Pierro wrote:

 This is not worth it. If you make a custom form than you are using html, 
 you may as well make the button in html.

 On Monday, 10 December 2012 15:15:30 UTC-6, Daniele wrote:

 When I use form.add_button() I am able to add a button to a form, which I 
 can display with {{=form}} in my view.

 However, if I'm making a custom form using form.custom, how can I display 
 that button??

 Thanks



-- 





[web2py] Re: problem importing dbconnection - works on first request after server start then shows zero rows

2012-12-11 Thread simon
OK I did not realise that if different threads import a module then it is 
only imported once and the globals are shared between threads.

I have a number of functions in the module and they all use db extensively. 
If I use db=DAL() or db.reconnect() at each request then that is OK for 
local usage of the db within the model. However now I have to pass db as a 
parameter to each function in the module; or turn the module into a class 
and it is very untidy to use self.db everywhere.

Is there any other way to force each thread/request to use their own 
version of a module with their own version of a db connection; but to make 
the db connection available to all functions within the module.


On Tuesday, 11 December 2012 00:24:40 UTC, Massimo Di Pierro wrote:

 You should now make web global. Imagine two requests arrive more or less 
 at the time time. Both call connect? Now you have two threads using the 
 same global web object. You are back to the previous problem. This breaks 
 connection pooling, thread safety, etc.

 You either call db = DAL() at each request and db is a local variable of 
 the request (which you call web) or you call db once in your model and use 
 db.reconnect() to duplicate the connection in the thread that is using it 
 (experimental).


 On Monday, 10 December 2012 10:49:40 UTC-6, simon wrote:

 OK. I think I have done something similar to your suggestion. It seems to 
 work but not sure about memory leaks. Also I note there is no web2py method 
 to close a database connection.

 I want to put all the code interfacing to a 3rd party system in a single 
 file. In that way if I change to a different 3rd party package I just need 
 to change the one file.

 MODULE:

 MODEL:
 import ocart2
 web=ocart2.connect()
 rows=web(web.category.category_id0).select()
 log.info((web.tables, rows))

 MODULE:
 web=None

 def connect():
 global web
 web=DAL(webstring, pool_size=10, migrate=False, migrate_enabled=False)
 web.define_table('category',
 Field('category_id', 'id', notnull=True, writable=False),
 Field('parent_id', 'integer', default=0, notnull=True, 
 writable=False),
 Field('status', 'integer', default=1),
 Field('top', 'integer', notnull=True, writable=False))
 return web





 On Monday, 10 December 2012 15:39:34 UTC, Massimo Di Pierro wrote:

 You cannot do this. The connection has to be stablished in the models 
 and the tables have to be defined in the models as well.

 The issue is that a db connection only lives within a thread. Since 
 web2py is multithreaded at every request you may get a different thread.

  If is ok to do

 import ocart2
 web=ocart2.web()
 rows=web(web.category.category_id0).select()
 log.info((web.tables, rows))

 MODULE:
 from gluon import *
 from config import webstring
 def web():
db = DAL(webstring, pool_size=10, migrate=False, 
 migrate_enabled=False)
db.define_table('category',
  Field('category_id', 'id', notnull=True, writable=False),
  Field('parent_id', 'integer', default=0, notnull=True, 
 writable=False),
  Field('status', 'integer', default=1),
  Field('top', 'integer', notnull=True, writable=False))
return db

 You may also be able to do this:

 MODEL:

 import ocart2
 web=ocart2.web
 web.reconnect() # 
 rows=web(web.category.category_id0).select()
 log.info((web.tables, rows))

 MODULE:
 from gluon import *
 from config import webstring
 web=DAL(webstring, pool_size=10, migrate=False, migrate_enabled=False)
 web.define_table('category',
 Field('category_id', 'id', notnull=True, writable=False),
 Field('parent_id', 'integer', default=0, notnull=True, 
 writable=False),
 Field('status', 'integer', default=1),
 Field('top', 'integer', notnull=True, writable=False))

 Yet the reconnect() method is experimental and I am not sure it does not 
 cause a memory leak. Yet you can help me test it.

 On Monday, 10 December 2012 04:13:43 UTC-6, simon wrote:

 In my model file I am importing a database definition from a module 
 file.
 This works correctly the first time after the server is started showing 
 the tablename and 11 rows in the table.
 However for the second and subsequent requests it shows a rows object 
 but 0 rows in the table.
 It works fine if I put the model definition code inline rather than 
 importing.

 [EDIT: I am fairly sure this used to work. Has something changed? Is 
 there a way to get this to work?]

 MODEL:

 import ocart2
 web=ocart2.web
 rows=web(web.category.category_id0).select()
 log.info((web.tables, rows))

 MODULE:
 from gluon import *
 from config import webstring
 web=DAL(webstring, pool_size=10, migrate=False, migrate_enabled=False)
 web.define_table('category',
 Field('category_id', 'id', notnull=True, writable=False),
 Field('parent_id', 'integer', default=0, notnull=True, 
 writable=False),
 Field('status', 'integer', default=1),
 Field('top', 'integer', notnull=True, writable=False))




[web2py] Dynamically created controllers

2012-12-11 Thread Leonel Câmara
Hey,

Is it possible to have something like this:

mycontroller = make_controller(someargument)


In one of your controller files? Assuming of course that make_controller 
returns a function.  
  
I'm trying to get it to work but I'm getting an *Invalid Function *when I 
try to visit mycontroller.

-- 





[web2py] REF: Returning a dictionary...error

2012-12-11 Thread Teddy Nyambe
What am i missing with these statement:

def getDict():
   return {(o.id:o.name for o in db(db.table).select()}

or

def getDict():
   return dict((o.id:o.name for o in db(db.table).select())

getting same syntax error for both, whats the correct way of returning a
dictionary?

Teddy L.

-- 





[web2py] Re: REF: Returning a dictionary...error

2012-12-11 Thread simon
You seem to have an extra (

On Tuesday, 11 December 2012 11:59:23 UTC, software.ted wrote:

 What am i missing with these statement:

 def getDict():
return {(o.id:o.name for o in db(db.table).select()}

 or

 def getDict():
return dict((o.id:o.name for o in db(db.table).select())

 getting same syntax error for both, whats the correct way of returning a 
 dictionary?

 Teddy L.


  

-- 





[web2py] Re: Dynamically created controllers

2012-12-11 Thread Leonel Câmara
One turnaround I've found is to put this in the controller file instead:


def mycontroller():
return make_controller(someargument)()


Which is a little more ugly and, in my opinion, less readable.

So if anyone can make the first version work I'd love that. 

-- 





Re: [web2py] Re: REF: Returning a dictionary...error

2012-12-11 Thread Teddy Nyambe
I am getting the following error still after removing the extra (

def office():
   return {o.id:o.name for o in db(db.table).select()}

Traceback (most recent call last):
  File /home/www-data/web2py/gluon/contrib/shell.py, line 188, in run
compiled = compile(statement, 'string', 'single')
  File string, line 2
return {o.id:o.name for o in db(db.table).select()}


on the other method I am getting the following error

In [5] : def offices():
   return dict((o.id,o.name) for o in db(db.table).select())


In [6] : print offices()
Traceback (most recent call last):
  File /home/www-data/web2py/gluon/contrib/shell.py, line 235, in run
exec compiled in statement_module.__dict__
  File string, line 1, in module
TypeError: offices() takes exactly 1 argument (0 given)

Kind regards,


On Tue, Dec 11, 2012 at 2:03 PM, simon simo...@gmail.com wrote:

 You seem to have an extra (


 On Tuesday, 11 December 2012 11:59:23 UTC, software.ted wrote:

 What am i missing with these statement:

 def getDict():
return {(o.id:o.name for o in db(db.table).select()}

 or

 def getDict():
return dict((o.id:o.name for o in db(db.table).select())

 getting same syntax error for both, whats the correct way of returning a
 dictionary?

 Teddy L.


   --







-- 
...
Teddy Lubasi Nyambe
Opensource Zambia
Lusaka, ZAMBIA

Cell: +260 97 7760473
website: http://www.opensource.org.zm

~/
Human Knowledge belongs to the world! - AntiTrust

Man is a tool-using animal. Without tools he is nothing, with tools he is
all - Thomas Carlyle 1795-1881

/~

-- 





Re: [web2py] Re: Dynamically created controllers

2012-12-11 Thread Vinicius Assef
Are you trying to dinamically generate a controller file or a function
inside a controller?



On Tue, Dec 11, 2012 at 10:07 AM, Leonel Câmara leonelcam...@gmail.com wrote:
 One turnaround I've found is to put this in the controller file instead:


 def mycontroller():
 return make_controller(someargument)()


 Which is a little more ugly and, in my opinion, less readable.

 So if anyone can make the first version work I'd love that.

 --




-- 





[web2py] calling LOAD from a button

2012-12-11 Thread jonas
Hi

I have a link that redirects to a comment page:

{{=A(TAG.i(_class=icon-pencil), _rel=tooltip, _title=give a comment, 
_class=btn, _href=URL('comment',args=result.id))}

But I want to use LOAD instead of filling a form in a separate page: 

{{=LOAD('default','comment.load',args=result.id,ajax=True,ajax_trap=True,target=userComment)}}

the controller and the view: 

def comment():

 create comment form. Every comment is id locked to the specific 
post 

crud.settings.create_next = URL('index')
post=db(db.blog.id==request.args(0)).select().first()
db.comments.post_id.default=post.id
form=crud.create(db.comments)

return dict(form=form)

{{=form.custom.begin}}
div class=row
  h5date: /h5{{=form.custom.widget.created_on}}
/div
div class=row
  h5name: /h5{{=form.custom.widget.created_by}}
/div
div class=row
  h5mail: /h5{{=form.custom.widget.mail}}
/div
div class=row
  h5link: /h5{{=form.custom.widget.link}}
/div
div class=row
  h5comment:/h5{{=form.custom.widget.comment}}
/div
{{=form.custom.submit}}
{{=form.custom.end}}

How do I trigger the load function from the button, i.e can I replace the 
URL tag with a call to LOAD?
Is it possible to close the LOAD form after completed form so it disappear 
again or at least clear the field and gives a response.flash = T(Posted!)?

-- 





Re: [web2py] Re: Dynamically created controllers

2012-12-11 Thread Leonel Câmara
A function inside a controller file, I'm sorry if I wasn't clear (not a 
native English speaker).

-- 





[web2py] Re: Dynamically created controllers

2012-12-11 Thread Anthony
See http://code.google.com/p/web2py/source/browse/gluon/myregex.py#20 -- 
the controller only exposes functions identified by matching regex_expose, 
which requires using the def syntax to define the function. So only your 
second option will work.

Anthony

On Tuesday, December 11, 2012 7:07:23 AM UTC-5, Leonel Câmara wrote:

 One turnaround I've found is to put this in the controller file instead:


 def mycontroller():
 return make_controller(someargument)()


 Which is a little more ugly and, in my opinion, less readable.

 So if anyone can make the first version work I'd love that. 


-- 





Re: [web2py] Re: REF: Returning a dictionary...error

2012-12-11 Thread Anthony
Do you want a list of dictionaries:

def office():
return dict(mylist=[{o.id:o.name} for o in db(db.table).select()])

Or do you want a single dictionary, with each id as a key:

def office():
return dict([(o.id, o.name) for o in db(db.table).select()])

Anthony

On Tuesday, December 11, 2012 8:11:17 AM UTC-5, software.ted wrote:

 I am getting the following error still after removing the extra (

 def office():
return {o.id:o.name for o in db(db.table).select()}

 Traceback (most recent call last):
   File /home/www-data/web2py/gluon/contrib/shell.py, line 188, in run
 compiled = compile(statement, 'string', 'single')
   File string, line 2
 return {o.id:o.name for o in db(db.table).select()}


 on the other method I am getting the following error

 In [5] : def offices():
return dict((o.id,o.name) for o in db(db.table).select())


 In [6] : print offices()
 Traceback (most recent call last):
   File /home/www-data/web2py/gluon/contrib/shell.py, line 235, in run
 exec compiled in statement_module.__dict__
   File string, line 1, in module
 TypeError: offices() takes exactly 1 argument (0 given)

 Kind regards,


 On Tue, Dec 11, 2012 at 2:03 PM, simon sim...@gmail.com javascript:wrote:

 You seem to have an extra (


 On Tuesday, 11 December 2012 11:59:23 UTC, software.ted wrote:

 What am i missing with these statement:

 def getDict():
return {(o.id:o.name for o in db(db.table).select()}

 or

 def getDict():
return dict((o.id:o.name for o in db(db.table).select())

 getting same syntax error for both, whats the correct way of returning a 
 dictionary?

 Teddy L.
  

   -- 
  
  
  




 -- 

 ...
 Teddy Lubasi Nyambe
 Opensource Zambia
 Lusaka, ZAMBIA

 Cell: +260 97 7760473
 website: http://www.opensource.org.zm

 ~/
 Human Knowledge belongs to the world! - AntiTrust

 Man is a tool-using animal. Without tools he is nothing, with tools he is 
 all - Thomas Carlyle 1795-1881

 /~
  

-- 





[web2py] Re: Subfolders in models

2012-12-11 Thread Massimo Di Pierro
How did that get in there? Fixed in trunk. Thanks Joel for reporting this.

On Tuesday, 11 December 2012 02:51:15 UTC-6, Joel Samuelsson wrote:

 I'm not sure if we're using the same web2py version. I am using the 
 current stable release (2.2.1). The call to listdir looks like this (just 
 downloaded a fresh copy and double-checked):
 models = listdir(path, '^\w+\.py$', 0, sort=False)
 I.e. sort=False. Otherwise, what you describe is true. With sort=False 
 though, sort order is not alphabetical and what you describe does not work 
 since you can't know in what order models are run.

 /Joel


 Den måndagen den 10:e december 2012 kl. 17:10:43 UTC+1 skrev Anthony:

 I've been testing the way you described above and it works, to a point. 
 The models are not imported in alphabetical order. This seems to be 
 controlled by this line (521):

 models = listdir(path, '^\w+\.py$', 0, sort=False) in compileapp.py
 listdir is essentially os.walk with a regexp for filtering and os.walk 
 doesn't give any guarantees for ordering at all from what I understand.


 Note, it is not os.listdir -- it is the listdir function from 
 gluon/fileutils.py, which does sort the files alphabetically: 
 http://code.google.com/p/web2py/source/browse/gluon/fileutils.py#88.
  

 Later in compileapp, the models found with listdir are looped through, 
 once (not dependant on the regexp) which gives changing the regexp between 
 models limited use.


 It loops through the files alphabetically -- within any given file, 
 response.models_to_run can be changed, which can affect whether models that 
 come *later* in alphabetical order get run (obviously it cannot cause 
 models that come earlier in alphabetical order to be run). Using 
 response.models_to_run does not change the order in which models are run, 
 nor the ability of later models to affect earlier ones. It merely controls 
 which models get run, with some ability for earlier models to make dynamic 
 changes that affect later ones.
  

 To explain my issue, I'll try to use an example. Please bear with me!
 Let's say I have the following models:

 dbInterface/someDbFile.py

 anotherInterface/someAnotherInterface.py

 __init__.py
 logic.py


 Now let's assume that listdir lists the models root dir first, then 
 anotherInterface dir and then dbInterface dir.


 That should be exactly how listdir lists the models.
  

 I want the dbInterface to load before anotherInterface since 
 anotherInterface is dependant on dbInterface.


 Very simple -- just change the names so dbInterface comes before 
 anotherInterface.
  

 Is there any way I can control the order things are imported from 
 subfolders without changing web2py? I am aware that just setting sort to 
 true in the listdir-call will fix my issue but I would like to be able to 
 update web2py without having to make that change each time, if possible.


 As noted, sort is already True, so you should be OK. There is no way to 
 change the order in which web2py executes the models, though (other than to 
 generate your folder and file names to produce the order you desire).
  
 Anthony



-- 





[web2py] Re: Default value for reference type

2012-12-11 Thread Massimo Di Pierro
I think the problem is here:

default=db.auth_group(current.auth.user_id)

but not sure. Do you have the complete traceback?

On Tuesday, 11 December 2012 04:23:25 UTC-6, Kostas M wrote:

 I try to define a lab_members table:

 from gluon import current
 current.auth = auth

 db.define_table('lab_members', 
 Field('lab', db.auth_group, label='Lab Name',
   represent=lambda id,row: str(row.role)+' Lab',
   default=db.auth_group(current.auth.user_id)  ),
 Field('member',db.auth_user'),
 )

 But the default value doesn't work. I have tried also the default= 
 auth.user_group(auth.user_id) with no luck either.
 What I would like to have, is the  lab field pre-completed with the 
 current user group, and to be writable=False.

 The error is: 
 type 'exceptions.TypeError' unsupported operand type(s) for %: 'bool' 
 and 'Row'


 If I put default= db.auth_group(2),writable=False, there is no error, 
 and a user group is selected in the drop-down selection, but it is still 
 selectable by the user.


 Any hints?


-- 





[web2py] Re: Add button to form access from view

2012-12-11 Thread Massimo Di Pierro
{{=A('click me',_href=URL('action'))}} (redirects)

or 

{{=A('click me', callback=URL('action'))}} (call via ajax)

or

div id=t/div {{=A('click me', callback=URL('action'),target=t)}} 
(call via ajax and store result in t)

or

div id=c{{=A('click me', callback=URL('action'),delete=div#c)}}/div 
(call via ajax and delete button)

They can be combined.




On Tuesday, 11 December 2012 04:41:25 UTC-6, Daniele wrote:

 Ok. What's the correct way of associating an action to the HTML button 
 with web2py?

 On Tuesday, December 11, 2012 12:30:34 AM UTC, Massimo Di Pierro wrote:

 This is not worth it. If you make a custom form than you are using html, 
 you may as well make the button in html.

 On Monday, 10 December 2012 15:15:30 UTC-6, Daniele wrote:

 When I use form.add_button() I am able to add a button to a form, which 
 I can display with {{=form}} in my view.

 However, if I'm making a custom form using form.custom, how can I 
 display that button??

 Thanks



-- 





[web2py] Re: problem importing dbconnection - works on first request after server start then shows zero rows

2012-12-11 Thread Massimo Di Pierro
All these methods work great. db.reconnect() is experimental and I cannot 
promise it has no memory leaks.

On Tuesday, 11 December 2012 05:14:27 UTC-6, simon wrote:

 OK I did not realise that if different threads import a module then it is 
 only imported once and the globals are shared between threads.

 I have a number of functions in the module and they all use db 
 extensively. If I use db=DAL() or db.reconnect() at each request then the 
 db is not available to each function in the module. I think my options are:
1) Pass db as a parameter to each function in the module
2) Turn the module into a class and use self.db everywhere
3) Put the db in current and have db=current.db at the top of each 
 function in the module

 Is there a better way e.g. can I somehow force each thread/request to use 
 their own version of a module with their own version of a db connection; 
 but make the db connection available to all functions within the module.


 On Tuesday, 11 December 2012 00:24:40 UTC, Massimo Di Pierro wrote:

 You should now make web global. Imagine two requests arrive more or less 
 at the time time. Both call connect? Now you have two threads using the 
 same global web object. You are back to the previous problem. This breaks 
 connection pooling, thread safety, etc.

 You either call db = DAL() at each request and db is a local variable of 
 the request (which you call web) or you call db once in your model and use 
 db.reconnect() to duplicate the connection in the thread that is using it 
 (experimental).


 On Monday, 10 December 2012 10:49:40 UTC-6, simon wrote:

 OK. I think I have done something similar to your suggestion. It seems 
 to work but not sure about memory leaks. Also I note there is no web2py 
 method to close a database connection.

 I want to put all the code interfacing to a 3rd party system in a single 
 file. In that way if I change to a different 3rd party package I just need 
 to change the one file.

 MODULE:

 MODEL:
 import ocart2
 web=ocart2.connect()
 rows=web(web.category.category_id0).select()
 log.info((web.tables, rows))

 MODULE:
 web=None

 def connect():
 global web
 web=DAL(webstring, pool_size=10, migrate=False, 
 migrate_enabled=False)
 web.define_table('category',
 Field('category_id', 'id', notnull=True, writable=False),
 Field('parent_id', 'integer', default=0, notnull=True, 
 writable=False),
 Field('status', 'integer', default=1),
 Field('top', 'integer', notnull=True, writable=False))
 return web





 On Monday, 10 December 2012 15:39:34 UTC, Massimo Di Pierro wrote:

 You cannot do this. The connection has to be stablished in the models 
 and the tables have to be defined in the models as well.

 The issue is that a db connection only lives within a thread. Since 
 web2py is multithreaded at every request you may get a different thread.

  If is ok to do

 import ocart2
 web=ocart2.web()
 rows=web(web.category.category_id0).select()
 log.info((web.tables, rows))

 MODULE:
 from gluon import *
 from config import webstring
 def web():
db = DAL(webstring, pool_size=10, migrate=False, 
 migrate_enabled=False)
db.define_table('category',
  Field('category_id', 'id', notnull=True, writable=False),
  Field('parent_id', 'integer', default=0, notnull=True, 
 writable=False),
  Field('status', 'integer', default=1),
  Field('top', 'integer', notnull=True, writable=False))
return db

 You may also be able to do this:

 MODEL:

 import ocart2
 web=ocart2.web
 web.reconnect() # 
 rows=web(web.category.category_id0).select()
 log.info((web.tables, rows))

 MODULE:
 from gluon import *
 from config import webstring
 web=DAL(webstring, pool_size=10, migrate=False, migrate_enabled=False)
 web.define_table('category',
 Field('category_id', 'id', notnull=True, writable=False),
 Field('parent_id', 'integer', default=0, notnull=True, 
 writable=False),
 Field('status', 'integer', default=1),
 Field('top', 'integer', notnull=True, writable=False))

 Yet the reconnect() method is experimental and I am not sure it does 
 not cause a memory leak. Yet you can help me test it.

 On Monday, 10 December 2012 04:13:43 UTC-6, simon wrote:

 In my model file I am importing a database definition from a module 
 file.
 This works correctly the first time after the server is started 
 showing the tablename and 11 rows in the table.
 However for the second and subsequent requests it shows a rows object 
 but 0 rows in the table.
 It works fine if I put the model definition code inline rather than 
 importing.

 [EDIT: I am fairly sure this used to work. Has something changed? Is 
 there a way to get this to work?]

 MODEL:

 import ocart2
 web=ocart2.web
 rows=web(web.category.category_id0).select()
 log.info((web.tables, rows))

 MODULE:
 from gluon import *
 from config import webstring
 web=DAL(webstring, pool_size=10, migrate=False, 

Re: [web2py] calling LOAD from a button

2012-12-11 Thread Teddy Nyambe
Yes you can call the LOAD your button like this:

{{=A(TAG.i(_class=icon-pencil), _rel=tooltip, _title=give a comment,
_class=btn, _href='#' onclick=jQuery('#myLoad').show();)}


So put this DIV where you want to display your LOAD component

div id=myLoad
   {{=LOAD('default','comment.load',args=result.id,ajax=
True,ajax_trap=True,target=userComment)}}
/div

make sure you hide the DIV on page load as follow...put this at the end of
your page

script
 jQuery('#myLoad').hide();
/script

For hiding the component, I gues you can have a javascript event inside
your comment.load component that hides the DIV




On Tue, Dec 11, 2012 at 3:57 PM, jonas jonas...@gmail.com wrote:

 Hi

 I have a link that redirects to a comment page:

 {{=A(TAG.i(_class=icon-pencil), _rel=tooltip, _title=give a comment,
 _class=btn, _href=URL('comment',args=result.id))}

 But I want to use LOAD instead of filling a form in a separate page:

 {{=LOAD('default','comment.load',args=result.id
 ,ajax=True,ajax_trap=True,target=userComment)}}

 the controller and the view:

 def comment():

  create comment form. Every comment is id locked to the specific
 post 

 crud.settings.create_next = URL('index')
 post=db(db.blog.id==request.args(0)).select().first()
 db.comments.post_id.default=post.id
 form=crud.create(db.comments)

 return dict(form=form)

 {{=form.custom.begin}}
 div class=row
   h5date: /h5{{=form.custom.widget.created_on}}
 /div
 div class=row
   h5name: /h5{{=form.custom.widget.created_by}}
 /div
 div class=row
   h5mail: /h5{{=form.custom.widget.mail}}
 /div
 div class=row
   h5link: /h5{{=form.custom.widget.link}}
 /div
 div class=row
   h5comment:/h5{{=form.custom.widget.comment}}
 /div
 {{=form.custom.submit}}
 {{=form.custom.end}}

 How do I trigger the load function from the button, i.e can I replace the
 URL tag with a call to LOAD?
 Is it possible to close the LOAD form after completed form so it disappear
 again or at least clear the field and gives a response.flash = T(Posted!)?

 --







-- 
...
Teddy Lubasi Nyambe
Opensource Zambia
Lusaka, ZAMBIA

Cell: +260 97 7760473
website: http://www.opensource.org.zm

~/
Human Knowledge belongs to the world! - AntiTrust

Man is a tool-using animal. Without tools he is nothing, with tools he is
all - Thomas Carlyle 1795-1881

/~

-- 





[web2py] Re: calling LOAD from a button

2012-12-11 Thread Massimo Di Pierro
I am not sure because depends on details but you can name a component and 
name it (target=) as you did

{{=LOAD('default','comment.load',args=result.id
,ajax=True,ajax_trap=True,target=userComment)}}

than you have a button call an action and refresh a component

{{=A('click me', _href=URL('comment.load'), component='target')}}





On Tuesday, 11 December 2012 07:57:02 UTC-6, jonas wrote:

 Hi

 I have a link that redirects to a comment page:

 {{=A(TAG.i(_class=icon-pencil), _rel=tooltip, _title=give a comment, 
 _class=btn, _href=URL('comment',args=result.id))}

 But I want to use LOAD instead of filling a form in a separate page: 

 {{=LOAD('default','comment.load',args=result.id
 ,ajax=True,ajax_trap=True,target=userComment)}}

 the controller and the view: 

 def comment():

  create comment form. Every comment is id locked to the specific 
 post 

 crud.settings.create_next = URL('index')
 post=db(db.blog.id==request.args(0)).select().first()
 db.comments.post_id.default=post.id
 form=crud.create(db.comments)

 return dict(form=form)

 {{=form.custom.begin}}
 div class=row
   h5date: /h5{{=form.custom.widget.created_on}}
 /div
 div class=row
   h5name: /h5{{=form.custom.widget.created_by}}
 /div
 div class=row
   h5mail: /h5{{=form.custom.widget.mail}}
 /div
 div class=row
   h5link: /h5{{=form.custom.widget.link}}
 /div
 div class=row
   h5comment:/h5{{=form.custom.widget.comment}}
 /div
 {{=form.custom.submit}}
 {{=form.custom.end}}

 How do I trigger the load function from the button, i.e can I replace the 
 URL tag with a call to LOAD?
 Is it possible to close the LOAD form after completed form so it disappear 
 again or at least clear the field and gives a response.flash = T(Posted!)?


-- 





[web2py] Re: IS_IN_SET problem.

2012-12-11 Thread villas
I think form.vars are always returned as strings anyway,  so just try:

Field('rating',type='integer',default=0,requires=IS_IN_SET(['0','1','2',...])),


On Thursday, December 6, 2012 8:25:15 AM UTC, Annet wrote:

 I have the following field definition:


 Field('rating',type='integer',default=0,requires=IS_IN_SET([0,1,2,3,4,5,6,7,8,9,10])),

 When rating is 0 the drop down field is empty and the drop down list shows 
 the set of ints.
 When rating is greater than 0 the drop down field does display the int.

 Why doesn't this work?

 Kind regards,

 Annet.


-- 





[web2py] Re: Subfolders in models

2012-12-11 Thread Anthony
Looks like sort=False was initially introduced 
herehttp://code.google.com/p/web2py/source/detail?path=/gluon/compileapp.pyname=R-1.96.1r=777cfc90f5833646cbd0b585a6ccc596561e57bc--
 not clear exactly why. Note, fileutils.listdir automatically sorts the 
files within folders, so this appears to affect only the sorting of the 
folders. It wasn't really an issue until the recent introduction of 
response.models_to_run because prior to that, with conditional models, only 
one folder was run.

Anthony

On Tuesday, December 11, 2012 9:25:21 AM UTC-5, Massimo Di Pierro wrote:

 How did that get in there? Fixed in trunk. Thanks Joel for reporting this.

 On Tuesday, 11 December 2012 02:51:15 UTC-6, Joel Samuelsson wrote:

 I'm not sure if we're using the same web2py version. I am using the 
 current stable release (2.2.1). The call to listdir looks like this (just 
 downloaded a fresh copy and double-checked):
 models = listdir(path, '^\w+\.py$', 0, sort=False)
 I.e. sort=False. Otherwise, what you describe is true. With sort=False 
 though, sort order is not alphabetical and what you describe does not work 
 since you can't know in what order models are run.

 /Joel


 Den måndagen den 10:e december 2012 kl. 17:10:43 UTC+1 skrev Anthony:

 I've been testing the way you described above and it works, to a point. 
 The models are not imported in alphabetical order. This seems to be 
 controlled by this line (521):

 models = listdir(path, '^\w+\.py$', 0, sort=False) in compileapp.py
 listdir is essentially os.walk with a regexp for filtering and os.walk 
 doesn't give any guarantees for ordering at all from what I understand.


 Note, it is not os.listdir -- it is the listdir function from 
 gluon/fileutils.py, which does sort the files alphabetically: 
 http://code.google.com/p/web2py/source/browse/gluon/fileutils.py#88.
  

 Later in compileapp, the models found with listdir are looped through, 
 once (not dependant on the regexp) which gives changing the regexp between 
 models limited use.


 It loops through the files alphabetically -- within any given file, 
 response.models_to_run can be changed, which can affect whether models that 
 come *later* in alphabetical order get run (obviously it cannot cause 
 models that come earlier in alphabetical order to be run). Using 
 response.models_to_run does not change the order in which models are run, 
 nor the ability of later models to affect earlier ones. It merely controls 
 which models get run, with some ability for earlier models to make dynamic 
 changes that affect later ones.
  

 To explain my issue, I'll try to use an example. Please bear with me!
 Let's say I have the following models:

 dbInterface/someDbFile.py

 anotherInterface/someAnotherInterface.py

 __init__.py
 logic.py


 Now let's assume that listdir lists the models root dir first, then 
 anotherInterface dir and then dbInterface dir.


 That should be exactly how listdir lists the models.
  

 I want the dbInterface to load before anotherInterface since 
 anotherInterface is dependant on dbInterface.


 Very simple -- just change the names so dbInterface comes before 
 anotherInterface.
  

 Is there any way I can control the order things are imported from 
 subfolders without changing web2py? I am aware that just setting sort to 
 true in the listdir-call will fix my issue but I would like to be able to 
 update web2py without having to make that change each time, if possible.


 As noted, sort is already True, so you should be OK. There is no way to 
 change the order in which web2py executes the models, though (other than to 
 generate your folder and file names to produce the order you desire).
  
 Anthony



-- 





[web2py] get table records using vars

2012-12-11 Thread Hassan Alnatour
Dear ALL , 

Is there a way that i can get table records for table  using vars ? 

best regards,

-- 





[web2py] Re: calling LOAD from a button

2012-12-11 Thread Anthony


 {{=LOAD('default','comment.load',args=result.id
 ,ajax=True,ajax_trap=True,target=userComment)}}


Note, the above will load the component immediately when the page is first 
loaded (even if the div is hidden). If you want to delay any loading until 
the link is clicked, you can just create an empty (possibly hidden) div:

div id=userComment/div

than you have a button call an action and refresh a component

 {{=A('click me', _href=URL('comment.load'), component='target')}}


I think the correct syntax here is:

{{=A('click me', component=URL('comment.load'), target='userComment')}}

When the link is clicked, the component will be loaded into the 
userComment div (and will be re-loaded upon subsequent clicks).

Anthony

-- 





Re: [web2py] get table records using vars

2012-12-11 Thread tomasz bandura
Hello,

For example:
entries = db(db.entry.tags.contains(*request.vars.tag*
)).select(db.entry.ALL)

for tag in URL:
{{=URL('default', 'index', vars=dict(tag=nnn))}}

T.


2012/12/11 Hassan Alnatour halna...@gardeniatelco.com

 Dear ALL ,

 Is there a way that i can get table records for table  using vars ?

 best regards,

 --





-- 





Re: [web2py] get table records using vars

2012-12-11 Thread hasan alnator
type 'exceptions.AttributeError' 'DAL' object has no attribute 'entry'
VERSIONweb2py™(2, 1, 1, datetime.datetime(2012, 10, 15, 12, 44, 40),
'stable')PythonPython 2.7.3: C:\Python27\python.exeTRACEBACK

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

Traceback (most recent call last):
  File C:\web2py\gluon\restricted.py, line 209, in restricted
exec ccode in environment
  File C:/web2py/applications/A3rasna_latestshop/controllers/admin.py
http://127.0.0.1:8000/admin/default/edit/A3rasna_latestshop/controllers/admin.py,
line 22, in module
  File C:\web2py\gluon\globals.py, line 187, in lambda
self._caller = lambda f: f()
  File C:/web2py/applications/A3rasna_latestshop/controllers/admin.py
http://127.0.0.1:8000/admin/default/edit/A3rasna_latestshop/controllers/admin.py,
line 12, in edit
entries = 
db(db.entry.tags.contains(request.vars.table)).select(db.entry.ALL)
  File C:\web2py\gluon\dal.py, line 7150, in __getattr__
return ogetattr(self, key)
AttributeError: 'DAL' object has no attribute 'entry'

-- 





Re: [web2py] get table records using vars

2012-12-11 Thread tomasz bandura
Ok,

To complete my example: You should define two tables (db.py)

db.define_table('tag',Field('name',length=16),format='%(name)s')
db.define_table('entry',
Field('title',length=64),
# (...) some other fields
Field('tags','list:reference tag'))



2012/12/11 hasan alnator halna...@gardeniatelco.com

 type 'exceptions.AttributeError' 'DAL' object has no attribute 
 'entry'VERSION
 web2py™ (2, 1, 1, datetime.datetime(2012, 10, 15, 12, 44, 40), 
 'stable')PythonPython
 2.7.3: C:\Python27\python.exe TRACEBACK

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

 Traceback (most recent call last):
   File C:\web2py\gluon\restricted.py, line 209, in restricted

 exec ccode in environment
   File C:/web2py/applications/A3rasna_latestshop/controllers/admin.py 
 http://127.0.0.1:8000/admin/default/edit/A3rasna_latestshop/controllers/admin.py,
  line 22, in module

   File C:\web2py\gluon\globals.py, line 187, in lambda

 self._caller = lambda f: f()

   File C:/web2py/applications/A3rasna_latestshop/controllers/admin.py 
 http://127.0.0.1:8000/admin/default/edit/A3rasna_latestshop/controllers/admin.py,
  line 12, in edit

 entries = 
 db(db.entry.tags.contains(request.vars.table)).select(db.entry.ALL)

   File C:\web2py\gluon\dal.py, line 7150, in __getattr__

 return ogetattr(self, key)
 AttributeError: 'DAL' object has no attribute 'entry'

  --





-- 





[web2py] Re: Dynamically created controllers

2012-12-11 Thread Leonel Câmara
Thanks for clarifying why the first one wasn't working.

Terça-feira, 11 de Dezembro de 2012 14:08:00 UTC, Anthony escreveu:

 See http://code.google.com/p/web2py/source/browse/gluon/myregex.py#20 -- 
 the controller only exposes functions identified by matching regex_expose, 
 which requires using the def syntax to define the function. So only your 
 second option will work.

 Anthony

 On Tuesday, December 11, 2012 7:07:23 AM UTC-5, Leonel Câmara wrote:

 One turnaround I've found is to put this in the controller file instead:


 def mycontroller():
 return make_controller(someargument)()


 Which is a little more ugly and, in my opinion, less readable.

 So if anyone can make the first version work I'd love that. 



-- 





[web2py] Re: Subfolders in models

2012-12-11 Thread Massimo Di Pierro
sort=False was probably introduce to avoid un-necessary sorting... until it 
become necessary again and I did not set it back to True.

On Tuesday, 11 December 2012 08:52:13 UTC-6, Anthony wrote:

 Looks like sort=False was initially introduced 
 herehttp://code.google.com/p/web2py/source/detail?path=/gluon/compileapp.pyname=R-1.96.1r=777cfc90f5833646cbd0b585a6ccc596561e57bc--
  not clear exactly why. Note, fileutils.listdir automatically sorts the 
 files within folders, so this appears to affect only the sorting of the 
 folders. It wasn't really an issue until the recent introduction of 
 response.models_to_run because prior to that, with conditional models, only 
 one folder was run.

 Anthony

 On Tuesday, December 11, 2012 9:25:21 AM UTC-5, Massimo Di Pierro wrote:

 How did that get in there? Fixed in trunk. Thanks Joel for reporting this.

 On Tuesday, 11 December 2012 02:51:15 UTC-6, Joel Samuelsson wrote:

 I'm not sure if we're using the same web2py version. I am using the 
 current stable release (2.2.1). The call to listdir looks like this (just 
 downloaded a fresh copy and double-checked):
 models = listdir(path, '^\w+\.py$', 0, sort=False)
 I.e. sort=False. Otherwise, what you describe is true. With sort=False 
 though, sort order is not alphabetical and what you describe does not work 
 since you can't know in what order models are run.

 /Joel


 Den måndagen den 10:e december 2012 kl. 17:10:43 UTC+1 skrev Anthony:

 I've been testing the way you described above and it works, to a point. 
 The models are not imported in alphabetical order. This seems to be 
 controlled by this line (521):

 models = listdir(path, '^\w+\.py$', 0, sort=False) in compileapp.py
 listdir is essentially os.walk with a regexp for filtering and os.walk 
 doesn't give any guarantees for ordering at all from what I understand.


 Note, it is not os.listdir -- it is the listdir function from 
 gluon/fileutils.py, which does sort the files alphabetically: 
 http://code.google.com/p/web2py/source/browse/gluon/fileutils.py#88.
  

 Later in compileapp, the models found with listdir are looped through, 
 once (not dependant on the regexp) which gives changing the regexp 
 between 
 models limited use.


 It loops through the files alphabetically -- within any given file, 
 response.models_to_run can be changed, which can affect whether models 
 that 
 come *later* in alphabetical order get run (obviously it cannot cause 
 models that come earlier in alphabetical order to be run). Using 
 response.models_to_run does not change the order in which models are run, 
 nor the ability of later models to affect earlier ones. It merely controls 
 which models get run, with some ability for earlier models to make dynamic 
 changes that affect later ones.
  

 To explain my issue, I'll try to use an example. Please bear with me!
 Let's say I have the following models:

 dbInterface/someDbFile.py

 anotherInterface/someAnotherInterface.py

 __init__.py
 logic.py


 Now let's assume that listdir lists the models root dir first, then 
 anotherInterface dir and then dbInterface dir.


 That should be exactly how listdir lists the models.
  

 I want the dbInterface to load before anotherInterface since 
 anotherInterface is dependant on dbInterface.


 Very simple -- just change the names so dbInterface comes before 
 anotherInterface.
  

 Is there any way I can control the order things are imported from 
 subfolders without changing web2py? I am aware that just setting sort to 
 true in the listdir-call will fix my issue but I would like to be able to 
 update web2py without having to make that change each time, if possible.


 As noted, sort is already True, so you should be OK. There is no way to 
 change the order in which web2py executes the models, though (other than 
 to 
 generate your folder and file names to produce the order you desire).
  
 Anthony



-- 





[web2py] How may I catch this exception class 'psycopg2.IntegrityError'

2012-12-11 Thread Richard
Hello,

I try to write a ondelete function that will try to delete a record and if 
fall on the exception : class 'psycopg2.IntegrityError'

Will trigger a flash message, here the code :

def ondelete_func(form):
try delete ondelete if database raise an error trigger a message 
telling the user that the record can't be deleted
try:
crud.delete(db[request.args(0)], request.args(1))
except IntegrityError:
session.flash = T('The record you try to delete is still referenced 
by other records and can\'t be deleted')

def create_update():
create update funciton
#crud.settings.update_ondelete = StorageList()
form = crud.update(db[request.args(0)], request.args(1), 
ondelete=ondelete_func)
return dict(form=form)

I also try with : except psycopg2.IntegrityError:

No chance.

Thanks

Richard

-- 





[web2py] Re: issue with multi-select widget

2012-12-11 Thread Derek
I suppose so. You could just take an empty list, append request.vars.mylist 
to it, and then it should definitely be a list.

On Tuesday, November 20, 2012 12:08:36 PM UTC-7, SamD wrote:

 Thanks, I found those fixes useful. At the same time, it is quite a pain 
 to have a message of error saying the type is not correct just because the 
 list we pass contains only one element or no element. Would'nt it be more 
 convenient to force whatever is passed to behave as a list (of strings) ?

-- 





Re: [web2py] How may I catch this exception class 'psycopg2.IntegrityError'

2012-12-11 Thread Derek
IntegrityError is a subclass of Database - you need to catch 
psycopg2.database.integrityerror

On Tuesday, December 11, 2012 9:43:04 AM UTC-7, Richard wrote:

 Hello,

 I try to write a ondelete function that will try to delete a record and if 
 fall on the exception : class 'psycopg2.IntegrityError'

 Will trigger a flash message, here the code :

 def ondelete_func(form):
 try delete ondelete if database raise an error trigger a message 
 telling the user that the record can't be deleted
 try:
 crud.delete(db[request.args(0)], request.args(1))
 except IntegrityError:
 session.flash = T('The record you try to delete is still 
 referenced by other records and can\'t be deleted')
 
 def create_update():
 create update funciton
 #crud.settings.update_ondelete = StorageList()
 form = crud.update(db[request.args(0)], request.args(1), 
 ondelete=ondelete_func)
 return dict(form=form)

 I also try with : except psycopg2.IntegrityError:

 No chance.

 Thanks

 Richard


-- 





[web2py] Re: How to fix CRYPT differences between Windows and Linux?

2012-12-11 Thread JoeCodeswell
Dear Massimo,

Thanks for the reply.

I just did a diff between the webfaction private/auth.key file and the 
localWindowsMachine private/auth.key file. 
RESULT: *Files Match*.

History::

*Local Windows Machine*
In response to Niphlod's BTW3 suggestion, which he made on Dec 6 in this 
thread, to copy FROM webfaction TO my local windows machine I: 
1. on webfaction used create package
2. on localWindowsMachine used upload package
You can see the details in my response to Niphlod, made on Dec 8 in this 
thread, starting with Hi Niphlod, Here is my report on your suggestion:.

*Local Ubuntu Machine*
ALSO, i used the create package/upload package technique FROM 
webfaction TO my local Ubuntu Machine. It DID NOT WORK. Please see my Dec 8 
post, starting with: Dear web2py folks, I also have a local ubuntu  

So, to me, there still seems to be a problem.

Thanks for your kelp, Massimo.

Love and peace,

Joe

On Monday, December 10, 2012 4:28:50 PM UTC-8, Massimo Di Pierro wrote:

 You should not publish your key.

 What I am saying is that as online as your key is the same used to create 
 the hashes, the CRYPT validators should do the right job.

 If you want your dev app and production to share data, they must share the 
 same key. 

 Another option is not using the key at all. The web web2py salts all 
 passwords. The global key adds an extra layer of security but it is no 
 longer as important as it used to be when salting was not done. In fact the 
 new welcome no longer creates auth.key.

 This makes it easier sharing salted passwords between different 
 installations of web2py apps.


 On Monday, 10 December 2012 13:26:55 UTC-6, JoeCodeswell wrote:

 Thanks for the response, Massimo.

 I have the auth.key. However, I am a bit concerned about publishing it 
 here since I have potential clients that are looking at myapp on webfaction 
 right now. I am concerned about what i have already published.  What do you 
 suggest I do?

 Thanks in advance.

 Love and peace,

 Joe

 On Saturday, December 8, 2012 2:41:52 PM UTC-8, Massimo Di Pierro wrote:

 The fact is that

  
 CRYPT()('NewFish04pw')==pbkdf2(1000,20,sha512)$a94f2bd3a071cfa8$69e71be8683802edbb83dfc2cb97dfea97ab76c0
 False

 because the stored hashed password depends on the salt but also on the 
 key stores in private/auth.key and I do not know what that is.

 On Saturday, 8 December 2012 14:26:25 UTC-6, JoeCodeswell wrote:

 Sure, Niphlod. I didn't see your post before i posted my comment about 
 my local ubuntu machine which seems to behave like my local windows 
 machine.

 1. can we see how auth is istantiated in your app ?

 In db.py
 from gluon.tools import Auth, Crud, Service, PluginManager, prettydate
 auth = Auth(db, hmac_key=Auth.get_or_create_key())

 2. can you pass us the database (or just one of the auth_user records 
 along with the unencrypted password)

 Here's part of the csv export from webfaction. This is the entry that 
 is awaiting approval. I have no problem giving this out because it is a 
 dummy that i created to test approval.

 auth_user.id
 ,auth_user.first_name,auth_user.last_name,auth_user.email,auth_user.password,auth_user.registration_key,auth_user.reset_password_key,auth_user.registration_id
 5,New,Person,new...@fowl.com
 ,pbkdf2(1000,20,sha512)$a94f2bd3a071cfa8$69e71be8683802edbb83dfc2cb97dfea97ab76c0,pending,,

 Here's the unencrypted pw: NewFish04pw

 Thanks for the help, Niphlod.

 Love and peace,

 Joe


 On Saturday, December 8, 2012 11:54:09 AM UTC-8, Niphlod wrote:

 Thanks Joe...
 1. can we see how auth is istantiated in your app ?
 2. can you pass us the database (or just one of the auth_user records 
 along with the unencrypted password)

 With those, we could easily reproduce the behaviour (i.e. trying to 
 login in the app with the password with exactly your auth_user records) 
 and 
 see what is going on

 On Saturday, December 8, 2012 8:18:58 PM UTC+1, JoeCodeswell wrote:

 Hi Niphlod,

 Here is my report on your suggestion:

 BTW3: to pass around an app just log into admin and hit create 
 package (or tar.gz the entire applications/myapp folder and load it 
 locally with upload package)

 On webfaction-web2py-admin:
 for myapp clicked the Pack all button  downloaded 
 web2py.app.myapp.w2p to myLocalMachine
 On  myLocalMachine in web2py-admin :

1. deleted myapp
2. in Upload and install packed application:
   1. Application name: myapp
   2. Upload a package: path-to/ web2py.app.myapp.w2p 
   3. Or Get from URL: LEFT BLANK
   4. [ ] Overwrite installed app# left this checkbox 
   UNCHECKED
   5. Clicked Install
   6. Flash said: application myapp installed with md5sum: 
   7632e93e985802371a0071a4daca49c7

 TO TEST
 1. Tried logging in with all 4 {email, pw} sets that work on 
 webfaction: RESULT:
 myLocalMachine COULD NOT LOGIN - returning to the login page 
 without comment.
 webfaction  LOGINS JUST FINE
 2. There is one 

Re: [web2py] Re: required_if_other_field_is_true validator

2012-12-11 Thread Jim Steil
Perfect - Thanks guys.

On Thu, Dec 6, 2012 at 5:24 PM, Anthony abasta...@gmail.com wrote:

 Or maybe something like this:

 db.define_table('thing',
 Field('a', 'boolean', default=True),
 Field('b', requires=IS_NOT_EMPTY() if request.vars.a else None))

 Anthony


 On Thursday, December 6, 2012 6:00:52 PM UTC-5, Massimo Di Pierro wrote:

 You can do:


 db.define_table('thing',Field('a','boolean',default=True),Field('b',requires=IS_NOT_EMPTY()))

 def check(form): if not form.vars.a and form.errors.b: del form.errors.b

 form = SQLFORM(db.thing).process(on_validation = check)



 On Thursday, 6 December 2012 16:42:10 UTC-6, Jim S wrote:

 I'm looking to write a validator that makes a field required if another
 field is set to True.  I've looked at this help lesson:

 https://snipt.net/rochacbruno/custom-validator-for-web2py-forms/

 ...but don't know how I'd pass in the value of the other field from the
 form.  Any clues?

 -Jim


 --





-- 





Re: [web2py] REF: Returning a dictionary...error

2012-12-11 Thread Jonathan Lundell
On 11 Dec 2012, at 3:59 AM, Teddy Nyambe software@gmail.com wrote:
 What am i missing with these statement:
 
 def getDict():
return {(o.id:o.name for o in db(db.table).select()}
 
 or
 
 def getDict():
return dict((o.id:o.name for o in db(db.table).select())
 
 getting same syntax error for both, whats the correct way of returning a 
 dictionary?
 

IIRC, dict() will take a list of tuples.

I'd try: return dict( ( (o.id, o.name) for o in db(db.table).select() ) )

(extra spaces for clarity)

-- 





[web2py] Many asked for it... Kryten is available

2012-12-11 Thread Massimo Di Pierro
https://github.com/mdipierro/kryten

-- 





Re: [web2py] How may I catch this exception class 'psycopg2.IntegrityError'

2012-12-11 Thread Richard Vézina
type 'exceptions.NameError' global name 'psycopg2' is not defined

Richard

On Tue, Dec 11, 2012 at 11:57 AM, Derek sp1d...@gmail.com wrote:

 psycopg2.database.integrityerror


-- 





Re: [web2py] Question about ondelete='CASCADE'

2012-12-11 Thread Mark
Based on your model, records in table2 are parent records, and records in 
table3 are child records. I think the ondelete means on_parent_delete. 

Mark 

On Tuesday, December 11, 2012 10:42:47 AM UTC-5, Richard wrote:

 Here the error class 'psycopg2.IntegrityError' ERREUR: UPDATE ou DELETE 
 sur la table « table2 » viole la contrainte de clé étrangère « 
 table3_field2t3_fkey » de la table « table3 » DETAIL: La clé (id)=(1) est 
 toujours référencée à partir de la table « table3 ». 

 Here the code :

 # Model 

 db.define_table('table1',Field('fieldt1','string'), format='%(fieldt1)s')

 db.define_table('table2',Field('fieldt2','string'), Field('field2t2', 
 'reference table1', ondelete='NO ACTION'), format='%(fieldt2)s')

 db.define_table('table3',Field('fieldt3','string'), Field('field2t3', 
 'reference table2', ondelete='NO ACTION'), format='%(fieldt3)s')

 # Controller

 def create_update():
 create update funciton
 form = crud.update(db[request.args(0)], request.args(1))
 return dict(form=form)

 I attach the app...

 The problem arrive when I try to delete a record in table2 that is 
 attached to a record in table 3.

 I can make a function that will check if this record is attached by a 
 record in table 3 before trying to deleted it, but I am curious to know if 
 there is an other solution.

 The database is Postgres.

 I just test with SQLite and it is even worse, deletion of the referenced 
 record is allowed but the record in the table 3 still reference the record. 
 Form my point of view deletion of a record referenced shouldn't be allowed 
 if there is a ondelete clause apply to the reference field. I also try to 
 change the 'NO ACTION' for 'CASCADE' and if I delete a record of table 3 
 that reference table2 record the referenced table 2 record doesn't get 
 deleted (still with SQLite).

 I use web2py 2.2.1 for all these test.

 Hope my model is correct.

 I just test also with Postgres (8.4) and even when CASCADE is setted the 
 referenced records are not deleted on deletion.

 Thanks

 Richard

 On Mon, Dec 10, 2012 at 5:28 PM, Niphlod nip...@gmail.com 
 javascript:wrote:

 we should see the model and the traceback. Some db engines are more 
 permissive than others. Often the cause of the issue is some sort of 
 unique or notnull costraint set on the referenced table.


 On Monday, December 10, 2012 10:30:15 PM UTC+1, Richard wrote:

 Hello,

 My app raise issue when someone delete a record referenced by a other 
 table. I this table I set for the reference field ondelete='NO ACTION', but 
 as far as I understand it not solve noting since table1 (the referenced 
 table) will not look at table2 definition to know what todo on delete.

 What should I do to make sure my app not raise issue on delete of a 
 record if the record someone try to delete could not be deleted because it 
 is referenced by an other table?

 Do I have to write my own function and trigger it with ondelete option 
 of crud.update or SQLFORM?

 Thanks

 Richard

  -- 
  
  
  




-- 





Re: [web2py] Question about ondelete='CASCADE'

2012-12-11 Thread Richard Vézina
You are right that what I am think, but the doc is not clear.

I open an other thread about a function that should be trigger on
crud.update in case of deletation with crud.update(..., ondelete=funciton)

Thanks

Richard

On Tue, Dec 11, 2012 at 2:18 PM, Mark czhang2...@gmail.com wrote:



-- 





[web2py] Re: Many asked for it... Kryten is available

2012-12-11 Thread Niphlod
I'll be the first one to thank you for it :P

On Tuesday, December 11, 2012 6:21:17 PM UTC+1, Massimo Di Pierro wrote:

 https://github.com/mdipierro/kryten


-- 





Re: [web2py] Many asked for it... Kryten is available

2012-12-11 Thread Bruno Rocha
Thanks!

I will use this for my nest talk!

-- 





Re: [web2py] Question about ondelete='CASCADE'

2012-12-11 Thread Niphlod
ok, I had time to test. 
SQLite environment, bug is there for 2.2.1, but is fixed in trunk.
For PostgreSQL, it's a different story. I'll quote the official docs on that
*

Restricting and cascading deletes are the two most common options. 
RESTRICTprevents deletion of a referenced row. NO 
ACTION means that if any referencing rows still exist when the constraint 
is checked, an error is raised; this is the default behavior if you do not 
specify anything. (The essential difference between these two choices is 
that NO ACTION allows the check to be deferred until later in the 
transaction, whereas RESTRICT does not.) CASCADE specifies that when a 
referenced row is deleted, row(s) referencing it should be automatically 
deleted as well. There are two other options: SET NULL and SET DEFAULT. 
These cause the referencing columns to be set to nulls or default values, 
respectively, when the referenced row is deleted. Note that these do not 
excuse you from observing any constraints. For example, if an action 
specifies SET DEFAULT but the default value would not satisfy the foreign 
key, the operation will fail.*

So, ondelete='NO ACTION' will still raise the error. If you need - as it 
seems - to simply let the check loose if the parent record is deleted, 
the way to go is either 'SET NULL' or 'SET DEFAULT'. 
BTW: To exploit SET DEFAULT you can't rely on the default= attribute of the 
field, that one is valid only inside the DAL. 

SET NULL works perfectly fine (i.e. your table3 record will have a field2t3 
set to NULL, effectively loosing the reference to table2.id)
PS: you have to let web2py recreate the table because once the table is 
created, changes to the ondelete attribute will not trigger the COSTRAINT 
drop and recreation.

On Tuesday, December 11, 2012 8:32:11 PM UTC+1, Richard wrote:

 You are right that what I am think, but the doc is not clear.

 I open an other thread about a function that should be trigger on 
 crud.update in case of deletation with crud.update(..., ondelete=funciton)

 Thanks

 Richard

 On Tue, Dec 11, 2012 at 2:18 PM, Mark czhan...@gmail.com javascript:wrote:

  




-- 





Re: [web2py] Question about ondelete='CASCADE'

2012-12-11 Thread Richard Vézina
Thanks Niphold I appreciate.

I try to work around this by creating a ondelete function that will try to
delete the record if it raise a error respond to the user the record can't
be delete.

I struggle to catch IntegrityError, I open an other thread about that if
you have time.

I don't want a record still referenced to be deleted and I want to prevent
web2py to throw a ticket about that.

Thanks

Richard

On Tue, Dec 11, 2012 at 3:08 PM, Niphlod niph...@gmail.com wrote:

 : you have to let web2py recreate the table because once the table is
 created, changes to the ondelete attribute will not trigger the COSTRAINT
 drop and

-- 





[web2py] Re: How to fix CRYPT differences between Windows and Linux?

2012-12-11 Thread Massimo Di Pierro
Can you try do this on both machines?

$ python web2py.py -S yourappname -M
 print db.auth_user.password.validate('dummy')[0]

Do you get the same output? What are the two python version? 32bits or 
64bits?

Massimo


On Tuesday, 11 December 2012 11:01:54 UTC-6, JoeCodeswell wrote:

 Dear Massimo,

 Thanks for the reply.

 I just did a diff between the webfaction private/auth.key file and the 
 localWindowsMachine private/auth.key file. 
 RESULT: *Files Match*.

 History::

 *Local Windows Machine*
 In response to Niphlod's BTW3 suggestion, which he made on Dec 6 in this 
 thread, to copy FROM webfaction TO my local windows machine I: 
 1. on webfaction used create package
 2. on localWindowsMachine used upload package
 You can see the details in my response to Niphlod, made on Dec 8 in this 
 thread, starting with Hi Niphlod, Here is my report on your suggestion:.

 *Local Ubuntu Machine*
 ALSO, i used the create package/upload package technique FROM 
 webfaction TO my local Ubuntu Machine. It DID NOT WORK. Please see my Dec 8 
 post, starting with: Dear web2py folks, I also have a local ubuntu  

 So, to me, there still seems to be a problem.

 Thanks for your kelp, Massimo.

 Love and peace,

 Joe

 On Monday, December 10, 2012 4:28:50 PM UTC-8, Massimo Di Pierro wrote:

 You should not publish your key.

 What I am saying is that as online as your key is the same used to create 
 the hashes, the CRYPT validators should do the right job.

 If you want your dev app and production to share data, they must share 
 the same key. 

 Another option is not using the key at all. The web web2py salts all 
 passwords. The global key adds an extra layer of security but it is no 
 longer as important as it used to be when salting was not done. In fact the 
 new welcome no longer creates auth.key.

 This makes it easier sharing salted passwords between different 
 installations of web2py apps.


 On Monday, 10 December 2012 13:26:55 UTC-6, JoeCodeswell wrote:

 Thanks for the response, Massimo.

 I have the auth.key. However, I am a bit concerned about publishing it 
 here since I have potential clients that are looking at myapp on webfaction 
 right now. I am concerned about what i have already published.  What do you 
 suggest I do?

 Thanks in advance.

 Love and peace,

 Joe

 On Saturday, December 8, 2012 2:41:52 PM UTC-8, Massimo Di Pierro wrote:

 The fact is that

  
 CRYPT()('NewFish04pw')==pbkdf2(1000,20,sha512)$a94f2bd3a071cfa8$69e71be8683802edbb83dfc2cb97dfea97ab76c0
 False

 because the stored hashed password depends on the salt but also on the 
 key stores in private/auth.key and I do not know what that is.

 On Saturday, 8 December 2012 14:26:25 UTC-6, JoeCodeswell wrote:

 Sure, Niphlod. I didn't see your post before i posted my comment about 
 my local ubuntu machine which seems to behave like my local windows 
 machine.

 1. can we see how auth is istantiated in your app ?

 In db.py
 from gluon.tools import Auth, Crud, Service, PluginManager, prettydate
 auth = Auth(db, hmac_key=Auth.get_or_create_key())

 2. can you pass us the database (or just one of the auth_user records 
 along with the unencrypted password)

 Here's part of the csv export from webfaction. This is the entry that 
 is awaiting approval. I have no problem giving this out because it is a 
 dummy that i created to test approval.

 auth_user.id
 ,auth_user.first_name,auth_user.last_name,auth_user.email,auth_user.password,auth_user.registration_key,auth_user.reset_password_key,auth_user.registration_id
 5,New,Person,new...@fowl.com
 ,pbkdf2(1000,20,sha512)$a94f2bd3a071cfa8$69e71be8683802edbb83dfc2cb97dfea97ab76c0,pending,,

 Here's the unencrypted pw: NewFish04pw

 Thanks for the help, Niphlod.

 Love and peace,

 Joe


 On Saturday, December 8, 2012 11:54:09 AM UTC-8, Niphlod wrote:

 Thanks Joe...
 1. can we see how auth is istantiated in your app ?
 2. can you pass us the database (or just one of the auth_user records 
 along with the unencrypted password)

 With those, we could easily reproduce the behaviour (i.e. trying to 
 login in the app with the password with exactly your auth_user records) 
 and 
 see what is going on

 On Saturday, December 8, 2012 8:18:58 PM UTC+1, JoeCodeswell wrote:

 Hi Niphlod,

 Here is my report on your suggestion:

 BTW3: to pass around an app just log into admin and hit create 
 package (or tar.gz the entire applications/myapp folder and load it 
 locally with upload package)

 On webfaction-web2py-admin:
 for myapp clicked the Pack all button  downloaded 
 web2py.app.myapp.w2p to myLocalMachine
 On  myLocalMachine in web2py-admin :

1. deleted myapp
2. in Upload and install packed application:
   1. Application name: myapp
   2. Upload a package: path-to/ web2py.app.myapp.w2p 
   3. Or Get from URL: LEFT BLANK
   4. [ ] Overwrite installed app# left this checkbox 
   UNCHECKED
   5. Clicked Install
   6. Flash said: application myapp 

Re: [web2py] Many asked for it... Kryten is available

2012-12-11 Thread Niphlod
this will make audio available for ubuntu too.

os.system('espeak -s 120 %s' % 
text.replace('','\\').replace(',\\'))

maybe a simple check with platform.platform and if MacOS use say else 
espeak ? Or a variable that takes the binary for text2speech conversion ?

On Tuesday, December 11, 2012 8:44:25 PM UTC+1, rochacbruno wrote:

 Thanks!

 I will use this for my nest talk!




-- 





Re: [web2py] How may I catch this exception class 'psycopg2.IntegrityError'

2012-12-11 Thread Niphlod

to catch the exceptions from a module, you should import it

import psycopg2



in your controller will let you do:

try:
db(db.table2.id0).delete()
except psycopg2.IntegrityError:
session.flash = can't do this and that

However, instead of resorting to catch the integrityerror that in the 
future may change, I'd go with the route that sees if in the child table(s) 
there are records attached.


-- 





Re: [web2py] How may I catch this exception class 'psycopg2.IntegrityError'

2012-12-11 Thread Richard Vézina
I have to see if record of table2 is attached by table3 in my example, but
in my app actually, table3 is 30 differents tables that each can refer to
table2 entry multiple time (one to many)...

I would prefer to do what you suggest child tables but I am afraid of
overhead.

Richard

On Tue, Dec 11, 2012 at 3:32 PM, Niphlod niph...@gmail.com wrote:

 ere are records attached.

-- 





Re: [web2py] Re: DB insert confusion

2012-12-11 Thread Kurt Grutzmacher
I don't think this is a good JSON-RPC example as the change broke our app 
that uses simplejsonrpc or jsonrpclib to make API calls.

Based on the jsonrpclib python module 
@ https://code.google.com/p/jsonrpclib/ requests look like:

 import jsonrpclib
 server = jsonrpclib.Server('http://localhost:8080')
 server.add(5,6)
11
 print jsonrpclib.history.request
{jsonrpc: 2.0, params: [5, 6], id: gb3c9g37, method: add}
 print jsonrpclib.history.response
{'jsonrpc': '2.0', 'result': 11, 'id': 'gb3c9g37'}


And the JSON-RPC spec states params should be An Array of objects to pass 
as arguments to the method. -- http://json-rpc.org/wiki/specification

However the actual spec doesn't specify array, dict or whatever as it tries 
to be universal: A Structured value that holds the parameter values to be 
used during the invocation of the method. This member MAY be omitted.  
http://www.jsonrpc.org/specification#request_object

For simplejsonrpc and jsonrpclib to work we have to undo this change in 
gluon/tools.py


On Wednesday, November 14, 2012 1:25:22 PM UTC-8, Mike Anson wrote:

 Thanks very much for your help Niphlod.

 On Wednesday, 14 November 2012 16:10:35 UTC-5, Niphlod wrote:


 Yes I understand your point. The reason it is currently like this is 
 because if I use your suggestion (which I obviously had originally)

 {id: 1, method: savemessage, params: { *message*: 
 variableholdingmessage, *uid* : variableholdingmail}}

 I get message and uid as the values in the DB. So I switched them.

 {id: 1, method: savemessage, params: { variableholdingmessage: 
 mymessage, variableholdinguid : myemail@localhost}}

 The result means that variableholdingmessage is saved as the message and 
 not the expected mymessage. Exactly the same for uid.

 Unfortunately jsonrpc call method has a bug. in web2py 2.2.1, in 
 gluon/tools.py, line 4231 should be 

 s = methods[method](**params)

 instead of

 s = methods[method](*params)


 sending a patch to Massimo right now!
  


 re: PS -- haha yes I know. I did try it with single quotes and it 
 crapped out?? So just kept the doubles. It's not that bad!

 re: PS2 -- have you any recommendations to solve this special character 
 potential problem?

  
 Normally with jsonrpc you use something that is not curl, e.g. a 
 programming language that supports json (python?!)
 Escaping on bash without awk, sed, etc is always problematic but if 
 you're willing to have as only limitation the  character that is less 
 frequent to use within a message, why don't you use one of the methods not 
 requiring a json body to be posted ? e.g. @service.xml, @service.csv or 
 @service.json

 curl -v --get --data-urlencode \uid=$uid\ --data-urlencode 
 \message=$message\ $url

 here curl takes care of urlencoding the message and the uid parameters.


  



-- 





Re: [web2py] Re: DB insert confusion

2012-12-11 Thread Niphlod
I took some time to watch at the jsonrpc specs. Right now I had experience 
with jsonrpc only in the named parameters format. I thought it was the 
standard, my bad. 
However, I found out that 2.0 introduced named parameters that were not 
supported - explicitely - in 1.0

-- {jsonrpc: 2.0, method: subtract, params: [42, 23], id: 1}
-- {jsonrpc: 2.0, result: 19, id: 1}

-- {jsonrpc: 2.0, method: subtract, params: {subtrahend: 23, 
minuend: 42}, id: 3}
-- {jsonrpc: 2.0, result: 19, id: 3}


are both valid.

Maybe revert this and make a jsonrpc2 decorator to support named parameters 
explicitely would be a better solution?

On Tuesday, December 11, 2012 9:57:50 PM UTC+1, Kurt Grutzmacher wrote:

 I don't think this is a good JSON-RPC example as the change broke our app 
 that uses simplejsonrpc or jsonrpclib to make API calls.

 Based on the jsonrpclib python module @ 
 https://code.google.com/p/jsonrpclib/ requests look like:

  import jsonrpclib
  server = jsonrpclib.Server('http://localhost:8080')
  server.add(5,6)
 11
  print jsonrpclib.history.request
 {jsonrpc: 2.0, params: [5, 6], id: gb3c9g37, method: add}
  print jsonrpclib.history.response
 {'jsonrpc': '2.0', 'result': 11, 'id': 'gb3c9g37'}


 And the JSON-RPC spec states params should be An Array of objects to pass 
 as arguments to the method. -- http://json-rpc.org/wiki/specification

 However the actual spec doesn't specify array, dict or whatever as it 
 tries to be universal: A Structured value that holds the parameter 
 values to be used during the invocation of the method. This member MAY be 
 omitted.  http://www.jsonrpc.org/specification#request_object

 For simplejsonrpc and jsonrpclib to work we have to undo this change in 
 gluon/tools.py


 On Wednesday, November 14, 2012 1:25:22 PM UTC-8, Mike Anson wrote:

 Thanks very much for your help Niphlod.

 On Wednesday, 14 November 2012 16:10:35 UTC-5, Niphlod wrote:


 Yes I understand your point. The reason it is currently like this is 
 because if I use your suggestion (which I obviously had originally)

 {id: 1, method: savemessage, params: { *message*: 
 variableholdingmessage, *uid* : variableholdingmail}}

 I get message and uid as the values in the DB. So I switched them.

 {id: 1, method: savemessage, params: { 
 variableholdingmessage: mymessage, variableholdinguid : 
 myemail@localhost}}

 The result means that variableholdingmessage is saved as the message 
 and not the expected mymessage. Exactly the same for uid.

 Unfortunately jsonrpc call method has a bug. in web2py 2.2.1, in 
 gluon/tools.py, line 4231 should be 

 s = methods[method](**params)

 instead of

 s = methods[method](*params)


 sending a patch to Massimo right now!
  


 re: PS -- haha yes I know. I did try it with single quotes and it 
 crapped out?? So just kept the doubles. It's not that bad!

 re: PS2 -- have you any recommendations to solve this special character 
 potential problem?

  
 Normally with jsonrpc you use something that is not curl, e.g. a 
 programming language that supports json (python?!)
 Escaping on bash without awk, sed, etc is always problematic but if 
 you're willing to have as only limitation the  character that is less 
 frequent to use within a message, why don't you use one of the methods not 
 requiring a json body to be posted ? e.g. @service.xml, @service.csv or 
 @service.json

 curl -v --get --data-urlencode \uid=$uid\ --data-urlencode 
 \message=$message\ $url

 here curl takes care of urlencoding the message and the uid parameters.


  



-- 





Re: [web2py] How may I catch this exception class 'psycopg2.IntegrityError'

2012-12-11 Thread Massimo Di Pierro
Mand that you if catch a DB exception you must revert or you cannot do 
anything else with the DB within the transaction and you end up with a 
ticket.

On Tuesday, 11 December 2012 14:52:08 UTC-6, Richard wrote:

 I have to see if record of table2 is attached by table3 in my example, but 
 in my app actually, table3 is 30 differents tables that each can refer to 
 table2 entry multiple time (one to many)...

 I would prefer to do what you suggest child tables but I am afraid of 
 overhead.

 Richard

 On Tue, Dec 11, 2012 at 3:32 PM, Niphlod nip...@gmail.com 
 javascript:wrote:

 ere are records attached.




-- 





Re: [web2py] Re: DB insert confusion

2012-12-11 Thread Jonathan Lundell
On 11 Dec 2012, at 1:09 PM, Niphlod niph...@gmail.com wrote:
 I took some time to watch at the jsonrpc specs. Right now I had experience 
 with jsonrpc only in the named parameters format. I thought it was the 
 standard, my bad. 
 However, I found out that 2.0 introduced named parameters that were not 
 supported - explicitely - in 1.0
 
 -- {jsonrpc: 2.0, method: subtract, params: [42, 23], id: 1}
 -- {jsonrpc: 2.0, result: 19, id: 1}
 
 -- {jsonrpc: 2.0, method: subtract, params: {subtrahend: 23, 
 minuend: 42}, id: 3}
 -- {jsonrpc: 2.0, result: 19, id: 3}
 
 are both valid.
 
 Maybe revert this and make a jsonrpc2 decorator to support named parameters 
 explicitely would be a better solution?

How about both jsonrpc1 and jsonrpc2, and then jsonrpc = jsonrpc2? (I think 
it'd be better to make v2 the default.)

 
 On Tuesday, December 11, 2012 9:57:50 PM UTC+1, Kurt Grutzmacher wrote:
 I don't think this is a good JSON-RPC example as the change broke our app 
 that uses simplejsonrpc or jsonrpclib to make API calls.
 
 Based on the jsonrpclib python module @ https://code.google.com/p/jsonrpclib/ 
 requests look like:
 
  import jsonrpclib
  server = jsonrpclib.Server('http://localhost:8080')
  server.add(5,6)
 11
  print jsonrpclib.history.request
 {jsonrpc: 2.0, params: [5, 6], id: gb3c9g37, method: add}
  print jsonrpclib.history.response
 {'jsonrpc': '2.0', 'result': 11, 'id': 'gb3c9g37'}
 
 And the JSON-RPC spec states params should be An Array of objects to pass as 
 arguments to the method. -- http://json-rpc.org/wiki/specification
 
 However the actual spec doesn't specify array, dict or whatever as it tries 
 to be universal: A Structured value that holds the parameter values to be 
 used during the invocation of the method. This member MAY be omitted.  
 http://www.jsonrpc.org/specification#request_object
 
 For simplejsonrpc and jsonrpclib to work we have to undo this change in 
 gluon/tools.py
 
 
 On Wednesday, November 14, 2012 1:25:22 PM UTC-8, Mike Anson wrote:
 Thanks very much for your help Niphlod.
 
 On Wednesday, 14 November 2012 16:10:35 UTC-5, Niphlod wrote:
 
 Yes I understand your point. The reason it is currently like this is because 
 if I use your suggestion (which I obviously had originally)
 
 {id: 1, method: savemessage, params: { message: 
 variableholdingmessage, uid : variableholdingmail}}
 
 I get message and uid as the values in the DB. So I switched them.
 
 {id: 1, method: savemessage, params: { variableholdingmessage: 
 mymessage, variableholdinguid : myemail@localhost}}
 
 The result means that variableholdingmessage is saved as the message and not 
 the expected mymessage. Exactly the same for uid.
 
 Unfortunately jsonrpc call method has a bug. in web2py 2.2.1, in 
 gluon/tools.py, line 4231 should be 
 
 s = methods[method](**params)
 
 instead of
 
 s = methods[method](*params)
 
 sending a patch to Massimo right now!
  
 
 re: PS -- haha yes I know. I did try it with single quotes and it crapped 
 out?? So just kept the doubles. It's not that bad!
 
 re: PS2 -- have you any recommendations to solve this special character 
 potential problem?
 
  
 Normally with jsonrpc you use something that is not curl, e.g. a programming 
 language that supports json (python?!)
 Escaping on bash without awk, sed, etc is always problematic but if 
 you're willing to have as only limitation the  character that is less 
 frequent to use within a message, why don't you use one of the methods not 
 requiring a json body to be posted ? e.g. @service.xml, @service.csv or 
 @service.json
 
 curl -v --get --data-urlencode \uid=$uid\ --data-urlencode 
 \message=$message\ $url
 
 here curl takes care of urlencoding the message and the uid parameters.
 
 
  
 
 -- 
  
  
  


-- 





Re: [web2py] How may I catch this exception class 'psycopg2.IntegrityError'

2012-12-11 Thread Richard Vézina
By the way import psycopg2

Doesn't seem to help.

Richard

On Tue, Dec 11, 2012 at 3:52 PM, Richard Vézina ml.richard.vez...@gmail.com
 wrote:

 I have to see if record of table2 is attached by table3 in my example, but
 in my app actually, table3 is 30 differents tables that each can refer to
 table2 entry multiple time (one to many)...

 I would prefer to do what you suggest child tables but I am afraid of
 overhead.

 Richard

 On Tue, Dec 11, 2012 at 3:32 PM, Niphlod niph...@gmail.com wrote:

 ere are records attached.




-- 





Re: [web2py] How may I catch this exception class 'psycopg2.IntegrityError'

2012-12-11 Thread Richard Vézina
So, it may be the reason I get internal error then. And the Niphold code is
working. I make test.

Richard

On Tue, Dec 11, 2012 at 4:40 PM, Massimo Di Pierro 
massimo.dipie...@gmail.com wrote:

 Mand that you if catch a DB exception you must revert or you cannot do
 anything else with the DB within the transaction and you end up with a
 ticket.


 On Tuesday, 11 December 2012 14:52:08 UTC-6, Richard wrote:

 I have to see if record of table2 is attached by table3 in my example,
 but in my app actually, table3 is 30 differents tables that each can refer
 to table2 entry multiple time (one to many)...

 I would prefer to do what you suggest child tables but I am afraid of
 overhead.

 Richard


 On Tue, Dec 11, 2012 at 3:32 PM, Niphlod nip...@gmail.com wrote:

 ere are records attached.


  --





-- 





Re: [web2py] How may I catch this exception class 'psycopg2.IntegrityError'

2012-12-11 Thread Richard Vézina
Do I am doing right?

def ondelete_func(form):
try delete ondelete if database raise an error trigger a message
telling the user that the record can't be deleted
import psycopg2
try:
db(db[request.args(0)].id==request.args(1)).delete()
except psycopg2.IntegrityError:
db.rollback()
session.flash = T('The record you try to delete is still referenced
by other records and can\'t be deleted')

def create_update():
create update funciton
form = crud.update(db[request.args(0)], request.args(1),
onvalidation=ondelete_func)
return dict(form=form)

I still get this ticket :

class 'psycopg2.IntegrityError' ERREUR: UPDATE ou DELETE sur la table «
table2 » viole la contrainte de clé étrangère « fk_table3 » de la table «
table3 » DETAIL: La clé (id)=(2) est toujours référencée à partir de la
table « table3 »


And I am not sure how I can revert the crud.update deletion the way I code
that.

Thanks

Richard

On Tue, Dec 11, 2012 at 4:45 PM, Richard Vézina ml.richard.vez...@gmail.com
 wrote:

 So, it may be the reason I get internal error then. And the Niphold code
 is working. I make test.

 Richard


 On Tue, Dec 11, 2012 at 4:40 PM, Massimo Di Pierro 
 massimo.dipie...@gmail.com wrote:

 Mand that you if catch a DB exception you must revert or you cannot do
 anything else with the DB within the transaction and you end up with a
 ticket.


 On Tuesday, 11 December 2012 14:52:08 UTC-6, Richard wrote:

 I have to see if record of table2 is attached by table3 in my example,
 but in my app actually, table3 is 30 differents tables that each can refer
 to table2 entry multiple time (one to many)...

 I would prefer to do what you suggest child tables but I am afraid of
 overhead.

 Richard


 On Tue, Dec 11, 2012 at 3:32 PM, Niphlod nip...@gmail.com wrote:

 ere are records attached.


  --







-- 





Re: [web2py] Re: DB insert confusion

2012-12-11 Thread Niphlod
uhm. The problem is that even though every jsonrpc interface I worked 
with was parameter-based, for jsonrpc2 position-based and parameter-based 
are both valid.

On Tuesday, December 11, 2012 10:42:06 PM UTC+1, Jonathan Lundell wrote:

 On 11 Dec 2012, at 1:09 PM, Niphlod nip...@gmail.com javascript: 
 wrote:

 I took some time to watch at the jsonrpc specs. Right now I had experience 
 with jsonrpc only in the named parameters format. I thought it was the 
 standard, my bad. 
 However, I found out that 2.0 introduced named parameters that were not 
 supported - explicitely - in 1.0

 -- {jsonrpc: 2.0, method: subtract, params: [42, 23], id: 1}
 -- {jsonrpc: 2.0, result: 19, id: 1}

 -- {jsonrpc: 2.0, method: subtract, params: {subtrahend: 23, 
 minuend: 42}, id: 3}
 -- {jsonrpc: 2.0, result: 19, id: 3}


 are both valid.

 Maybe revert this and make a jsonrpc2 decorator to support named 
 parameters explicitely would be a better solution?


 How about both jsonrpc1 and jsonrpc2, and then jsonrpc = jsonrpc2? (I 
 think it'd be better to make v2 the default.)


 On Tuesday, December 11, 2012 9:57:50 PM UTC+1, Kurt Grutzmacher wrote:

 I don't think this is a good JSON-RPC example as the change broke our app 
 that uses simplejsonrpc or jsonrpclib to make API calls.

 Based on the jsonrpclib python module @ 
 https://code.google.com/p/jsonrpclib/ requests look like:

  import jsonrpclib
  server = jsonrpclib.Server('http://localhost:8080')
  server.add(5,6)
 11
  print jsonrpclib.history.request
 {jsonrpc: 2.0, params: [5, 6], id: gb3c9g37, method: add}
  print jsonrpclib.history.response
 {'jsonrpc': '2.0', 'result': 11, 'id': 'gb3c9g37'}


 And the JSON-RPC spec states params should be An Array of objects to 
 pass as arguments to the method. -- 
 http://json-rpc.org/wiki/specification

 However the actual spec doesn't specify array, dict or whatever as it 
 tries to be universal: A Structured value that holds the parameter 
 values to be used during the invocation of the method. This member MAY be 
 omitted.  http://www.jsonrpc.org/specification#request_object

 For simplejsonrpc and jsonrpclib to work we have to undo this change in 
 gluon/tools.py


 On Wednesday, November 14, 2012 1:25:22 PM UTC-8, Mike Anson wrote:

 Thanks very much for your help Niphlod.

 On Wednesday, 14 November 2012 16:10:35 UTC-5, Niphlod wrote:


 Yes I understand your point. The reason it is currently like this is 
 because if I use your suggestion (which I obviously had originally)

 {id: 1, method: savemessage, params: { *message*: 
 variableholdingmessage, *uid* : variableholdingmail}}

 I get message and uid as the values in the DB. So I switched them.

 {id: 1, method: savemessage, params: { 
 variableholdingmessage: mymessage, variableholdinguid : 
 myemail@localhost}}

 The result means that variableholdingmessage is saved as the message 
 and not the expected mymessage. Exactly the same for uid.

 Unfortunately jsonrpc call method has a bug. in web2py 2.2.1, in 
 gluon/tools.py, line 4231 should be 

 s = methods[method](**params)

 instead of

 s = methods[method](*params)


 sending a patch to Massimo right now!
  


 re: PS -- haha yes I know. I did try it with single quotes and it 
 crapped out?? So just kept the doubles. It's not that bad!

 re: PS2 -- have you any recommendations to solve this special 
 character potential problem?

  
 Normally with jsonrpc you use something that is not curl, e.g. a 
 programming language that supports json (python?!)
 Escaping on bash without awk, sed, etc is always problematic but if 
 you're willing to have as only limitation the  character that is less 
 frequent to use within a message, why don't you use one of the methods not 
 requiring a json body to be posted ? e.g. @service.xml, @service.csv or 
 @service.json

 curl -v --get --data-urlencode \uid=$uid\ --data-urlencode 
 \message=$message\ $url

 here curl takes care of urlencoding the message and the uid parameters.


  


 -- 
  
  
  





-- 





[web2py] new setup-web2py-nginx-uwsgi-ubuntu.sh

2012-12-11 Thread Niphlod
I run uwsgi using the emperor mode for some time now based on my config 
I tried to upgrade the existing one. Result is available at 
https://www.dropbox.com/s/n7chteos9sh6p2h/setup-web2py-nginx-uwsgi-ubuntu.sh

I'm looking forward to improve things both on uwsgi niceties and general 
bash customization (the moment I saw fabric http://fabfile.org I almost 
stopped writing bash :-P)

Improvements:
- no uwsgi from debian packages (overcomplicated configurations). uwsgi is 
installed from pip (so you can upgrade with a simple pip install --upgrade 
uwsgi)
- optional response.static_version friendly static directories 
configuration (added also cache headers as an option)
- improved syntax for web2py.xml (no app, no plugin)
- example of uwsgi cron facility (clean sessions script included)
- uwsgi emperor mode, managed with Upstart
- optional upstart pre-script command to fix permissions and compress 
static files

If interested, I can make a fabfile for that.

offtopic on I use Redis as cache but for the I love embedded guys uwsgi 
has a cache framework. I'm accepting votes to make a uwsgi's cache 
compatible module for web2py, but you will have to test it (no time for 
that, sorry)
offtopic off

-- 





Re: [web2py] How may I catch this exception class 'psycopg2.IntegrityError'

2012-12-11 Thread Massimo Di Pierro
There are some problem with this although they are not the case of your 
traceback.

- One problem is hat this allows any visitor to delete any record in any 
table. But you know that.
- The second problem is that you deleted the record you are editing on 
validation, before it gets updated. When web2py calls update_record the 
record has been deleted. I do not think the exception happens where you 
catch it. It happens later when update_record is called.

Can you explain us what is the purpose of this code?

On Tuesday, 11 December 2012 15:50:25 UTC-6, Richard wrote:

 Do I am doing right?

 def ondelete_func(form):
 try delete ondelete if database raise an error trigger a message 
 telling the user that the record can't be deleted
 import psycopg2
 try:
 db(db[request.args(0)].id==request.args(1)).delete()
 except psycopg2.IntegrityError:
 db.rollback()
 session.flash = T('The record you try to delete is still 
 referenced by other records and can\'t be deleted')

 def create_update():
 create update funciton
 form = crud.update(db[request.args(0)], request.args(1), 
 onvalidation=ondelete_func)
 return dict(form=form)

 I still get this ticket :

 class 'psycopg2.IntegrityError' ERREUR: UPDATE ou DELETE sur la table « 
 table2 » viole la contrainte de clé étrangère « fk_table3 » de la table « 
 table3 » DETAIL: La clé (id)=(2) est toujours référencée à partir de la 
 table « table3 » 


 And I am not sure how I can revert the crud.update deletion the way I code 
 that.

 Thanks

 Richard

 On Tue, Dec 11, 2012 at 4:45 PM, Richard Vézina 
 ml.richa...@gmail.comjavascript:
  wrote:

 So, it may be the reason I get internal error then. And the Niphold code 
 is working. I make test.

 Richard


 On Tue, Dec 11, 2012 at 4:40 PM, Massimo Di Pierro 
 massimo@gmail.comjavascript:
  wrote:

 Mand that you if catch a DB exception you must revert or you cannot do 
 anything else with the DB within the transaction and you end up with a 
 ticket.


 On Tuesday, 11 December 2012 14:52:08 UTC-6, Richard wrote:

 I have to see if record of table2 is attached by table3 in my example, 
 but in my app actually, table3 is 30 differents tables that each can refer 
 to table2 entry multiple time (one to many)...

 I would prefer to do what you suggest child tables but I am afraid of 
 overhead.

 Richard


 On Tue, Dec 11, 2012 at 3:32 PM, Niphlod nip...@gmail.com wrote:

 ere are records attached.


  -- 
  
  
  





-- 





Re: [web2py] Re: How to fix CRYPT differences between Windows and Linux?

2012-12-11 Thread Jonathan Lundell
On 11 Dec 2012, at 4:05 PM, JoeCodeswell joecodesw...@gmail.com wrote:
 Dear Massimo,
 
 Here's the answers.
 
 Can you try do this on both machines?
 
 webfaction
 
 $ python web2py.py -S myappNotReally -M
 web2py Web Framework
 Created by Massimo Di Pierro, Copyright 2007-2012
 Version 2.2.1 (2012-10-21 16:57:04) stable
 Database drivers available: SQLite(sqlite3), MySQL(pymysql), MySQL(MySQLdb), 
 Pos   tgreSQL(psycopg2), PostgreSQL(pg8000), 
 IMAP(imaplib)
 Python 2.7.3 (default, Jun 11 2012, 22:26:11)
 Type copyright, credits or license for more information.
 
 IPython 0.12.1
 


In [51]: webfaction = 
'pbkdf2(1000,20,sha512)$ad443a669b5729b7$b7d02805d6681f93d54e95b05611734cbdc93cf9'

In [52]: windows =
'pbkdf2(1000,20,sha512)$975228a4f2f27156$72e54a69f7fb6e1e0a209a45f4ca206d42ebedca'

If you don't specify explicit (and constant) salt, CRYPT will generate a random 
salt on each call. I'd expect you to get different values on each run, not just 
on different systems.

-- 





[web2py] Re: Login logout links drop down not working on mobile

2012-12-11 Thread Wes Hall
Find anything?

On Monday, October 8, 2012 3:03:52 AM UTC-4, lyn2py wrote:

 Per the subject line, I can click to drop down the links but I can't click 
 on them. 
 This is on production and using stable.

 May I know how to resolve? Thanks!


-- 





[web2py] how to hide a field until another field is chosen using SQLFORM.smartgrid

2012-12-11 Thread JimK
I have a table defined with many columns but some are only relevant if a 
previous one is chosen.  How would I hide a field like this 
with SQLFORM.smartgrid?

model:
db.define_table('t_schedule_frat_query',
Field('f_recurring', type='boolean', notnull=True,
  label=T('Recurring schedule?'),
Field('f_schedule_frequency', type='string',
  label=T('Schedule Frequency'),
auth.signature,
format='%(f_query_name)s',
migrate=True)

controller:
def foo():
form = SQLFORM.smartgrid(db.t_frat_query)
return locals()

view:
default view

On the webpage, t_schedule_frat_query. f_schedule_frequency should only 
show up if t_schedule_frat_query. f_recurring is checked.  How would I do 
this?


Jim

-- 





Re: [web2py] Many asked for it... Kryten is available

2012-12-11 Thread Vinicius Assef
Great! \o/

On Tue, Dec 11, 2012 at 6:25 PM, Niphlod niph...@gmail.com wrote:
 this will make audio available for ubuntu too.

 os.system('espeak -s 120 %s' %
 text.replace('','\\').replace(',\\'))

 maybe a simple check with platform.platform and if MacOS use say else
 espeak ? Or a variable that takes the binary for text2speech conversion ?


 On Tuesday, December 11, 2012 8:44:25 PM UTC+1, rochacbruno wrote:

 Thanks!

 I will use this for my nest talk!


 --




-- 





Re: [web2py] Re: How to fix CRYPT differences between Windows and Linux?

2012-12-11 Thread Massimo Di Pierro
Jonathan is right.

I forgot to ask you also set

db.auth_user.password.validators[0].salt = False

I am trying to find out if (for the same salt or no salt) you get the same 
hash. I suspect not.

On Tuesday, 11 December 2012 18:30:46 UTC-6, Jonathan Lundell wrote:

 On 11 Dec 2012, at 4:05 PM, JoeCodeswell joecod...@gmail.comjavascript: 
 wrote:

 Dear Massimo,

 Here's the answers.

 *Can you try do this on both machines?*

 *webfaction*

 $ python web2py.py -S myappNotReally -M
 web2py Web Framework
 Created by Massimo Di Pierro, Copyright 2007-2012
 Version 2.2.1 (2012-10-21 16:57:04) stable
 Database drivers available: SQLite(sqlite3), MySQL(pymysql), MySQL(MySQLdb
 ), Pos   tgreSQL(psycopg2), PostgreSQL(pg8000),IMAP
 (imaplib)
 Python 2.7.3 (default, Jun 11 2012, 22:26:11)
 Type copyright, credits or license for more information.

 IPython 0.12.1


 In [51]: webfaction = 
 'pbkdf2(1000,20,sha512)$ad443a669b5729b7$b7d02805d6681f93d54e95b05611734cbdc93cf9'

 In [52]: windows =
 'pbkdf2(1000,20,sha512)$975228a4f2f27156$72e54a69f7fb6e1e0a209a45f4ca206d42ebedca'

 If you don't specify explicit (and constant) salt, CRYPT will generate a 
 random salt on each call. I'd expect you to get different values on each 
 run, not just on different systems.


-- 





Re: [web2py] get table records using vars

2012-12-11 Thread hasan alnator
I did it like this :

*in controller :*

def index():
return locals()

def edit():
response.flash = Viewing All recordes For %s . % (request.vars.table)

# Get ALL Fields For a table Using Request.vars
dbtable=db[request.vars.table]['fields']

entries = db(db[request.vars.table].id = 0).select()
return locals()

def users():
 return locals()

def login():
form=auth.login()
return locals()

def download():

allows downloading of uploaded files
http:///[app]/default/download/[filename]

return response.download(request,db)


*in view:*

  !-- Data --
table class=table table-bordered table-striped table-hover 

!-- Table Fields --
thead
tr
{{fields = []}}
  {{for i in dbtable:}}
  th style=text-align:center{{=i}}/th
{{fields.append(i)}}
  {{pass}}
  thEdit/th
  thDelete/th
/tr
  /thead
   !-- End Of Table  Fields --


{{number = 0}}
{{for s in entries:}}
tr
{{for i in fields:}}
{{if db[request.vars.table][i].type == 'upload':}}
td style=text-align:centerimg
src={{=URL('download',args=s[i])}} width=50px height=150px//td
{{else:}}
td
style=text-align:center{{=str(s[i])[:10]}}/td
{{pass}}
{{pass}}
td style=width:70px
form method=post
action={{=URL('editrecord')}}
input type=hidden name=ID value={{=
s.id}}/
input type=hidden name=table
value={{=request.vars.table}}/
button class=btn btn-success type=submit
style=width:70px href=#i class=icon-cog/i Edit/button
/form
/td
td style=width:90px
form method=post
action={{=URL('deleterecord')}}
input type=hidden name=ID value={{=
s.id}}/
input type=hidden name=table
value={{=request.vars.table}}/
button class=btn btn-danger type=submit
style=width:90pxi class=icon-remove/i Delete/button
/form
/td


{{number = number + 1}}
   /tr
{{pass}}

   tbody
/tbody
/table


Best Regards,



On Tue, Dec 11, 2012 at 5:36 PM, tomasz bandura tomasz.band...@gmail.comwrote:

 Ok,

 To complete my example: You should define two tables (db.py)

 db.define_table('tag',Field('name',length=16),format='%(name)s')
 db.define_table('entry',
  Field('title',length=64),
 # (...) some other fields
 Field('tags','list:reference tag'))



 2012/12/11 hasan alnator halna...@gardeniatelco.com

 type 'exceptions.AttributeError' 'DAL' object has no attribute 
 'entry'VERSION
 web2py™ (2, 1, 1, datetime.datetime(2012, 10, 15, 12, 44, 40), 
 'stable')PythonPython
 2.7.3: C:\Python27\python.exe TRACEBACK

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

 Traceback (most recent call last):
   File C:\web2py\gluon\restricted.py, line 209, in restricted


 exec ccode in environment
   File C:/web2py/applications/A3rasna_latestshop/controllers/admin.py 
 http://127.0.0.1:8000/admin/default/edit/A3rasna_latestshop/controllers/admin.py,
  line 22, in module


   File C:\web2py\gluon\globals.py, line 187, in lambda


 self._caller = lambda f: f()


   File C:/web2py/applications/A3rasna_latestshop/controllers/admin.py 
 http://127.0.0.1:8000/admin/default/edit/A3rasna_latestshop/controllers/admin.py,
  line 12, in edit


 entries = 
 db(db.entry.tags.contains(request.vars.table)).select(db.entry.ALL)


   File C:\web2py\gluon\dal.py, line 7150, in __getattr__


 return ogetattr(self, key)

 AttributeError: 'DAL' object has no attribute 'entry'

   --





  --





-- 





[web2py] Re: Code changes not honored (by web2py?)

2012-12-11 Thread Chr_M
Python 2.7.3
Web2py 2.2.1

The situation:

In modules directory I have a subdirectory with two files class1.py and 
class2.py. This is a package (empty __init__.py is present). class2.py 
imports class1.py and Class2 inherits from Class1. My controller 
dynamically imports class2 with the function __import__(class2). On top of 
my db.py model I call the track_changes part. The modules do not seem to be 
updated if I change code in class1.py or class2.py.

I have solved it for now by reloading all the modules with reload() after I 
import them. So after I dynamically import class2 in my controller I call 
reload(class2). In class2.py after the import of class1 I call 
reload(class1). This is the only way I get the code changes to work in both 
files.

It seems that the track_changes part is not working in this situation or 
something? Or is there another solution?

Regards, Chris


On Monday, December 10, 2012 4:34:33 PM UTC+1, Massimo Di Pierro wrote:

 It should work when you do it.

 Which python version? Which web2py version?

 On Monday, 10 December 2012 02:57:20 UTC-6, Chr_M wrote:

 I call this function at the top of my db.py model file. Is this not the 
 correct location?

 Regards, Chris


 On Sunday, December 9, 2012 11:55:06 PM UTC+1, Massimo Di Pierro wrote:

 This has come up before.

 from gluon.custom_import import track_changes; track_changes()

 must be a model file, before the modules are imported, not in the 
 modules themselves which are otherwise cached and therefore the line may or 
 may not be executed.

 Massimo

 On Sunday, 9 December 2012 15:34:09 UTC-6, Chr_M wrote:

 Sometimes the changes in the code of a module (in the modules 
 directory) are not working when requesting the url that uses these 
 modules. 
 in the modules directory I have a subdirectory with python files that form 
 a package (__init__.py file in this subdirectory). I have added 

 from gluon.custom_import import track_changes
 track_changes()

 in the first model that gets called, but still sometimes code changes 
 are not working. I noticed that the py-files in the modules dir get 
 compiled to pyc-files. But at one point (it looks to be randomly) these 
 are 
 not compiled anymore when I change code in the py-files. But even when I 
 remove these pyc-files, the code changes are still not working when 
 requesting the url. 

 Am I missing something? Is there a cache I can clear or something? I 
 now have to restart web2py to make the code changes work...

 Thanks.

 Regards, Chris



--