[web2py] Re: Include another file, but do not process it

2015-02-16 Thread Daniel Gonzalez
Thanks Anthony, looks like a good solution.

On Sunday, February 15, 2015 at 2:35:23 AM UTC+1, Anthony wrote:

 Maybe something like this:

 In a model file or module:

 def include_hbs(view_path):
 import os
 response.write(open(os.path.join(request.folder, 'views', view_path), 
 'rb').read(),
escape=False)

 In the view:

 {{include_hbs('dashboard.hbs')}}

 You might also add an option to cache in RAM for some period of time.

 Anthony

 On Saturday, February 14, 2015 at 6:42:38 AM UTC-5, Daniel Gonzalez wrote:

 Hi,

 This is my use case: I have some web2py templates which are serving some 
 views with embedded handlebar templates, which are intended for processing 
 on the client side: they must arrive untouched to the browser.
 The problem is that handlebars and web2py have by default the same 
 delimiters: {{ }}

 I can change these default settings for either web2py or handlebars, but 
 this has some unintended consequences. For example, I need to go around 
 configuring tools to understand these changes, like code highlighters 
 (web-mode in emacs, etc) which is not always obvious / possible to do.

 So, I would prefer to stick to the default delimiters. What I would like 
 is something like this:

 !-- my-view.html: web2py / html code --

 ...

 {{include 'dashboard.hbs'}}


 !-- dashboard.hbs: handlebars stuff --


 {{sdfsdf}}

 But I would like the web2py engine not to process dashboard.hbs, and 
 serve it as-is.
 Web2py could make this decision based on the extension of the file (do 
 not process .hbs files) or with a flag to disable processing for a 
 specific include: {{include 'dashboard.hbs' dont-process}}
 Is this implemented? I have found no documentation regarding the web2py 
 include statement (there is documentation scattered around the guide, but 
 nothing specific as far as I can see).

 Thanks!
 DanG



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


[web2py] Include another file, but do not process it

2015-02-14 Thread Daniel Gonzalez
Hi,

This is my use case: I have some web2py templates which are serving some 
views with embedded handlebar templates, which are intended for processing 
on the client side: they must arrive untouched to the browser.
The problem is that handlebars and web2py have by default the same 
delimiters: {{ }}

I can change these default settings for either web2py or handlebars, but 
this has some unintended consequences. For example, I need to go around 
configuring tools to understand these changes, like code highlighters 
(web-mode in emacs, etc) which is not always obvious / possible to do.

So, I would prefer to stick to the default delimiters. What I would like is 
something like this:

!-- my-view.html: web2py / html code --

...

{{include 'dashboard.hbs'}}


!-- dashboard.hbs: handlebars stuff --


{{sdfsdf}}

But I would like the web2py engine not to process dashboard.hbs, and serve 
it as-is.
Web2py could make this decision based on the extension of the file (do not 
process .hbs files) or with a flag to disable processing for a specific 
include: {{include 'dashboard.hbs' dont-process}}
Is this implemented? I have found no documentation regarding the web2py 
include statement (there is documentation scattered around the guide, but 
nothing specific as far as I can see).

Thanks!
DanG

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


[web2py] define_table does not create table in database

2014-10-30 Thread Daniel Gonzalez
I am running `define_tables` in the recommended way:

db = DAL('postgres://user:@localhost:5432/mydb', 
migrate_enabled=False, auto_import=False, lazy_tables=True)
db.define_table('auth_user',
Field('email', unique=True),
Field('password', length=512, type='password', readable=False, 
label='Password'),
...)

This gets executed without errors, but no table is created in the database. 
Whenever I try to insert a new user:

relation auth_user does not exist

What can be going on? Once the tables are created (manually, for example), 
the application works fine. I am using a postgres backend. This happens no 
matter what value I give to `lazy_tables`

EDIT


This is the full test script:

from gluon import DAL
from gluon import Field

db = DAL('postgres://user:pass@localhost:5432/mydb', 
migrate_enabled=False)

db.define_table(
'auth_user',
Field('email',  type='string', unique=True),
Field('password',   type='password'),
Field('registration_key',   type='string',   length=512, 
writable=False, readable=False, default=''),
Field('reset_password_key', type='string',   length=512, 
writable=False, readable=False, default=''),
Field('registration_id',type='string',   length=512, 
writable=False, readable=False, default=''),
)
db.commit()

print db.tables

db.auth_user.insert(email='g@b.c')

And I get the following output:

['auth_user']
Traceback (most recent call last):
  File xxx.py, line 19, in module
db.auth_user.insert(email='g@b.c')
  File /tmp/web2py/gluon/dal.py, line 9293, in insert
ret =  self._db._adapter.insert(self, self._listify(fields))
  File /tmp/web2py/gluon/dal.py, line 1361, in insert
raise e
psycopg2.ProgrammingError: relation auth_user does not exist
LINE 1: INSERT INTO auth_user(reset_password_key,registration_id,reg...

The table is somehow created (in memory?), but it is not really in the 
postgres database. What does this mean?

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


[web2py] Re: define_table does not create table in database

2014-10-30 Thread Daniel Gonzalez
Thanks for your reply,

Migrate is not the problem: it does not matter if I do 
migrate_enabled=False or migrate_enabled=True.
Besides, there is no table to migrate. That is the whole problem: 
define_table does not create the table!

I am doing my own define_table because I have need to trigger some other 
code whenever new users are created (not shown here)

Why does db.tables show that the table is created, when it is not? 
(verified with pgadmin)

BR,
Daniel

On Thursday, October 30, 2014 11:49:25 AM UTC+1, Leonel Câmara wrote:

 Well the tables are lazy, but that shouldn't cause your problem because 
 once you use them they really get defined. May I ask why you are defining 
 your own user table instead of using auth.define_tables()?

 Anyway, your problem is caused by migrate_enabled=False.


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


[web2py] Re: define_table does not create table in database

2014-10-30 Thread Daniel Gonzalez
One more thing: you mention tables are lazy, but the documentation says 
they are lazy only whenever DAL(...,lazy_tables=True) is set (DAL 
documentation 
http://www.web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#DAL-constructor
)
Which one is right?


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


[web2py] Re: define_table does not create table in database

2014-10-30 Thread Daniel Gonzalez
Getting closer to identifying my problem. It seems I am having several 
problems at once.

First, it seems that migrate_enabled=False prevents not only migrations, 
but also table creation (am I right here?)

Second: while trying to guess the problems with my application, I am using 
 the  test script provided. Running manually that script, and at the same 
time working with pgadmin (that is, manually creating / droping 
databases/tables), causes serious conflicts with web2py. It seems web2py 
has its own caching mechanism on the file system for the table definitions 
(pickled objects?)

I have now clarified that, and to mitigate those problems I am doing: 
1. drop database, remove pickled files, restart web2py
2. Do not use lazy_tables and enable migrations (this ensures that the 
tables will be created exactly on the call to define_tables)
3. Call .commit(). I have the code to define_tables outside in a module, 
and according to the manual, no autocommit is performed for modules. The 
reason I am doing this is that I want to be able to reuse the same code 
from outside my web2py application, for maintenance/reporting purposes: I 
have a library with all web2py related functionality, which I can call from 
the web2py application itself, or simply from an external script.

But still, I see a problem: I can see clearly in the sql.log file that my 
define_table creates the table as I want, but immediately after, 
auth.define_tables() modifies that table: drops my fields, adds the 
standard auth fields.

According to the manual 
(http://web2py.com/books/default/chapter/29/9#Customizing-Auth):

If a table is declared beforeauth.define_tables() it is used instead of the 
default one

I would expect that Auth sees that auth_user is already defined, skip the 
definition of that table, and define the other auth tables. But in my case 
it seems auth is overwrriting the table defintion. Why can this be?

BR,
Daniel


On Thursday, October 30, 2014 1:04:27 PM UTC+1, Anthony wrote:

 On Thursday, October 30, 2014 7:41:07 AM UTC-4, Leonel Câmara wrote:

 Well lazy_tables=True is the default.


 Actually, it does default to False, but that's not the issue here.

 Anthony 


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


[web2py] Re: define_table does not create table in database

2014-10-30 Thread Daniel Gonzalez
I have solved my problem. I was not properly reusing the db (DAL object) in 
my library. Instead, a new DAL connection was being created in some cases. 
Therefore, even though the tables were defined at the pyhton level, auth 
was not really aware of it, and was trying to redefine them.

Facit: make sure that a single db object is used in the models and in any 
external modules.

Thanks for your assistance!
Daniel Gonzalez

On Thursday, October 30, 2014 4:29:26 PM UTC+1, Daniel Gonzalez wrote:

 Getting closer to identifying my problem. It seems I am having several 
 problems at once.

 First, it seems that migrate_enabled=False prevents not only migrations, 
 but also table creation (am I right here?)

 Second: while trying to guess the problems with my application, I am using 
  the  test script provided. Running manually that script, and at the same 
 time working with pgadmin (that is, manually creating / droping 
 databases/tables), causes serious conflicts with web2py. It seems web2py 
 has its own caching mechanism on the file system for the table definitions 
 (pickled objects?)

 I have now clarified that, and to mitigate those problems I am doing: 
 1. drop database, remove pickled files, restart web2py
 2. Do not use lazy_tables and enable migrations (this ensures that the 
 tables will be created exactly on the call to define_tables)
 3. Call .commit(). I have the code to define_tables outside in a module, 
 and according to the manual, no autocommit is performed for modules. The 
 reason I am doing this is that I want to be able to reuse the same code 
 from outside my web2py application, for maintenance/reporting purposes: I 
 have a library with all web2py related functionality, which I can call from 
 the web2py application itself, or simply from an external script.

 But still, I see a problem: I can see clearly in the sql.log file that my 
 define_table creates the table as I want, but immediately after, 
 auth.define_tables() modifies that table: drops my fields, adds the 
 standard auth fields.

 According to the manual (
 http://web2py.com/books/default/chapter/29/9#Customizing-Auth):

 If a table is declared beforeauth.define_tables() it is used instead of 
 the default one

 I would expect that Auth sees that auth_user is already defined, skip the 
 definition of that table, and define the other auth tables. But in my case 
 it seems auth is overwrriting the table defintion. Why can this be?

 BR,
 Daniel


 On Thursday, October 30, 2014 1:04:27 PM UTC+1, Anthony wrote:

 On Thursday, October 30, 2014 7:41:07 AM UTC-4, Leonel Câmara wrote:

 Well lazy_tables=True is the default.


 Actually, it does default to False, but that's not the issue here.

 Anthony 



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


Re: [web2py] Re: Proposal: create namespaces for translation system

2013-09-23 Thread Daniel Gonzalez Zaballos
The idea is exactly for this. To have separated localized components. I
hope that in a few weeks/months we can release something that we are
working on components. I cannot say to much now :)


2013/9/23 Massimo Di Pierro massimo.dipie...@gmail.com

 I was skeptical but I have been convinced this is an excellent idea. Your
 patch is going to trunk now. Thank you!


 On Monday, 23 September 2013 02:13:10 UTC-5, jamarcer wrote:

 Hello:

 I'm Demetrio's mate, and he asked me to upgrade the T with namespaces
 functionality into trunk (Version 2.6.3-stable+timestamp.2013.**
 09.18.14.36.14).

 I have added a comment into 1196 issue with a code patch and a
 explanation.

 https://code.google.com/p/**web2py/issues/detail?id=1196https://code.google.com/p/web2py/issues/detail?id=1196

 I hope it will be usefull.

 Best regards.

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


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


Re: [web2py] Re: Proposal: create namespaces for translation system

2013-09-02 Thread Daniel Gonzalez Zaballos
Hello Massimo,

We'll try to have it at the end of the month. We had applied it to
production and is a 1.99.7 version and the trunk version has changed a lot.

One question, what do you mean with use . instead of app_name?

Regards


2013/9/1 Massimo Di Pierro massimo.dipie...@gmail.com

 Hello Demetrio,

 sorry for the late response. Could you please resend your patch, make sure
 it applies to trunk, and use . instead of app_name?


 On Thursday, 29 November 2012 06:17:22 UTC-6, demetrio wrote:

 Hi everyone I post a reply in the web3py thread in this mailing list
 asking for a site where make a wishlist, but thinking about what I would
 want in web3py, I realized that I needed in web2py already so I have
 make a patch for the actual translation system in the gluon/languages.py
 file.

 One of the lacks that I see in the translation system is that is a
 little difficult to maintain the language file in large applications
 like the one I am developing at this moment. Think about modules that
 you can plug or unplug of your application, and each have their own
 strings, or something more common, the pluggin system.

 Actually if you want to install a plugin like plugin_wiki you have to do
 your own translation because you cannot insert translation files (if
 actually web2py supports this... do it I don't know how to make it xD).
 It would be great to have a community where you can make plugins and add
 the language files inside.

 This is what makes the patch:

 Allows to use a namespace parameter in the T() like this

 T(Hello World, namespace=plugin_wiki)

 So in the languages/ folder will appear this:

 - languages/
 - en_en.py
 - plugin_wiki/
 - en_en.py

 so if you use T(Hello World, namespace=plugin_wiki) it will go to
 find the string into languates/plugin_wiki/*your_**lang*.py and if you
 use
 the common way T(Hello World) it will go as always to
 languages/*your_lang*.py

 I haven't tested it enough but it works for me at now, and I haven't
 written the part for the admin interface where you can push the button
 for refreshing the lang files (I don't get on wiht the RegExp at all)

 My 2 cents
 I hope that I can send the patch to the list

  --

 ---
 You received this message because you are subscribed to the Google Groups
 web2py-users group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to web2py+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.


-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[web2py] Catch-all function in controller

2013-06-26 Thread Daniel Gonzalez
Hi,

I have an api.py module which is the interface to my restful api. Currently 
I have to do the following to extend my api:

def common(obj):
response.view = 'generic.json'

response.headers['Content-Type'] = CONTENT_TYPE_JSON
def GET(*args,**vars):

return api_router(API_GET, obj, *args, **vars)
def POST(*args,**vars):
return api_router(API_POST, obj, *args, **vars)
def PUT(*args,**vars):
return api_router(API_PUT, obj, *args, **vars)
def DELETE(*args, **vars):
return api_router(API_DELETE, obj, *args, **vars)
return dict(GET=GET, POST=POST, PUT=PUT, DELETE=DELETE)


@request.restful()
def index():
return common('root')


@request.restful()
def nodes():
return common('nodes')


@request.restful()
def agents():
return common('agents')
...


For any new object that I want to offer via my api, I need to list it as 
@request.restful funcion, and link to common (the common api 
implementation). I would like to define this common function as the 
catch-all restful function for my api. My api_router already knows which 
objects are supported, and replies with 404 if a requested object is not 
supported, so it makes no sense for me to be forced to do this again on the 
controller.

How can I define this catch-all function in my api controller?

Thanks,
Daniel

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] URL for static assets produces wrong value?

2013-05-30 Thread Daniel Gonzalez
Hi,

I have a strange use case, which is maybe not covered by the router / URL 
implementation.

I have just started using a second application, and I have modified my 
routes.py:

routes_in = (
('/admin(?Pany.*)',   '/admin\gany'),
('/app1(?Pany.*)','/app1\gany'),
('/(?Pany.*)','/app2/\gany'),
)
routes_out = (
('/admin(?Pany.*)',  '/\gany'),
('/app1(?Pany.*)',   '/\gany'),
('/app2/(?Pany.*)',  '/\gany'),
)

(app2 is my default app, which should be accessible at the root of the url)

In my app1 I am doing something like this:

URL('static','images/image01.png')

And I was expecting a url like: /app1/static/images/image01.png

Instead, I am getting: //static/images/image01.png

So the application part is skipped. Is this normal? Can I solve this 
problem somehow?

Thanks,
Daniel

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: URL for static assets produces wrong value?

2013-05-30 Thread Daniel Gonzalez
Oos. Sorry, sorry, sorry. My bad. My router rules had an slash too 
many. Here are the correct ones:

routes_in = (
('/admin(?Pany.*)',   '/admin\gany'),
('/app1(?Pany.*)','/app1\gany'),
('/(?Pany.*)','/app2/\gany'),
)
routes_out = (
('/admin(?Pany.*)',  '\gany'),
('/app1(?Pany.*)',   '\gany'),
('/app2/(?Pany.*)',  '/\gany'),
)

And that works. Sorry again.

On Thursday, May 30, 2013 8:12:26 PM UTC+2, Daniel Gonzalez wrote:

 Hi,

 I have a strange use case, which is maybe not covered by the router / URL 
 implementation.

 I have just started using a second application, and I have modified my 
 routes.py:

 routes_in = (
 ('/admin(?Pany.*)',   '/admin\gany'),
 ('/app1(?Pany.*)','/app1\gany'),
 ('/(?Pany.*)','/app2/\gany'),
 )
 routes_out = (
 ('/admin(?Pany.*)',  '/\gany'),
 ('/app1(?Pany.*)',   '/\gany'),
 ('/app2/(?Pany.*)',  '/\gany'),
 )

 (app2 is my default app, which should be accessible at the root of the url)

 In my app1 I am doing something like this:

 URL('static','images/image01.png')

 And I was expecting a url like: /app1/static/images/image01.png

 Instead, I am getting: //static/images/image01.png

 So the application part is skipped. Is this normal? Can I solve this 
 problem somehow?

 Thanks,
 Daniel


-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Support for internationalization in web2py wiki

2013-05-29 Thread Daniel Gonzalez
In the same way as internationalization is handled in the T operator? That 
means that an accept-language: it- it would tell the wiki engine to look 
for pages corresponding to the URL which are marked in the database as 
being in italian. That means:

   1. a new field is needed in the database to mark the language the page 
   is written in
   2. the wiki engine would select that page
   3. a fall back mechanism would return a page in a default language 
   (english?)
   4. when creating new wiki entries, the support views would offer a 
   drop-down to specifiy the language in which the page is being created 
   (which would default to the accept-language setting)
   

On Tuesday, May 28, 2013 10:29:27 PM UTC+2, Massimo Di Pierro wrote:

 There is not. The problem is that normal internationalization libraries 
 are not appropriate for wiki pages. I would recommended using different 
 pages for different languages. In your opinion, how should 
 internationalization for wiki pages work?

 On Tuesday, 28 May 2013 14:35:21 UTC-5, Daniel Gonzalez wrote:

 Hi,

 I have started to use the web2py wiki module, but can not find any 
 support for internationalization of the wiki pages. What I would like is to 
 be able to select the language based on some query parameters or some 
 configuration parameters. Of course, the pages must be already be saved in 
 the desired language.

 Is there any support for this built-in?

 Thanks,
 Daniel



-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Strategies to select the preferred language

2013-05-29 Thread Daniel Gonzalez
Hi,

According to the 
documentationhttp://web2py.com/books/default/chapter/29/04#Internationalization,-and-Pluralization-with-T,
 
the T operator works based on the Accept-Language setting. In my 
experience, this is quite cumbersome for a user to set-up (I have not even 
succeeded in setting this up in Chrome), so I would prefer to rely on 
offering the user a limited set of available languages for my web 
application, in the form of a menu, or maybe a profile setting.

For users without profile (i.e. not logged in), I would like to persist 
this setting across requests. How could I do this?

What are the strategies being used by others offering pages in multiple 
languages?

Thanks,
Daniel

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Strategies to select the preferred language

2013-05-29 Thread Daniel Gonzalez
You are right. I guess I am having trouble myself because I *am* trying to 
force the language (which is something a user will not do. since they are 
happy with the default browser setting). And I have just found this piece 
of code in admin:

{{if hasattr(T,'get_possible_languages_info'):}}
- {{=T('Admin language')}}/span
select name=adminlanguage onchange=var date = new 
Date();cookieDate=date.setTime(date.getTime()+(100*24*60*60*1000));document.cookie='adminLanguage='+this.options[this.selectedIndex].id+';
 
expires='+cookieDate+'; path=/';window.location.reload()
{{for langinfo in sorted([(code,info[1]) for code,info 
in T.get_possible_languages_info().iteritems() if code != 'default']):}}
option {{=T.accepted_language==langinfo[0] and 
'selected' or ''}} {{='id='+langinfo[0]}} {{=langinfo[1]}}/option
{{pass}}
/select
{{else:}}
/span{{pass}}

And the model:

# set the language
if 'adminLanguage' in request.cookies and not (request.cookies[
'adminLanguage'] is None):
T.force(request.cookies['adminLanguage'].value)

Let me get this straight: a cookie adminLanguage is set with 100 days 
expiration date. This cookie is then accessible via request. Sounds simple 
enough, I guess I can reuse this. I do not get the select part, but I 
guess is just boilerplate to create the options and force a reload of the 
page when a selection is performed.

On Wednesday, May 29, 2013 9:06:56 AM UTC+2, Niphlod wrote:

 ? never had issues with users  usually they download the browser with 
 the language they're in. 
 BTW, forcing a language using a session variable is not hard at all in 
 web2py.

 Il giorno mercoledì 29 maggio 2013 09:00:05 UTC+2, Daniel Gonzalez ha 
 scritto:

 Hi,

 According to the 
 documentationhttp://web2py.com/books/default/chapter/29/04#Internationalization,-and-Pluralization-with-T,
  
 the T operator works based on the Accept-Language setting. In my 
 experience, this is quite cumbersome for a user to set-up (I have not even 
 succeeded in setting this up in Chrome), so I would prefer to rely on 
 offering the user a limited set of available languages for my web 
 application, in the form of a menu, or maybe a profile setting.

 For users without profile (i.e. not logged in), I would like to persist 
 this setting across requests. How could I do this?

 What are the strategies being used by others offering pages in multiple 
 languages?

 Thanks,
 Daniel



-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Strategies to select the preferred language

2013-05-29 Thread Daniel Gonzalez
And a final question: since I will only be supporting a handful of 
languages (english, german and italian) I would like to set the current 
languages. I have found T.set_current_languages. Is this the right function 
to set the supported languages? Is there an example somewhere on how to use 
this function?

I would go with something like: T.set_current_languages(['en', 'it', 'de']) 
in my model, but I am not sure that is the right way to use it.
I have tried (in models/0.py):

T.set_current_languages(['it', 'de', 'en'])

But I get:

type 'exceptions.IOError' [Errno 2] No such file or directory: 
/xxx/applications/example/languages/en-us.py'

I also get that if I remove 'en': T.set_current_languages(['it', 'de'])

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Missing ASIDE tag in web2py gluon

2013-05-29 Thread Daniel Gonzalez
The ASIDE http://www.w3schools.com/tags/tag_aside.asp helper (HTML5) is 
missing in gluon (using web2py 2.7.4). Useful to do something like this: 
http://purecss.io/layouts/gallery/

I have defined it in terms of DIV: 

class ASIDE(DIV):

tag = 'aside'

And works for me. I am not sure if gluon is supposed to implement all 
possible html tags, or if only a selected few are provided.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Support for internationalization in web2py wiki

2013-05-28 Thread Daniel Gonzalez
Hi,

I have started to use the web2py wiki module, but can not find any support 
for internationalization of the wiki pages. What I would like is to be able 
to select the language based on some query parameters or some configuration 
parameters. Of course, the pages must be already be saved in the desired 
language.

Is there any support for this built-in?

Thanks,
Daniel

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Create URL with embedded json object

2013-05-17 Thread Daniel Gonzalez
Hi,

In one of my views I am creating a table. During table creation time I have 
some dictionaries that I want to return as json objects. So in column 
data I want to provide a link to download this json objects. These 
objects are not stored anywhere (they are dinamically created), and are 
thus only known during the table instantiation time.

Is it possible to do something like this:

my_link = A(URL(data))

So that clicking the link will not perform an access to the web2py (no 
controller needs to be accessed, the data is already in the URL), but just 
show the json data?

Thanks,
Daniel

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Handling OPTIONS request in a web2py RESTful API

2013-05-10 Thread Daniel Gonzalez
Hi,

I have implemented a RESTful api in web2py which handle the usual GET, 
POST, PUT, DELETE. (using @request.restful())
Is there a standard mechanism in web2py to implement OPTIONS requests?

Thanks,
Daniel

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [web2py] Re: track_changes bug or feature?

2013-04-08 Thread Daniel Gonzalez Zaballos
Thanks! I said it because restarting the server with every little change in
a development environment, is a little weird. I'll change some imports to
make them inside methods.


2013/4/6 Massimo Di Pierro massimo.dipie...@gmail.com

 This is intended. classone is importend once and it imports classtwo. This
 happens only once before http requests arrive. Python caches modules.

 track changes only affect import done explicitly at runtime (when http
 requests are processed).

 Changing this would require that web2py keep track of all dependencies
 (who import who). This would slow down everything.

 Massimo


 On Monday, 25 March 2013 09:55:19 UTC-5, demetrio wrote:

 Hi everyone,

 I have notice an strange behaviour of the track_changes feature (working
 on web2py 2.3.2 and python 2.7.3).

 Imagine the following structure:

 modules/
 ├── classone.py
 ├── __init__.py
 └── mymodule
 ├── classtwo.py
 └── __init__.py

 (assuming that there is a models/0.py file with the track_changes(True)
 statement)

 In the file classone.py I have the following:
 #=**=
 #!/usr/bin/env python
 # coding: utf8
 from gluon import *
 *from mymodule.classtwo import ClassTwo*

 class ClassOne(object):
 def say_something(self):
 classtwo = ClassTwo()
 return classtwo.say_something()
 #=**=

 And in classtwo.py this:
 #=**=
 #!/usr/bin/env python
 # coding: utf8
 from gluon import *

 class ClassTwo(object):
 def say_something(self):
 return Hi!
 #=**=

 In this case, the changes inside ClassTwo are not tracked, but if I
 change class one to:

 #=**=
 #!/usr/bin/env python
 # coding: utf8
 from gluon import *

 class ClassOne(object):
 def say_something(self):
 *from mymodule.classtwo import ClassTwo*
 classtwo = ClassTwo()
 return classtwo.say_something()
 #=**=

 Now it works correctly and all the changes are tracked, notice that now
 the import statement is inside of a method.

 In the first case, the custom_importer() function is only called at the
 first execution to import ClassTwo, but in the second case,
 custom_importer its called in all executions.

 I have made an example application with this issue attached to this mail.

 Is this intended or it is a bug?

 greetings, Daniel.

  --

 ---
 You received this message because you are subscribed to the Google Groups
 web2py-users group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to web2py+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.




-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Access data in PUT request for @request.restful()

2013-04-03 Thread Daniel Gonzalez
Sorry to come back to this after two weeks (was busy with other stuff). I 
am trying to access the post_vars, but they are emtpy (Storage {})
My PUT request body is coming from an emberjs client, and looks like this 
(this is just test data):

{node:{type:voicemenu,name:sdfsfd,outputs:{jumpIfBusy:null,startnode:null,jumpIfNoAnswer:null,exten:null},properties:{record:null,multilocator:null,locator:null}}}

But this data is not in post_vars. I do not understand very well what you 
mean by:

basically request.post_vars are the variables in body whether it is PUT or 
POST or other.

I do not have variables in the body, I have json data. This should be 
parsed as json. Should I do it manually, or is @request.restful() doing 
that automatically? (I can not see it in the code).

Thanks,
Daniel

On Friday, March 22, 2013 6:02:32 AM UTC+1, Massimo Di Pierro wrote:

 if request.env.request_method=='POST':
 put_vars = request.post_vars

 basically request.post_vars are the variables in body whether it is PUT 
 or POST or other.



 On Thursday, 21 March 2013 19:10:27 UTC-5, Daniel Gonzalez wrote:

 Hi,

 How can I access the data in the PUT request? (in the body of the request)
 Can this be automatically parsed (my data is JSON)

 Thanks,
 Daniel



-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Access data in PUT request for @request.restful()

2013-04-03 Thread Daniel Gonzalez
I see. So I assume I will have to parse the json myself.
I wonder if after @request.restful() has done its job, I can still access 
the body.
I need to parse the json data, but maybe the body is already consumed ...

On Wednesday, April 3, 2013 9:24:47 AM UTC+2, Niphlod wrote:

 the restful part parses the data as web2py does, so accepts form/* encoded 
 parameters... it doesn't parse json in the body.

 On Wednesday, April 3, 2013 8:19:04 AM UTC+2, Daniel Gonzalez wrote:

 Sorry to come back to this after two weeks (was busy with other stuff). I 
 am trying to access the post_vars, but they are emtpy (Storage {})
 My PUT request body is coming from an emberjs client, and looks like this 
 (this is just test data):


 {node:{type:voicemenu,name:sdfsfd,outputs:{jumpIfBusy:null,startnode:null,jumpIfNoAnswer:null,exten:null},properties:{record:null,multilocator:null,locator:null}}}

 But this data is not in post_vars. I do not understand very well what you 
 mean by:

 basically request.post_vars are the variables in body whether it is PUT 
 or POST or other.

 I do not have variables in the body, I have json data. This should be 
 parsed as json. Should I do it manually, or is @request.restful() doing 
 that automatically? (I can not see it in the code).

 Thanks,
 Daniel

 On Friday, March 22, 2013 6:02:32 AM UTC+1, Massimo Di Pierro wrote:

 if request.env.request_method=='POST':
 put_vars = request.post_vars

 basically request.post_vars are the variables in body whether it is PUT 
 or POST or other.



 On Thursday, 21 March 2013 19:10:27 UTC-5, Daniel Gonzalez wrote:

 Hi,

 How can I access the data in the PUT request? (in the body of the 
 request)
 Can this be automatically parsed (my data is JSON)

 Thanks,
 Daniel



-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Access data in PUT request for @request.restful()

2013-03-22 Thread Daniel Gonzalez
Thanks Massimo,

I realize now that those variables are also in **vars (request.restful 
interfacehttp://www.web2pyslices.com/slice/show/1533/restful-api-with-web2py
)
I wonder how conflicts between query parameters and body parameters are 
resolved.

BR,
Daniel

On Friday, March 22, 2013 6:02:32 AM UTC+1, Massimo Di Pierro wrote:

 if request.env.request_method=='POST':
 put_vars = request.post_vars

 basically request.post_vars are the variables in body whether it is PUT 
 or POST or other.



 On Thursday, 21 March 2013 19:10:27 UTC-5, Daniel Gonzalez wrote:

 Hi,

 How can I access the data in the PUT request? (in the body of the request)
 Can this be automatically parsed (my data is JSON)

 Thanks,
 Daniel



-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Access data in PUT request for @request.restful()

2013-03-21 Thread Daniel Gonzalez
Hi,

How can I access the data in the PUT request? (in the body of the request)
Can this be automatically parsed (my data is JSON)

Thanks,
Daniel

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Call a function at the end of every request

2013-03-14 Thread Daniel Gonzalez
Hi,

For some tests that I am performing, I would like to call a function 
request_processed() (defined in a model, for example), at the end of 
every request.

1. Is this possible? How?
2. Is it possible to also call this function in case no controller was 
found to serve the request?

Thanks,
Daniel

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Call a function at the end of every request

2013-03-14 Thread Daniel Gonzalez
And:

3. Is it possible to call this function also for jsonrpc requests?

On Thursday, March 14, 2013 11:00:13 AM UTC+1, Daniel Gonzalez wrote:

 Hi,

 For some tests that I am performing, I would like to call a function 
 request_processed() (defined in a model, for example), at the end of 
 every request.

 1. Is this possible? How?
 2. Is it possible to also call this function in case no controller was 
 found to serve the request?

 Thanks,
 Daniel


-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Call a function at the end of every request

2013-03-14 Thread Daniel Gonzalez
And (I am discovering some effects during testing):

4. Is it possible to call this function *after* the templates have been 
rendered?

On Thursday, March 14, 2013 11:09:51 AM UTC+1, Daniel Gonzalez wrote:

 And:

 3. Is it possible to call this function also for jsonrpc requests?

 On Thursday, March 14, 2013 11:00:13 AM UTC+1, Daniel Gonzalez wrote:

 Hi,

 For some tests that I am performing, I would like to call a function 
 request_processed() (defined in a model, for example), at the end of 
 every request.

 1. Is this possible? How?
 2. Is it possible to also call this function in case no controller was 
 found to serve the request?

 Thanks,
 Daniel



-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Call a function at the end of every request

2013-03-14 Thread Daniel Gonzalez
Are you suggesting something like this (which is what I am currently doing):

In my model I define a decorator:

def finish_request(fn, *args, **kwargs):
def wrapped():
res = fn(*args, **kwargs)
do_whatever_after_the_request_has_been_processed()
return res
return wrapped

And then in my controller:

@finish_request
@auth.requires_login()
def index():
return Hello



On Thursday, March 14, 2013 11:48:48 AM UTC+1, Niphlod wrote:

 let's dive it into  I don't think there's an integrated way to do it, 
 rather than decorating your function with something else.
 Please note that as far as I know (but I may be totally wrong) you can't 
 actually return from a function (so it gets rendered and transferred to the 
 client) and continue your computationi.e. if you have return 'abcd' to 
 ship 'abcd' to the client, execution stops there.
 So, assuming that you are fine with, e.g.
 def func():
  result = 'abcd'
  .some lengthy after callback
  return result

 I'd say it's definitely doable.
 If I remember correctly, there's only one handy shortcut available without 
 starting toying with decorators response.custom_commit that can be a 
 callable and gets called at the end of every request (before returning the 
 results) 

 PS: if the thing to do after callback is fine if executed 
 asynchronously, you can set up a queue of things to do to be processed 
 afterwards.

 PS2: to kick in after the rendering you must return the compiled template, 
 e.g.
 result = response.render(...)
 ...some lengthy after callback
 return result

 On Thursday, March 14, 2013 11:35:20 AM UTC+1, Daniel Gonzalez wrote:

 And (I am discovering some effects during testing):

 4. Is it possible to call this function *after* the templates have been 
 rendered?

 On Thursday, March 14, 2013 11:09:51 AM UTC+1, Daniel Gonzalez wrote:

 And:

 3. Is it possible to call this function also for jsonrpc requests?

 On Thursday, March 14, 2013 11:00:13 AM UTC+1, Daniel Gonzalez wrote:

 Hi,

 For some tests that I am performing, I would like to call a function 
 request_processed() (defined in a model, for example), at the end of 
 every request.

 1. Is this possible? How?
 2. Is it possible to also call this function in case no controller was 
 found to serve the request?

 Thanks,
 Daniel



-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Call a function at the end of every request

2013-03-14 Thread Daniel Gonzalez
But this has two drawbacks:

   - the decorator must be added to every controller function
   - it gets executed before rendering the template.

On Thursday, March 14, 2013 11:56:53 AM UTC+1, Daniel Gonzalez wrote:

 Are you suggesting something like this (which is what I am currently 
 doing):

 In my model I define a decorator:

 def finish_request(fn, *args, **kwargs):
 def wrapped():
 res = fn(*args, **kwargs)
 do_whatever_after_the_request_has_been_processed()
 return res
 return wrapped

 And then in my controller:

 @finish_request
 @auth.requires_login()
 def index():
 return Hello



 On Thursday, March 14, 2013 11:48:48 AM UTC+1, Niphlod wrote:

 let's dive it into  I don't think there's an integrated way to do it, 
 rather than decorating your function with something else.
 Please note that as far as I know (but I may be totally wrong) you can't 
 actually return from a function (so it gets rendered and transferred to the 
 client) and continue your computationi.e. if you have return 'abcd' to 
 ship 'abcd' to the client, execution stops there.
 So, assuming that you are fine with, e.g.
 def func():
  result = 'abcd'
  .some lengthy after callback
  return result

 I'd say it's definitely doable.
 If I remember correctly, there's only one handy shortcut available 
 without starting toying with decorators response.custom_commit that can 
 be a callable and gets called at the end of every request (before returning 
 the results) 

 PS: if the thing to do after callback is fine if executed 
 asynchronously, you can set up a queue of things to do to be processed 
 afterwards.

 PS2: to kick in after the rendering you must return the compiled 
 template, e.g.
 result = response.render(...)
 ...some lengthy after callback
 return result

 On Thursday, March 14, 2013 11:35:20 AM UTC+1, Daniel Gonzalez wrote:

 And (I am discovering some effects during testing):

 4. Is it possible to call this function *after* the templates have been 
 rendered?

 On Thursday, March 14, 2013 11:09:51 AM UTC+1, Daniel Gonzalez wrote:

 And:

 3. Is it possible to call this function also for jsonrpc requests?

 On Thursday, March 14, 2013 11:00:13 AM UTC+1, Daniel Gonzalez wrote:

 Hi,

 For some tests that I am performing, I would like to call a function 
 request_processed() (defined in a model, for example), at the end of 
 every request.

 1. Is this possible? How?
 2. Is it possible to also call this function in case no controller was 
 found to serve the request?

 Thanks,
 Daniel



-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Call a function at the end of every request

2013-03-14 Thread Daniel Gonzalez
Thanks Niphlod, I am making progress thanks to your suggestions.

I have a strange effect: if I do

def finish_request(xxx): # It receives None as parameter, I do not know why
print yadayada

response.custom_commit = finish_request

My function gets called, at the end of the request, *twice* in rapid 
succession. Is this expected? Maybe a web2py bug? (using commit 10c67e5, 
from 4 days ago)

On Thursday, March 14, 2013 12:17:36 PM UTC+1, Niphlod wrote:

 as said before, for 1 there's response.custom_commit and for 2 you must 
 render the template inside your function.

 On Thursday, March 14, 2013 11:59:26 AM UTC+1, Daniel Gonzalez wrote:

 But this has two drawbacks:

- the decorator must be added to every controller function
- it gets executed before rendering the template.

 On Thursday, March 14, 2013 11:56:53 AM UTC+1, Daniel Gonzalez wrote:

 Are you suggesting something like this (which is what I am currently 
 doing):

 In my model I define a decorator:

 def finish_request(fn, *args, **kwargs):
 def wrapped():
 res = fn(*args, **kwargs)
 do_whatever_after_the_request_has_been_processed()
 return res
 return wrapped

 And then in my controller:

 @finish_request
 @auth.requires_login()
 def index():
 return Hello



 On Thursday, March 14, 2013 11:48:48 AM UTC+1, Niphlod wrote:

 let's dive it into  I don't think there's an integrated way to do 
 it, rather than decorating your function with something else.
 Please note that as far as I know (but I may be totally wrong) you 
 can't actually return from a function (so it gets rendered and transferred 
 to the client) and continue your computationi.e. if you have return 
 'abcd' to ship 'abcd' to the client, execution stops there.
 So, assuming that you are fine with, e.g.
 def func():
  result = 'abcd'
  .some lengthy after callback
  return result

 I'd say it's definitely doable.
 If I remember correctly, there's only one handy shortcut available 
 without starting toying with decorators response.custom_commit that 
 can 
 be a callable and gets called at the end of every request (before 
 returning 
 the results) 

 PS: if the thing to do after callback is fine if executed 
 asynchronously, you can set up a queue of things to do to be processed 
 afterwards.

 PS2: to kick in after the rendering you must return the compiled 
 template, e.g.
 result = response.render(...)
 ...some lengthy after callback
 return result

 On Thursday, March 14, 2013 11:35:20 AM UTC+1, Daniel Gonzalez wrote:

 And (I am discovering some effects during testing):

 4. Is it possible to call this function *after* the templates have 
 been rendered?

 On Thursday, March 14, 2013 11:09:51 AM UTC+1, Daniel Gonzalez wrote:

 And:

 3. Is it possible to call this function also for jsonrpc requests?

 On Thursday, March 14, 2013 11:00:13 AM UTC+1, Daniel Gonzalez wrote:

 Hi,

 For some tests that I am performing, I would like to call a function 
 request_processed() (defined in a model, for example), at the end of 
 every request.

 1. Is this possible? How?
 2. Is it possible to also call this function in case no controller 
 was found to serve the request?

 Thanks,
 Daniel



-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Call a function at the end of every request

2013-03-14 Thread Daniel Gonzalez
(Strange, your reply arrives per email but is not visible in the google 
groups thread. I quote)

it **should** not happen if you see the code.
 https://github.com/web2py/web2py/blob/master/gluon/main.py#L566
 https://github.com/web2py/web2py/blob/master/gluon/dal.py#L555
 are you sure that the double execution is not some generated by a 
 decorator lying around in your code ?


Yes, I have verified the web2py code and it should not happen, that is why 
I am surprised.
And no, I have no old code lying around (that I can see ...). It really 
gets called twice by web2py. I'll have to investigate further.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Slow DAL initialization

2013-03-14 Thread Daniel Gonzalez
This codes in the model takes between 5ms and 24ms to complete:

WEB2PY_DAL_STORAGE=postgres://myuser:mypass@localhost:5432/mydb
db = DAL(WEB2PY_DAL_STORAGE, migrate_enabled=False, lazy_tables=True)

I am in a laptop with:

   - 2 cores, 3300 bogomips/core
   - 4 GB
   - linux 2.6.32-5-686

Is this expected?

Thanks,
Daniel

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [web2py] Re: Call a function at the end of every request

2013-03-14 Thread Daniel Gonzalez
Thanks Jonathan, that makes sense.

On Thursday, March 14, 2013 1:54:35 PM UTC+1, Jonathan Lundell wrote:

 On 14 Mar 2013, at 4:45 AM, Daniel Gonzalez gonv...@gmail.comjavascript: 
 wrote: 
  Thanks Niphlod, I am making progress thanks to your suggestions. 
  
  I have a strange effect: if I do 
  
  def finish_request(xxx): # It receives None as parameter, I do not know 
 why 
  print yadayada 
  
  response.custom_commit = finish_request 
  
  My function gets called, at the end of the request, *twice* in rapid 
 succession. Is this expected? Maybe a web2py bug? (using commit 10c67e5, 
 from 4 days ago) 
  

 It's normal, IIRC. It's called with different arguments, once for each db 
 thread and once with None. When I use it (to do some cache flushing after 
 the db commits), my function looks like this: 

 def oncommit(_db): 
 custom_commit callback: commit, then flush the cache 
 if _db is None: # after all commits 
 flush_active_channels() 
 else: 
 _db.commit()# not called for Google Datastore 



-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Slow DAL initialization

2013-03-14 Thread Daniel Gonzalez
Great, thanks Niphlod!

Now the setup times have been reduced to the 3ms (with some cases of 3ms, 
and even less over 10ms). I would say, discarding the initial pool setup, 
the average is around 4 ms, with some spikes around 10ms (these are not 
accurate stats)

Anyway, looks like an improvement.

On Thursday, March 14, 2013 2:13:51 PM UTC+1, Niphlod wrote:

 pool ?

 On Thursday, March 14, 2013 1:16:25 PM UTC+1, Daniel Gonzalez wrote:

 This codes in the model takes between 5ms and 24ms to complete:

 WEB2PY_DAL_STORAGE=postgres://myuser:mypass@localhost:5432/mydb
 db = DAL(WEB2PY_DAL_STORAGE, migrate_enabled=False, lazy_tables=True)

 I am in a laptop with:

- 2 cores, 3300 bogomips/core
- 4 GB
- linux 2.6.32-5-686

 Is this expected?

 Thanks,
 Daniel



-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Strange problem importing a module

2013-03-07 Thread Daniel Gonzalez
Moving to 2.4.2 did not solve the issue. What did solve it was a 
reorganizing of my libraries: previously I was importing libraries from a 
top-level directory, and now I have put all my libraries inside a new 
namespace, so that instead of doing:

from my_module import my_function

Now I am doing:

from top_namespace.my_module import my_funcion

And the issues are gone. I suspect one of my libraries was conflicting with 
one the modules provided by web2py, but have no prove of that.

On Wednesday, March 6, 2013 7:53:26 PM UTC+1, Daniel Gonzalez wrote:

 Currently running Version 2.4.1-alpha.2+timestamp.2013.01.13.13.14.47

 And I remember that I had a similar issue, which was indeed related to the 
 custom importer:
 https://groups.google.com/d/topic/web2py/IzhnixOivic/discussion

 It seems I am run into a similar problem again. If I find any information 
 I'll post it. Otherwise I'll move to 2.4.2 and see if that solves the 
 problems.

 On Wednesday, March 6, 2013 7:41:23 PM UTC+1, Massimo Di Pierro wrote:

 Which web2py version? Some changes were made to 2.4.2 to the custom 
 importer.

 On Wednesday, 6 March 2013 12:19:32 UTC-6, Daniel Gonzalez wrote:

 Hi,

 I have this very strange issue: I am importing a module in the web2py 
 models, but the module can not be found.
 This is only happening in one of my production hosts: the rest are ok 
 (very similar machines, similar setup).
 If I import the module from a python shell, it works, but importing from 
 the web2py shell fails.
 I have verified that os.environ.get('PYTHONPATH') are exactly the same 
 in both web2py shell and normal python shell.

 sys.path differ slightly: basically, in web2py shell it has the web2py 
 installation directory, and in the normal python shell it has the current 
 directory.
 But this should not affect finding the module I want to import. So, I do 
 not understand why this one module is not being found. 

 I have experienced in the past that web2py complains about a module not 
 found, when actually what happens is that importing that module causes an 
 error (for whatever reason: because an import there does not work, or 
 syntax error, or whatever). But I can not tell in this specific case if 
 that is my problem. How can I further debug this annoying issue?

 Thanks,
 Daniel



-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Strange problem importing a module

2013-03-06 Thread Daniel Gonzalez
Hi,

I have this very strange issue: I am importing a module in the web2py 
models, but the module can not be found.
This is only happening in one of my production hosts: the rest are ok (very 
similar machines, similar setup).
If I import the module from a python shell, it works, but importing from 
the web2py shell fails.
I have verified that os.environ.get('PYTHONPATH') are exactly the same in 
both web2py shell and normal python shell.

sys.path differ slightly: basically, in web2py shell it has the web2py 
installation directory, and in the normal python shell it has the current 
directory.
But this should not affect finding the module I want to import. So, I do 
not understand why this one module is not being found. 

I have experienced in the past that web2py complains about a module not 
found, when actually what happens is that importing that module causes an 
error (for whatever reason: because an import there does not work, or 
syntax error, or whatever). But I can not tell in this specific case if 
that is my problem. How can I further debug this annoying issue?

Thanks,
Daniel

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Strange problem importing a module

2013-03-06 Thread Daniel Gonzalez
Currently running Version 2.4.1-alpha.2+timestamp.2013.01.13.13.14.47

And I remember that I had a similar issue, which was indeed related to the 
custom importer:
https://groups.google.com/d/topic/web2py/IzhnixOivic/discussion

It seems I am run into a similar problem again. If I find any information 
I'll post it. Otherwise I'll move to 2.4.2 and see if that solves the 
problems.

On Wednesday, March 6, 2013 7:41:23 PM UTC+1, Massimo Di Pierro wrote:

 Which web2py version? Some changes were made to 2.4.2 to the custom 
 importer.

 On Wednesday, 6 March 2013 12:19:32 UTC-6, Daniel Gonzalez wrote:

 Hi,

 I have this very strange issue: I am importing a module in the web2py 
 models, but the module can not be found.
 This is only happening in one of my production hosts: the rest are ok 
 (very similar machines, similar setup).
 If I import the module from a python shell, it works, but importing from 
 the web2py shell fails.
 I have verified that os.environ.get('PYTHONPATH') are exactly the same in 
 both web2py shell and normal python shell.

 sys.path differ slightly: basically, in web2py shell it has the web2py 
 installation directory, and in the normal python shell it has the current 
 directory.
 But this should not affect finding the module I want to import. So, I do 
 not understand why this one module is not being found. 

 I have experienced in the past that web2py complains about a module not 
 found, when actually what happens is that importing that module causes an 
 error (for whatever reason: because an import there does not work, or 
 syntax error, or whatever). But I can not tell in this specific case if 
 that is my problem. How can I further debug this annoying issue?

 Thanks,
 Daniel



-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Querying the DAL by regex

2013-01-22 Thread Daniel Gonzalez
Hi,

I have this function to delete a user with a certain email address:

def delete_user(self, email):
my_query = self.db[self.web2py_user_table].email == email
my_set   = self.db(my_query)
my_set.delete()

Now I would like to implement a function to delete several users at once, 
based on a regex parameter:

def delete_users(self, regex):
my_query = define query using regex
my_set   = self.db(my_query)
my_set.delete()

Is it possible to do this?

Thanks,

Daniel

-- 





[web2py] Specify my own controller for @auth.requires_login()

2013-01-18 Thread Daniel Gonzalez
Hi,

Whenever my login expires, web2py redirects to 
application/default/user/login?_next=next_url.
Since I have a customized login controller, I would like to redirect to it 
whenever the login expires.
Is it possible to configure @auth.requires_login() to point to my own 
controller?

Thanks,
Daniel

-- 





[web2py] Re: Possible bug? session.auth is None in some requests

2013-01-17 Thread Daniel Gonzalez
I was having a problem with session.auth.user, and my investigation has 
narrowed down the problem to web2py code. Instrumenting the code has 
allowed me to see the problem directly in the logs, but the problem is 
there no matter whether I modify Auth code or not.

Sure, for me Sessions and session.auth work well ... except when I am doing 
stress testing. With 10 parallel clients, I start to have problems. Strange 
problems as you see in the logs: around 30% of the requests overall do not 
have a properly initialized auth. Some clients have nearly no problems, 
other clients have lots of problems.

My question is: is nobody else seeing this? Not even when running several 
clients in parallel? I am fairly confident on my client code ...

I am running:
Version 2.4.1-alpha.2+timestamp.2013.01.13.13.14.47
commit 4bbe6ed, 4 days ago, minor fix in parse_as_rest

On Thursday, January 17, 2013 4:56:00 AM UTC+1, Massimo Di Pierro wrote:

 You are modifying Auth code. What problem are you trying to solve? 
 Sessions and session.auth work well with both stable and trunk version, do 
 they not?

 On Wednesday, 16 January 2013 21:19:01 UTC-6, Daniel Gonzalez wrote:

 Hi,

 I am doing stress testing of my web2py application. The way I am doing 
 this is:

- 10 parallel clients
- the clients log-in automatically, and obtain the session cookie
- the clients log-in only *once* at the start of testing.
- I use the session cookie to tag log messages in order to look for 
mý problem: this way I can relate the log messages to a specific client.
- I am looking for problems in the web2py code, specifically in 
tools.py, Auth.__init__, where the auth.user is defined

 This is my instrumented code (in tools.py, Auth.__init__):

 if auth is None:
 tools_tracer.show('session.auth is None')
 if auth and auth.last_visit and auth.last_visit + \
 datetime.timedelta(days=0, seconds=auth.expiration) request
 .now:
 tools_tracer.show('session.auth active, last_visit=%s', auth.
 last_visit)
 self.user = auth.user
 # this is a trick to speed up sessions
 if (request.now - auth.last_visit).seconds  (auth.expiration 
 / 10):
 auth.last_visit = request.now
 else:
 self.user = None
 if session.auth:
 del session.auth
 tools_tracer.show('session.auth expired')

 And (in tools.py, Auth.login_user):

 current.session.auth = Storage(
 user = user,
 last_visit=current.request.now,
 expiration=self.settings.expiration,
 hmac_key=web2py_uuid())
 tools_tracer.show('session.auth created')

 This is my current log:

 2013-01-17 04:00:41,816 - Thread-5  - c2d769 session.auth 
 is None
 2013-01-17 04:00:41,861 - Thread-5  - c2d769 session.auth 
 created
 2013-01-17 04:00:41,984 - Thread-6  - c2d769 session.auth 
 active, last_visit=2013-01-17 04:00:41.791030
 2013-01-17 04:00:48,923 - Thread-7  - c2d769 session.auth 
 is None
 2013-01-17 04:01:51,131 - Thread-10 - c2d769 session.auth 
 is None
 2013-01-17 04:01:51,214 - Thread-9  - c2d769 session.auth 
 is None
 2013-01-17 04:02:42,506 - Thread-6  - c2d769 session.auth 
 is None
 2013-01-17 04:04:42,791 - Thread-9  - c2d769 session.auth 
 active, last_visit=2013-01-17 04:04:07.717197
 2013-01-17 04:04:42,816 - Thread-4  - c2d769 session.auth 
 is None
 2013-01-17 04:04:48,862 - Thread-10 - c2d769 session.auth 
 is None
 2013-01-17 04:04:49,251 - Thread-6  - c2d769 session.auth 
 is None
 2013-01-17 04:05:35,713 - Thread-7  - c2d769 session.auth 
 is None
 2013-01-17 04:06:39,764 - Thread-8  - c2d769 session.auth 
 active, last_visit=2013-01-17 04:06:10.853567
 2013-01-17 04:06:39,803 - Thread-2  - c2d769 session.auth 
 is None
 2013-01-17 04:07:35,154 - Thread-8  - c2d769 session.auth 
 active, last_visit=2013-01-17 04:07:00.261709
 2013-01-17 04:07:40,860 - Thread-9  - c2d769 session.auth 
 is None
 2013-01-17 04:07:46,176 - Thread-8  - c2d769 session.auth 
 is None
 2013-01-17 04:07:46,266 - Thread-5  - c2d769 session.auth 
 is None
 2013-01-17 04:08:27,416 - Thread-9  - c2d769 session.auth 
 active, last_visit=2013-01-17 04:08:03.492030
 2013-01-17 04:08:27,436 - Thread-2  - c2d769 session.auth 
 is None
 2013-01-17 04:09:31,485 - Thread-10 - c2d769 session.auth 
 is None
 2013-01-17 04:11:21,903 - Thread-7  - c2d769 session.auth 
 is None
 2013-01-17 04:12:20,207 - Thread-10 - c2d769 session.auth 
 is None

 (the c2d769 is a hash of the cookie, and identifies the client)

 As you

[web2py] Re: Possible bug? session.auth is None in some requests

2013-01-17 Thread Daniel Gonzalez
Yes Anthony, pretty sure. The little hash that you see in the logs *is* the 
cookie. Otherwise I can not grep for the relevant log messages (lots of 
activity going on with 10 parallel requests). This is the code that I have 
at the very top of my db.py:

try:
cookie_value = request.cookies[response.session_id_name].value
except:
cookie_value = None

from gluon.tools import tools_tracer
tools_tracer.setid(cookie_value)

(tools_tracer is part of my instrumentation) And that setid call with 
compute a cookie hash for my logs.

On Thursday, January 17, 2013 5:32:22 AM UTC+1, Anthony wrote:

 You're sure the client is sending the session cookie each time?

 On Wednesday, January 16, 2013 10:19:01 PM UTC-5, Daniel Gonzalez wrote:

 Hi,

 I am doing stress testing of my web2py application. The way I am doing 
 this is:

- 10 parallel clients
- the clients log-in automatically, and obtain the session cookie
- the clients log-in only *once* at the start of testing.
- I use the session cookie to tag log messages in order to look for 
mý problem: this way I can relate the log messages to a specific client.
- I am looking for problems in the web2py code, specifically in 
tools.py, Auth.__init__, where the auth.user is defined

 This is my instrumented code (in tools.py, Auth.__init__):

 if auth is None:
 tools_tracer.show('session.auth is None')
 if auth and auth.last_visit and auth.last_visit + \
 datetime.timedelta(days=0, seconds=auth.expiration) request
 .now:
 tools_tracer.show('session.auth active, last_visit=%s', auth.
 last_visit)
 self.user = auth.user
 # this is a trick to speed up sessions
 if (request.now - auth.last_visit).seconds  (auth.expiration 
 / 10):
 auth.last_visit = request.now
 else:
 self.user = None
 if session.auth:
 del session.auth
 tools_tracer.show('session.auth expired')

 And (in tools.py, Auth.login_user):

 current.session.auth = Storage(
 user = user,
 last_visit=current.request.now,
 expiration=self.settings.expiration,
 hmac_key=web2py_uuid())
 tools_tracer.show('session.auth created')

 This is my current log:

 2013-01-17 04:00:41,816 - Thread-5  - c2d769 session.auth 
 is None
 2013-01-17 04:00:41,861 - Thread-5  - c2d769 session.auth 
 created
 2013-01-17 04:00:41,984 - Thread-6  - c2d769 session.auth 
 active, last_visit=2013-01-17 04:00:41.791030
 2013-01-17 04:00:48,923 - Thread-7  - c2d769 session.auth 
 is None
 2013-01-17 04:01:51,131 - Thread-10 - c2d769 session.auth 
 is None
 2013-01-17 04:01:51,214 - Thread-9  - c2d769 session.auth 
 is None
 2013-01-17 04:02:42,506 - Thread-6  - c2d769 session.auth 
 is None
 2013-01-17 04:04:42,791 - Thread-9  - c2d769 session.auth 
 active, last_visit=2013-01-17 04:04:07.717197
 2013-01-17 04:04:42,816 - Thread-4  - c2d769 session.auth 
 is None
 2013-01-17 04:04:48,862 - Thread-10 - c2d769 session.auth 
 is None
 2013-01-17 04:04:49,251 - Thread-6  - c2d769 session.auth 
 is None
 2013-01-17 04:05:35,713 - Thread-7  - c2d769 session.auth 
 is None
 2013-01-17 04:06:39,764 - Thread-8  - c2d769 session.auth 
 active, last_visit=2013-01-17 04:06:10.853567
 2013-01-17 04:06:39,803 - Thread-2  - c2d769 session.auth 
 is None
 2013-01-17 04:07:35,154 - Thread-8  - c2d769 session.auth 
 active, last_visit=2013-01-17 04:07:00.261709
 2013-01-17 04:07:40,860 - Thread-9  - c2d769 session.auth 
 is None
 2013-01-17 04:07:46,176 - Thread-8  - c2d769 session.auth 
 is None
 2013-01-17 04:07:46,266 - Thread-5  - c2d769 session.auth 
 is None
 2013-01-17 04:08:27,416 - Thread-9  - c2d769 session.auth 
 active, last_visit=2013-01-17 04:08:03.492030
 2013-01-17 04:08:27,436 - Thread-2  - c2d769 session.auth 
 is None
 2013-01-17 04:09:31,485 - Thread-10 - c2d769 session.auth 
 is None
 2013-01-17 04:11:21,903 - Thread-7  - c2d769 session.auth 
 is None
 2013-01-17 04:12:20,207 - Thread-10 - c2d769 session.auth 
 is None

 (the c2d769 is a hash of the cookie, and identifies the client)

 As you can see, very often (for this specific client, other clients have 
 fewer problems), the session.auth  is not there. But then suddenly, in the 
 following request, it is there again.

 What can be causing this strange problem?

 Thanks,
 Daniel



-- 





[web2py] Re: Why does the login expire when doing periodic jsonrpc requests?

2013-01-17 Thread Daniel Gonzalez
Here: http://code.google.com/p/web2py/issues/detail?id=1287

On Thursday, January 17, 2013 4:50:08 AM UTC+1, Massimo Di Pierro wrote:

 Please open a ticket about this... :-)

 On Wednesday, 16 January 2013 17:28:59 UTC-6, Daniel Gonzalez wrote:

 This is the relevant section in Auth.__init__ for the login expiration:

 if auth and auth.last_visit and auth.last_visit + \
 datetime.timedelta(days=0, seconds=auth.expiration) request
 .now:
 self.user = auth.user
 # this is a trick to speed up sessions
 if (request.now - auth.last_visit).seconds  (auth.expiration 
 / 10):
 auth.last_visit = request.now
 else:
 self.user = None
 if session.auth:
 del session.auth

 I have verified that jsonrpc requests will update the last_visit. BUT the 
 login will expire anyway (after expiration, since the original login), 
 which I can not understand from the code above.

 This does not happen when doing normal accesses: doing periodic requests 
 will keep an active login forever, which is expected I think.

 Am I missing something here?

 Thanks,
 Daniel



-- 





[web2py] Re: Problems with auth.login_bare when using postgres

2013-01-17 Thread Daniel Gonzalez
M, not really: I still need to create the database. Maybe web2py can do 
that for me if I start with a blank postgres database, but I am not 
familiar with that, so this was an easier path for me.

By the way, I found out another problem: we need serial PRIMARY KEY, so 
the sed script must be changed to include:

s/INTEGER PRIMARY KEY AUTOINCREMENT/serial PRIMARY KEY/

And the postgres sequences must be initialized after import:

select setval(pg_get_serial_sequence('auth_user'   , 'id'), (select max(
id) from auth_user) );
select setval(pg_get_serial_sequence('fulluser', 'id'), (select max(
id) from fulluser) );
select setval(pg_get_serial_sequence('auth_group'  , 'id'), (select max(
id) from auth_group) );
select setval(pg_get_serial_sequence('auth_membership' , 'id'), (select max(
id) from auth_membership) );
select setval(pg_get_serial_sequence('auth_permission' , 'id'), (select max(
id) from auth_permission) );
select setval(pg_get_serial_sequence('auth_event'  , 'id'), (select max(
id) from auth_event) );
select setval(pg_get_serial_sequence('auth_cas', 'id'), (select max(
id) from auth_cas) );



On Thursday, January 17, 2013 8:52:03 PM UTC+1, Niphlod wrote:

 yep, probably exporting all to csv and reimporting would have you saved a 
 bit of hassle.

 On Wednesday, January 16, 2013 5:43:09 PM UTC+1, Daniel Gonzalez wrote:

 I found the problem: CHAR fields in postgres (the default that the .dump 
 command in sqlite is generating) will be extended with spaces to fill the 
 available length in postgres, so that username/password do not match 
 anymore.

 I have modified my import script like this:

 import_from_sqlite_ ( ) {
 # Set the following:
 #  WEB2PY_PG_DB : the name of the database in postgres to import to
 #  SQLITE_FILE: the location of the sqlite file
 #  PG_USER  : the postgres user
 #  PG_PWD   : the potgres password
 #
 sql_dump=/tmp/from_sqlite.sql
 # Dump the data:
 #   - PRAGMA and AUTOINCREMENT are not supported in postgres
 #   - sqlite_sequence is specific to sqlite
 #   - CHAR will have fixed size in postgres, so it will be filled 
 with empty spaces. Use VARCHAR instead.
 sqlite3 $SQLITE_FILE .dump | sed -e 
 '/^PRAGMA/d;/sqlite_sequence/d;s/AUTOINCREMENT//;s/ 
 CHAR/ VARCHAR/'  $sql_dump
 # Drop / recreate database
 sudo -u postgres dropdb $WEB2PY_PG_DB
 sudo -u postgres createdb -O $PG_USER -E UTF8 $WEB2PY_PG_DB
 # Import the data
 sudo -u postgres PGPASSWORD=$PG_PWD psql -h localhost -U $PG_USER -d 
 $WEB2PY_PG_DB  $sql_dump
 # Show some data, to see if the import worked fine
 sudo -u postgres psql -l
 echo \dt | sudo -u postgres psql -d $WEB2PY_PG_DB
 echo select * from auth_user; | sudo -u postgres psql -d 
 $WEB2PY_PG_DB
 rm -f $sql_dump
 }


 Be careful with this, since it will drop and recreate the database. Also, 
 the changes to the sqlite dump are very specific to my situation. YMMV.

 On Wednesday, January 16, 2013 4:06:23 PM UTC+1, Daniel Gonzalez wrote:

 Hi,

 The following code was working when using SQLite, and now that I have 
 moved to postgres it is failing:

 auth.login_bare(request.vars.email, request.vars.password)

 I have the passwords for the time being in plaintext, both in postgres 
 and SQLite. I have imported the data to postgres like this:

 # PRAGMA and AUTOINCREMENT are not supported in postgres
 # sqlite_sequence is specific to sqlite
 sqlite3 storage.sqlite .dump | sed -e 
 '/^PRAGMA/d;/sqlite_sequence/d;s/AUTOINCREMENT//'  /tmp/from_sqlite.sql
 sudo -u postgres PGPASSWORD=mypass psql -h localhost -U myuser -d 
 web2py_wavportal  /tmp/from_sqlite.sql

 I have verified that the data in postgres looks fine:

 web2py_wavportal=# \dt
   List of relations
  Schema |  Name   | Type  |   Owner   
 +-+---+---
  public | auth_cas| table | wavportal
  public | auth_event  | table | wavportal
  public | auth_group  | table | wavportal
  public | auth_membership | table | wavportal
  public | auth_permission | table | wavportal
  public | auth_user   | table | wavportal
  public | fulluser| table | wavportal
 (7 rows)

 The credentials in auth_user are as expected, but auth.login_bare is 
 failing. Why could that be?

 Thanks,
 Daniel



-- 





[web2py] Re: Triggering imports during web2py startup

2013-01-17 Thread Daniel Gonzalez
That is true ... per-process. If my apache server has several processes, I 
must make sure that all processes are triggered. This is difficult to 
guarantee.

On Thursday, January 17, 2013 8:50:53 PM UTC+1, Niphlod wrote:

 I'm not very well versed in all the intricacies, but if the layer calls 
 os.fork() (if you're on linux, that's probably what the underlying server 
 does) your import will happen only on the first request. 
 All the subsequent should not import anything because they will acquire 
 the current status of the process when they are forked. 
 There are some options in most of the layers (being apache, uwsgi, and 
 so on) to tell the interpreter to completely restart the process after a 
 while, but if you have those issues you'll be better off never forcing a 
 restart of the interpreter.

 On Wednesday, January 16, 2013 5:47:18 PM UTC+1, Daniel Gonzalez wrote:

 That would work, and is what I am planning to do, but: how can I 
 guarantee that all processes (threads?) have been targetted?.
 I guess this is not possible, unless I start at least N parallel 
 requests, N being the number of processes ...

 On Wednesday, January 16, 2013 5:37:24 PM UTC+1, Niphlod wrote:

 do an outside request as soon as you reload apache with curl ?

 Il giorno mercoledì 16 gennaio 2013 12:06:14 UTC+1, Daniel Gonzalez ha 
 scritto:

 Hi,

 In my models I am importing third party libraries. Importing those 
 libraries takes time (3s) which means the first requests (one per process) 
 take long time to be served.

 Do you have any suggestion on how to trigger the importing before the 
 first requests arrive? I am running web2py via apache / mod_wsgi.

 Thanks,
 Daniel



-- 





[web2py] Triggering imports during web2py startup

2013-01-16 Thread Daniel Gonzalez
Hi,

In my models I am importing third party libraries. Importing those 
libraries takes time (3s) which means the first requests (one per process) 
take long time to be served.

Do you have any suggestion on how to trigger the importing before the first 
requests arrive? I am running web2py via apache / mod_wsgi.

Thanks,
Daniel

-- 





[web2py] Problems with auth.login_bare when using postgres

2013-01-16 Thread Daniel Gonzalez
Hi,

The following code was working when using SQLite, and now that I have moved 
to postgres it is failing:

auth.login_bare(request.vars.email, request.vars.password)

I have the passwords for the time being in plaintext, both in postgres and 
SQLite. I have imported the data to postgres like this:

# PRAGMA and AUTOINCREMENT are not supported in postgres
# sqlite_sequence is specific to sqlite
sqlite3 storage.sqlite .dump | sed -e 
'/^PRAGMA/d;/sqlite_sequence/d;s/AUTOINCREMENT//'  /tmp/from_sqlite.sql
sudo -u postgres PGPASSWORD=mypass psql -h localhost -U myuser -d 
web2py_wavportal  /tmp/from_sqlite.sql

I have verified that the data in postgres looks fine:

web2py_wavportal=# \dt
  List of relations
 Schema |  Name   | Type  |   Owner   
+-+---+---
 public | auth_cas| table | wavportal
 public | auth_event  | table | wavportal
 public | auth_group  | table | wavportal
 public | auth_membership | table | wavportal
 public | auth_permission | table | wavportal
 public | auth_user   | table | wavportal
 public | fulluser| table | wavportal
(7 rows)

The credentials in auth_user are as expected, but auth.login_bare is 
failing. Why could that be?

Thanks,
Daniel

-- 





[web2py] Re: Problems with auth.login_bare when using postgres

2013-01-16 Thread Daniel Gonzalez
I found the problem: CHAR fields in postgres (the default that the .dump 
command in sqlite is generating) will be extended with spaces to fill the 
available length in postgres, so that username/password do not match 
anymore.

I have modified my import script like this:

import_from_sqlite_ ( ) {
# Set the following:
#  WEB2PY_PG_DB : the name of the database in postgres to import to
#  SQLITE_FILE: the location of the sqlite file
#  PG_USER  : the postgres user
#  PG_PWD   : the potgres password
#
sql_dump=/tmp/from_sqlite.sql
# Dump the data:
#   - PRAGMA and AUTOINCREMENT are not supported in postgres
#   - sqlite_sequence is specific to sqlite
#   - CHAR will have fixed size in postgres, so it will be filled with 
empty spaces. Use VARCHAR instead.
sqlite3 $SQLITE_FILE .dump | sed -e 
'/^PRAGMA/d;/sqlite_sequence/d;s/AUTOINCREMENT//;s/ 
CHAR/ VARCHAR/'  $sql_dump
# Drop / recreate database
sudo -u postgres dropdb $WEB2PY_PG_DB
sudo -u postgres createdb -O $PG_USER -E UTF8 $WEB2PY_PG_DB
# Import the data
sudo -u postgres PGPASSWORD=$PG_PWD psql -h localhost -U $PG_USER -d 
$WEB2PY_PG_DB  $sql_dump
# Show some data, to see if the import worked fine
sudo -u postgres psql -l
echo \dt | sudo -u postgres psql -d $WEB2PY_PG_DB
echo select * from auth_user; | sudo -u postgres psql -d $WEB2PY_PG_DB
rm -f $sql_dump
}


Be careful with this, since it will drop and recreate the database. Also, 
the changes to the sqlite dump are very specific to my situation. YMMV.

On Wednesday, January 16, 2013 4:06:23 PM UTC+1, Daniel Gonzalez wrote:

 Hi,

 The following code was working when using SQLite, and now that I have 
 moved to postgres it is failing:

 auth.login_bare(request.vars.email, request.vars.password)

 I have the passwords for the time being in plaintext, both in postgres and 
 SQLite. I have imported the data to postgres like this:

 # PRAGMA and AUTOINCREMENT are not supported in postgres
 # sqlite_sequence is specific to sqlite
 sqlite3 storage.sqlite .dump | sed -e 
 '/^PRAGMA/d;/sqlite_sequence/d;s/AUTOINCREMENT//'  /tmp/from_sqlite.sql
 sudo -u postgres PGPASSWORD=mypass psql -h localhost -U myuser -d 
 web2py_wavportal  /tmp/from_sqlite.sql

 I have verified that the data in postgres looks fine:

 web2py_wavportal=# \dt
   List of relations
  Schema |  Name   | Type  |   Owner   
 +-+---+---
  public | auth_cas| table | wavportal
  public | auth_event  | table | wavportal
  public | auth_group  | table | wavportal
  public | auth_membership | table | wavportal
  public | auth_permission | table | wavportal
  public | auth_user   | table | wavportal
  public | fulluser| table | wavportal
 (7 rows)

 The credentials in auth_user are as expected, but auth.login_bare is 
 failing. Why could that be?

 Thanks,
 Daniel


-- 





[web2py] Re: Triggering imports during web2py startup

2013-01-16 Thread Daniel Gonzalez
That would work, and is what I am planning to do, but: how can I guarantee 
that all processes (threads?) have been targetted?.
I guess this is not possible, unless I start at least N parallel requests, 
N being the number of processes ...

On Wednesday, January 16, 2013 5:37:24 PM UTC+1, Niphlod wrote:

 do an outside request as soon as you reload apache with curl ?

 Il giorno mercoledì 16 gennaio 2013 12:06:14 UTC+1, Daniel Gonzalez ha 
 scritto:

 Hi,

 In my models I am importing third party libraries. Importing those 
 libraries takes time (3s) which means the first requests (one per process) 
 take long time to be served.

 Do you have any suggestion on how to trigger the importing before the 
 first requests arrive? I am running web2py via apache / mod_wsgi.

 Thanks,
 Daniel



-- 





[web2py] Re: What is the timeout for the session?

2013-01-16 Thread Daniel Gonzalez
I see. You are differentiating between login and session, and I guess I 
understand the distinction.
I have verified the service.jsonrpc calls, and they indeed update 
last_visit.

The open issue is still expiration of the data in memcache, in combination 
with the auth.settings.expiration. I think this is not well integrated: if 
the memcache data expires, that's it. No matter how 
big auth.settings.expiration is, expiration of the data in memcache will 
force the login to expire.

On Tuesday, January 15, 2013 3:08:38 PM UTC+1, Anthony wrote:

 First, note that sessions do not expire -- web2py will keep the session as 
 long as the client keeps returning the session cookie, so it's up to the 
 client when to terminate the session (typically when the browser is 
 closed). auth.settings.expiration does not determine when the session 
 expires but when the login expires (i.e., after a period of inactivity, the 
 user will have to log in again). Note, in order to avoid excessive session 
 writing, session.auth.last_visit does not actually get updated on every 
 single request -- it only gets updated if the time between the last visit 
 and the current request exceeds 10% of the auth.settings.expiration time 
 (so, about every 6 minutes with a one hour expiration).

 As for the @service.jsonrpc requests, are those requests accessing an 
 action that requires authentication, and if so, are you authenticating via 
 a session cookie? If not, then those calls would not affect the session or 
 the Auth login expiration.

 Anthony

 On Tuesday, January 15, 2013 8:27:04 AM UTC-5, Daniel Gonzalez wrote:

 FYI:

 Regarding my last two questions: the expiration is set in auth.settings, 
 but since I was using the session in memcache and the default_time_expire 
 in memche is 300 seconds, what I think is happening is that the session in 
 memcache is expiring, even though the session in auth.settings is not.

 That means no data can be recovered from memcache for the session, and 
 thus the session expires.

 I see several problems here:

- the memcache session does not get updated, even though I am doing 
accesses (in this case @service.jsonrpc accesses). I mean, this key 
 should 
be refreshed in memcache since I am accessing it (its ttl must be reset). 
Just reading the session is not enough: it must be updated too, otherwise 
it will expire!
- auth.settings.expiration is not useful if the memcache time_expire 
is smaller
- session.auth.last_visit does not get updated in @service.jsonrpc 
accesses

 Or maybe I am misunderstanding the expiration concept: it could be that 
 only login actions are supposed to refresh the session.

 But this looks a bit strange to me: as long as the client is sending 
 requests, the session should remain active! Whenever an *inactivity* 
 (meaning, no requests at all) period longer than auth.settings.expiration 
 has passed, the session should expire. Is this how things should work with 
 the current implementation?


 On Tuesday, January 15, 2013 1:26:48 PM UTC+1, Daniel Gonzalez wrote:

 And even worse: I am setting, for testing:

 auth.settings.expiration = 3600 * 24 * 30  # one month

 But the session is expiring after 5 minutes anyway! What is happening 
 here?

 On Tuesday, January 15, 2013 12:14:59 PM UTC+1, Daniel Gonzalez wrote:

 And a related question: my session is expiring after 5 minutes (300s). 
 I am not setting the expiration time, and the default in 
 Auth.default_settings.expiration is 3600. 

 Where is the 300 coming from!?!?

 On Tuesday, January 15, 2013 11:57:03 AM UTC+1, Daniel Gonzalez wrote:

 Thanks Niphlod,

 I am now using:

- session.auth.expiration
- session.auth.last_visit

 And I have realized about one (at least for me) unexpected thing: 
 accessing @service.jsonrpc controllers does not 
 reset session.auth.last_visit. Is this intended?

 On Tuesday, January 15, 2013 11:43:11 AM UTC+1, Niphlod wrote:

 session expiration is managed by auth.settings.expiration ... 



-- 





[web2py] Re: What is the timeout for the session?

2013-01-16 Thread Daniel Gonzalez
Added: http://code.google.com/p/web2py/issues/detail?id=1285

On Wednesday, January 16, 2013 9:24:19 PM UTC+1, Anthony wrote:

 The open issue is still expiration of the data in memcache, in combination 
 with the auth.settings.expiration. I think this is not well integrated: if 
 the memcache data expires, that's it. No matter how 
 big auth.settings.expiration is, expiration of the data in memcache will 
 force the login to expire.


 I'm not really familiar with that implementation. Maybe open an 
 issuehttp://code.google.com/p/web2py/issues/listabout it.

 Anthony 


-- 





[web2py] Re: Moving away from the default controller

2013-01-16 Thread Daniel Gonzalez
Have you modified the routes.py file?

On Wednesday, January 16, 2013 11:39:55 PM UTC+1, GeeksRule wrote:

 I think I'm doing something silly. For the first time now I'm moving away 
 from the default controller.
 I've created a new controller called fromuser.py, there is a single 
 function in it : def submitAStory(): which returns a form.

 When I hit : http://site.com/myapp/fromuser/submitAStory
 It gives me an error : invalid function (default/fromuser)

 I think it is still trying to go into the default controller.

 Note : I have created a view called* fromuser/submitAStory.html*
 *
 *
 Any pointers ?*
 *


-- 





[web2py] Why does the login expire when doing periodic jsonrpc requests?

2013-01-16 Thread Daniel Gonzalez
This is the relevant section in Auth.__init__ for the login expiration:

if auth and auth.last_visit and auth.last_visit + \
datetime.timedelta(days=0, seconds=auth.expiration) request
.now:
self.user = auth.user
# this is a trick to speed up sessions
if (request.now - auth.last_visit).seconds  (auth.expiration / 
10):
auth.last_visit = request.now
else:
self.user = None
if session.auth:
del session.auth

I have verified that jsonrpc requests will update the last_visit. BUT the 
login will expire anyway (after expiration, since the original login), 
which I can not understand from the code above.

This does not happen when doing normal accesses: doing periodic requests 
will keep an active login forever, which is expected I think.

Am I missing something here?

Thanks,
Daniel

-- 





[web2py] Set up of db.py takes too long time

2013-01-15 Thread Daniel Gonzalez
Hi,

My db.py takes a long time to run (around 40 ms). This means that just the 
overhead of db.py limits my throughput to 25 req/s (in a single process / 
single thread configuration). This seems to me quite low.

I have tried to take a look at where the time is spent. I have seen the 
following runtimes. These are average values:

 8 ms - session.connect(request,response,db=MEMDB(cache.memcache))
 2 ms - db = DAL('sqlite://storage.sqlite', migrate=False)
 5 ms - auth = Auth(db)
20 ms - define tables

My define tables is like this:

# Use the authorization table for users
web2py_user_table = auth.settings.table_user_name
# web2py_user_table = 'web2py_user'
db.define_table(
web2py_user_table,
Field('org_id',   type='integer', compute=set_org_id),
Field('email',unique=True),
Field('user_doc_id',  length=128, compute=create_new_user),
Field('password', length=512, compute=automatic_password
, type='password', readable=False, label='Password'), # TODO: use CRYPT
# These fields are needed for authorization
Field('registration_key', length=512, writable=False, readable=
False, default=''),
Field('reset_password_key',   length=512, writable=False, readable=
False, default=''),
Field('registration_id',  length=512, writable=False, readable=
False, default=''),
format = '%(email)s')

# Add constraints to the web2py_user table
web2py_user = db[web2py_user_table]
web2py_user.email.requires= [IS_EMAIL(error_message=auth.
messages.invalid_email), IS_NOT_IN_DB(db, '%s.email' % (web2py_user_table))]
# web2py_user.user_doc_id.requires = 
IS_NOT_EMPTY(error_message=auth.messages.is_empty)
# web2py_user.password.requires = [IS_STRONG(min=5, special=0, 
upper=0), CRYPT()]

auth.define_tables()

Those run times look to me quite high. Maybe some of you can give me hints:

   - Is there anything I can do to speed this up?
   - Why is the define tables taking such a long time, even with 
   migrate=False?
   - Would moving to postgres improve things a lot?
   - Is sqlite the bottleneck here?
   
It is difficult for me to believe that sqlite is the cultprit here: I am 
using a single client in my tests, sending requests sequentially (no 
parallel requests).

Thanks,
Daniel

-- 





Re: [web2py] Set up of db.py takes too long time

2013-01-15 Thread Daniel Gonzalez
Very few records (around 10). I am testing still.

On Tuesday, January 15, 2013 9:23:43 AM UTC+1, rochacbruno wrote:


 On Tue, Jan 15, 2013 at 6:20 AM, Daniel Gonzalez 
 gonv...@gmail.comjavascript:
  wrote:

 IS_NOT_IN_DB(db, '%s.email' % (web2py_user_table))


 If you too many records on user table, the above code will take a long 
 time, because on every request it will select email from auth_user





-- 





Re: [web2py] Set up of db.py takes too long time

2013-01-15 Thread Daniel Gonzalez
No imports in the code-area profiled. Also, I am testing some requests, but 
the time I am measuring is the time spent in the code-area that I have 
provided. That is, in the define tables code. The controllers are of course 
making use of the table definitions later, but that is not what I am 
measuring.

I have put a print time.time() before and after the define tables code. 
So no controller is involved in my measurements.

On Tuesday, January 15, 2013 9:56:57 AM UTC+1, rochacbruno wrote:

 It will run only when called!

 But if he is testing a form, the problem maybe there.

 There are some imports?


-- 





[web2py] What is the timeout for the session?

2013-01-15 Thread Daniel Gonzalez
Hi,

In one of my controllers I would to display:

   - what is the timeout for this session
   - how long has the current session still to stay active
   - a list of requests / timestamps (I guess this is not tracked in web2py)
   - when was the last request performed (unfortunately this will be the 
   current request, so it will be now?)
   
I have taken a look at the code and I found:

   - Session._last_timestamp

But I am unable to see where the timeout parameter is set for a 
session. Definitely not in Session.connect() ...

Thanks,
Daniel

-- 





[web2py] Re: What is the timeout for the session?

2013-01-15 Thread Daniel Gonzalez
Thanks Niphlod,

I am now using:

   - session.auth.expiration
   - session.auth.last_visit
   
And I have realized about one (at least for me) unexpected thing: 
accessing @service.jsonrpc controllers does not 
reset session.auth.last_visit. Is this intended?

On Tuesday, January 15, 2013 11:43:11 AM UTC+1, Niphlod wrote:

 session expiration is managed by auth.settings.expiration ... 


-- 





[web2py] Re: Fatal Python error: Couldn't create autoTLSkey mapping

2013-01-15 Thread Daniel Gonzalez
I am actually researching the same problem. Please take a look here:

https://groups.google.com/d/topic/modwsgi/DW-SlIb07rE/discussion
http://bugs.python.org/issue13156

This is a bug in python 2.7.2, and has been solved in 2.7.3. I am also 
affected, and will have to upgrade all my servers :(

On Tuesday, January 15, 2013 11:51:44 AM UTC+1, Niphlod wrote:

 I may be out of line here, but the problem may lie in the fact that if you 
 want to start a subprocess usually subprocess.call uses a thread to 
 communicate with it. uwsgi doesn't allow to spawn your own threads as 
 long as you don't supply the --enable-threads parameter.

 PS: spawning processes from a web-app poses always a lot of problems 
 (concurrency, pipes, stderrs, inherited socket, and so on). Be sure of what 
 you're doing.

 Il giorno martedì 15 gennaio 2013 06:30:14 UTC+1, Richard Penman ha 
 scritto:

 hello,

 I set up a uwsgi / nginx server using 
 the setup-web2py-nginx-uwsgi-ubuntu.sh script.
 However I find when the app tries to start a sub-process I get this error:

 Fatal Python error: Couldn't create autoTLSkey mapping

 I read around and apparently this can happen when lack of memory.

 Do you see any problems with these uwsgi settings:
 uwsgi
 socket/tmp/web2py.socket/socket
 pythonpath/var/www/web2py//pythonpath
 mount/=wsgihandler:application/mount
 master/
 processes4/processes
 harakiri60/harakiri
 reload-mercy8/reload-mercy
 cpu-affinity1/cpu-affinity
 stats/tmp/stats.socket/stats
 max-requests2000/max-requests
 limit-as512/limit-as
 reload-on-as256/reload-on-as
 reload-on-rss192/reload-on-rss
 uidwww-data/uid
 gidwww-data/gid
 cron0 0 -1 -1 -1 python /var/www/web2py/web2py.py -Q -S welcome -M 
 -R scripts/sessions2trash.py -A -o/cron
 no-orphans/
 /uwsgi



-- 





[web2py] Re: What is the timeout for the session?

2013-01-15 Thread Daniel Gonzalez
And a related question: my session is expiring after 5 minutes (300s). I am 
not setting the expiration time, and the default in 
Auth.default_settings.expiration is 3600. 

Where is the 300 coming from!?!?

On Tuesday, January 15, 2013 11:57:03 AM UTC+1, Daniel Gonzalez wrote:

 Thanks Niphlod,

 I am now using:

- session.auth.expiration
- session.auth.last_visit

 And I have realized about one (at least for me) unexpected thing: 
 accessing @service.jsonrpc controllers does not 
 reset session.auth.last_visit. Is this intended?

 On Tuesday, January 15, 2013 11:43:11 AM UTC+1, Niphlod wrote:

 session expiration is managed by auth.settings.expiration ... 



-- 





Re: [web2py] Re: Fatal Python error: Couldn't create autoTLSkey mapping

2013-01-15 Thread Daniel Gonzalez
The links I sent are related to mod_wsgi / apache / python 2.7.2, but it is 
a generic python 2.7.2 problem. The problems do not happen always.

What python version are you using?

On Tuesday, January 15, 2013 1:20:16 PM UTC+1, Richard Penman wrote:

 I used subprocesses on my previous server with uwsgi and had no problem. 


 On Tue, Jan 15, 2013 at 9:51 PM, Niphlod nip...@gmail.com javascript: 
 wrote: 
  I may be out of line here, but the problem may lie in the fact that if 
 you 
  want to start a subprocess usually subprocess.call uses a thread to 
  communicate with it. uwsgi doesn't allow to spawn your own threads 
 as 
  long as you don't supply the --enable-threads parameter. 
  
  PS: spawning processes from a web-app poses always a lot of problems 
  (concurrency, pipes, stderrs, inherited socket, and so on). Be sure of 
 what 
  you're doing. 
  
  Il giorno martedì 15 gennaio 2013 06:30:14 UTC+1, Richard Penman ha 
 scritto: 
  
  hello, 
  
  I set up a uwsgi / nginx server using the 
  setup-web2py-nginx-uwsgi-ubuntu.sh script. 
  However I find when the app tries to start a sub-process I get this 
 error: 
  
  Fatal Python error: Couldn't create autoTLSkey mapping 
  
  I read around and apparently this can happen when lack of memory. 
  
  Do you see any problems with these uwsgi settings: 
  uwsgi 
  socket/tmp/web2py.socket/socket 
  pythonpath/var/www/web2py//pythonpath 
  mount/=wsgihandler:application/mount 
  master/ 
  processes4/processes 
  harakiri60/harakiri 
  reload-mercy8/reload-mercy 
  cpu-affinity1/cpu-affinity 
  stats/tmp/stats.socket/stats 
  max-requests2000/max-requests 
  limit-as512/limit-as 
  reload-on-as256/reload-on-as 
  reload-on-rss192/reload-on-rss 
  uidwww-data/uid 
  gidwww-data/gid 
  cron0 0 -1 -1 -1 python /var/www/web2py/web2py.py -Q -S welcome 
 -M 
  -R scripts/sessions2trash.py -A -o/cron 
  no-orphans/ 
  /uwsgi 
  
  -- 
  
  
  


-- 





[web2py] Re: What is the timeout for the session?

2013-01-15 Thread Daniel Gonzalez
And even worse: I am setting, for testing:

auth.settings.expiration = 3600 * 24 * 30  # one month

But the session is expiring after 5 minutes anyway! What is happening here?

On Tuesday, January 15, 2013 12:14:59 PM UTC+1, Daniel Gonzalez wrote:

 And a related question: my session is expiring after 5 minutes (300s). I 
 am not setting the expiration time, and the default in 
 Auth.default_settings.expiration is 3600. 

 Where is the 300 coming from!?!?

 On Tuesday, January 15, 2013 11:57:03 AM UTC+1, Daniel Gonzalez wrote:

 Thanks Niphlod,

 I am now using:

- session.auth.expiration
- session.auth.last_visit

 And I have realized about one (at least for me) unexpected thing: 
 accessing @service.jsonrpc controllers does not 
 reset session.auth.last_visit. Is this intended?

 On Tuesday, January 15, 2013 11:43:11 AM UTC+1, Niphlod wrote:

 session expiration is managed by auth.settings.expiration ... 



-- 





Re: [web2py] Re: Fatal Python error: Couldn't create autoTLSkey mapping

2013-01-15 Thread Daniel Gonzalez
I have not yet upgraded :(

On Tuesday, January 15, 2013 1:25:06 PM UTC+1, Richard Penman wrote:

 Already 2.7.3. 

 Did you find the problem fixed after upgrading? 


 On Tue, Jan 15, 2013 at 11:22 PM, Daniel Gonzalez 
 gonv...@gmail.comjavascript: 
 wrote: 
  The links I sent are related to mod_wsgi / apache / python 2.7.2, but it 
 is 
  a generic python 2.7.2 problem. The problems do not happen always. 
  
  What python version are you using? 
  
  
  On Tuesday, January 15, 2013 1:20:16 PM UTC+1, Richard Penman wrote: 
  
  I used subprocesses on my previous server with uwsgi and had no 
 problem. 
  
  
  On Tue, Jan 15, 2013 at 9:51 PM, Niphlod nip...@gmail.com wrote: 
   I may be out of line here, but the problem may lie in the fact that 
 if 
   you 
   want to start a subprocess usually subprocess.call uses a thread to 
   communicate with it. uwsgi doesn't allow to spawn your own 
 threads 
   as 
   long as you don't supply the --enable-threads parameter. 
   
   PS: spawning processes from a web-app poses always a lot of problems 
   (concurrency, pipes, stderrs, inherited socket, and so on). Be sure 
 of 
   what 
   you're doing. 
   
   Il giorno martedì 15 gennaio 2013 06:30:14 UTC+1, Richard Penman ha 
   scritto: 
   
   hello, 
   
   I set up a uwsgi / nginx server using the 
   setup-web2py-nginx-uwsgi-ubuntu.sh script. 
   However I find when the app tries to start a sub-process I get this 
   error: 
   
   Fatal Python error: Couldn't create autoTLSkey mapping 
   
   I read around and apparently this can happen when lack of memory. 
   
   Do you see any problems with these uwsgi settings: 
   uwsgi 
   socket/tmp/web2py.socket/socket 
   pythonpath/var/www/web2py//pythonpath 
   mount/=wsgihandler:application/mount 
   master/ 
   processes4/processes 
   harakiri60/harakiri 
   reload-mercy8/reload-mercy 
   cpu-affinity1/cpu-affinity 
   stats/tmp/stats.socket/stats 
   max-requests2000/max-requests 
   limit-as512/limit-as 
   reload-on-as256/reload-on-as 
   reload-on-rss192/reload-on-rss 
   uidwww-data/uid 
   gidwww-data/gid 
   cron0 0 -1 -1 -1 python /var/www/web2py/web2py.py -Q -S 
 welcome 
   -M 
   -R scripts/sessions2trash.py -A -o/cron 
   no-orphans/ 
   /uwsgi 
   
   -- 
   
   
   
  
  -- 
  
  
  


-- 





[web2py] Re: What is the timeout for the session?

2013-01-15 Thread Daniel Gonzalez
FYI:

Regarding my last two questions: the expiration is set in auth.settings, 
but since I was using the session in memcache and the default_time_expire 
in memche is 300 seconds, what I think is happening is that the session in 
memcache is expiring, even though the session in auth.settings is not.

That means no data can be recovered from memcache for the session, and thus 
the session expires.

I see several problems here:

   - the memcache session does not get updated, even though I am doing 
   accesses (in this case @service.jsonrpc accesses). I mean, this key should 
   be refreshed in memcache since I am accessing it (its ttl must be reset). 
   Just reading the session is not enough: it must be updated too, otherwise 
   it will expire!
   - auth.settings.expiration is not useful if the memcache time_expire is 
   smaller
   - session.auth.last_visit does not get updated in @service.jsonrpc 
   accesses
   
Or maybe I am misunderstanding the expiration concept: it could be that 
only login actions are supposed to refresh the session.

But this looks a bit strange to me: as long as the client is sending 
requests, the session should remain active! Whenever an *inactivity* 
(meaning, no requests at all) period longer than auth.settings.expiration 
has passed, the session should expire. Is this how things should work with 
the current implementation?


On Tuesday, January 15, 2013 1:26:48 PM UTC+1, Daniel Gonzalez wrote:

 And even worse: I am setting, for testing:

 auth.settings.expiration = 3600 * 24 * 30  # one month

 But the session is expiring after 5 minutes anyway! What is happening here?

 On Tuesday, January 15, 2013 12:14:59 PM UTC+1, Daniel Gonzalez wrote:

 And a related question: my session is expiring after 5 minutes (300s). I 
 am not setting the expiration time, and the default in 
 Auth.default_settings.expiration is 3600. 

 Where is the 300 coming from!?!?

 On Tuesday, January 15, 2013 11:57:03 AM UTC+1, Daniel Gonzalez wrote:

 Thanks Niphlod,

 I am now using:

- session.auth.expiration
- session.auth.last_visit

 And I have realized about one (at least for me) unexpected thing: 
 accessing @service.jsonrpc controllers does not 
 reset session.auth.last_visit. Is this intended?

 On Tuesday, January 15, 2013 11:43:11 AM UTC+1, Niphlod wrote:

 session expiration is managed by auth.settings.expiration ... 



-- 





[web2py] Strange import problem: is sys.path not used in web2py?

2013-01-14 Thread Daniel Gonzalez
Hi,

I have a problem with an import in my model:

Traceback (most recent call last):
  File /installdir/web2py/gluon/restricted.py, line 212, in restricted
exec ccode in environment
  File /installdir/web2py/applications/wavilon_portal/models/db.py, line 
10, in module
import nltk.data
  File /installdir/web2py/gluon/custom_import.py, line 77, incustom_importer
raise ImportError, 'Cannot import module %s' % str(e)
ImportError: Cannot import module 'nltk'

I thought this would be a problem with sys.path, so I am displaying it in 
the top of the controller (sys_path_in_model)
Then I am doing, manually in the python interpreter:

import sys
sys.path=sys_path_in_model
import nltk.data

But this is giving no error!

What is happening here? Is the import mechanism in web2py using something 
different than sys,path?

Thanks,
Daniel

-- 





[web2py] Re: Strange import problem: is sys.path not used in web2py?

2013-01-14 Thread Daniel Gonzalez
Version 2.3.2 (2012-12-17 08:59:58) stable, commit 9557c46, in Ubuntu 
12.04.1 LTS. I am running from a virtualenv with python 2.7.2.

I have no idea how to force nltk to be found: the sys.path is correct, as I 
have verified by setting manually in the interpreter and running the import 
statement. That is why I mean this is a strange error: everything seems 
to be set up correctly, but running from web2py I get an import error, and 
doing the same thing directly in the interpreter does not.

I am taking a look at the custom_importer: I do no know why this import is 
falling to line 77 (if I understand correctly, that part is doing the 
custom web2py modules/models/controllers importing). It should go to line 
96:

return NATIVE_IMPORTER(name, globals, locals, fromlist, level)

since nltk.data is a system import. It has nothing to do with web2py.

On Monday, January 14, 2013 11:42:10 AM UTC+1, Alan Etkin wrote:

 I have a problem with an import in my model:


 What version are you running?, in what OS?. As a temporary workaround and 
 If it's a path error you can try fixing sys.path so nltk is found. 


-- 





[web2py] Re: Strange import problem: is sys.path not used in web2py?

2013-01-14 Thread Daniel Gonzalez
The problem is this code in custom_import.py

# if not relative and not from applications:
if hasattr(current, 'request') \
and level = 0 \
and not name.split('.')[0] in INVALID_MODULES \
and isinstance(globals, dict):

import nltk.data goes through, but it shouldn't. Why could that be? (I do 
not understand the code very well)

On Monday, January 14, 2013 11:52:26 AM UTC+1, Daniel Gonzalez wrote:

 Version 2.3.2 (2012-12-17 08:59:58) stable, commit 9557c46, in Ubuntu 
 12.04.1 LTS. I am running from a virtualenv with python 2.7.2.

 I have no idea how to force nltk to be found: the sys.path is correct, as 
 I have verified by setting manually in the interpreter and running the 
 import statement. That is why I mean this is a strange error: everything 
 seems to be set up correctly, but running from web2py I get an import 
 error, and doing the same thing directly in the interpreter does not.

 I am taking a look at the custom_importer: I do no know why this import is 
 falling to line 77 (if I understand correctly, that part is doing the 
 custom web2py modules/models/controllers importing). It should go to line 
 96:

 return NATIVE_IMPORTER(name, globals, locals, fromlist, level)

 since nltk.data is a system import. It has nothing to do with web2py.

 On Monday, January 14, 2013 11:42:10 AM UTC+1, Alan Etkin wrote:

 I have a problem with an import in my model:


 What version are you running?, in what OS?. As a temporary workaround and 
 If it's a path error you can try fixing sys.path so nltk is found. 



-- 





[web2py] Re: Strange import problem: is sys.path not used in web2py?

2013-01-14 Thread Daniel Gonzalez
I have logged the import activity, modifying custom_import like this:

FORMAT=%s - %-40s %-10s %-10s %-10s %-10s
# if not relative and not from applications:
if hasattr(current, 'request') \
and level = 0 \
and not name.split('.')[0] in INVALID_MODULES \
and isinstance(globals, dict):
print FORMAT % (custom, name, hasattr(current, 'request'), level,name
.split('.')[0] in INVALID_MODULES, isinstance(globals, dict))
...
finally:
if import_tb:
import_tb = None
print FORMAT % (native, name, hasattr(current, 'request'), level, name
.split('.')[0] in INVALID_MODULES, isinstance(globals, dict))
return NATIVE_IMPORTER(name, globals, locals, fromlist, level)

Here you see some of the data:

native - random   True   -1 
True   True  
custom - nltk.dataTrue   -1 
False  True  
native - __future__   True   -1 
True   True  
native - os   True   -1 
True   True  
custom - internalsTrue   -1 
False  True  
native - subprocess   True   -1 
True   True  
native - os   True   -1 
True   True  
native - os.path  True   -1 
True   True  
native - re   True   -1 
True   True  
native - warnings True   -1 
True   True  
native - textwrap True   -1 
True   True  
native - typesTrue   -1 
True   True  
native - sys  True   -1 
True   True  
native - stat True   -1 
True   True   

For nltk the test name.split('.')[0] in INVALID_MODULES is False, but 
should be True. Why could that be?

- I had to type this 7 times! the google groups message composer is not 
very stable :(

On Monday, January 14, 2013 12:38:43 PM UTC+1, Alan Etkin wrote:

 The problem is this code in custom_import.py


 With a very similar configuration but the trunk version I could not 
 reproduce the problem (altough the nltk library has taken about 20 seconds 
 to import in the model)

 My system config:
 Python 2.7.3 Ubuntu 12.04 Rocket server

 This has something to do with virtualenv surely. BTW, there's a recent 
 issue posted about module headers that might be related.



-- 





[web2py] Re: Strange import problem: is sys.path not used in web2py?

2013-01-14 Thread Daniel Gonzalez
I have found a workaround (hack) to my problem. I had to modify:

INVALID_MODULES = set(('', 'gluon', 'applications', 'custom_import'))

to

INVALID_MODULES = set(('', 'gluon', 'applications', 'custom_import', 'nltk', 
'collocations', 'numpy', 'testing'))

(there were more modules affected by the same problem). This is ugly, so I 
hope we can find a real fix for this.

It seems the custom_import_install:

def custom_import_install():
if __builtin__.__import__ == NATIVE_IMPORTER:
INVALID_MODULES.update(sys.modules.keys())
__builtin__.__import__ = custom_importer

Is not working as expected?

-- 





[web2py] Changes in jsonrpc calls?

2013-01-14 Thread Daniel Gonzalez
I am moving to a recent web2py version, and I realize that now the json 
parameters are parsed inside tools.serve_jsonrpc. Previously I was parsing 
them in my jsonrpc controller, so that means I have to adapt my 
controllers. Unexpected, but I can manage.

My question is:

Should I do simplejson.dumps in my controller for the reply, or is this now 
also done automatically in tools.serve_jsonrpc? I do not see that.

I am asking because it looks inconsistent that the parameters are 
automatically parsed from json, but the reply is not automatically 
converted to json.

Maybe the reply must not always be json, I am not sure about that.

-- 





[web2py] Handling unicode keys in jsonrpc calls

2013-01-14 Thread Daniel Gonzalez
Recently web2py changed to parse the jsonrpc parameters in 
tools.py/Service.serve_jsonrpc. Now I have a frawework in my client 
(ember.js) which is sending unicode keys in the jsonrpc parameters. This 
causes the code to fail, like this:

{version: 1.1, id: ID1, error: {message: TypeError: 
access_view() argument after ** must be a mapping, not unicode, code: 
100, data: [  File \/xxx/web2py/gluon/tools.py\, line 4266, in 
serve_jsonrpc\ns = methods[method](**params)\n], name: 
JSONRPCError}}

Previously I was sanitizing those keys in the controller like this:

def process_json_from_client(**pars):
# I do not know why, but sometimes the keys and values come in unicode
#   I will convert all keys to strings, and some values too
#   (not all, since sometimes unicode is expected)
sanitized = { }
keys_to_convert = ['cdr_doc_id']
for key, value in pars.iteritems():
key = str(key)
if key in keys_to_convert : value = str(value)
sanitized[str(key)] = value
if __debug__ and SHOW_SANITIZED_PARS: log.warning('sanitized - %s', gd.
pp.pformat(sanitized))
return sanitized

But since now this is done in tools.py/Service.serve_jsonrpc, I can not 
sanitize before calling the jsonrpc controller.

How can unicode keys be accepted in controllers? I think python does not 
allow for unicode parameters, right?

-- 





[web2py] Make gluon components accessible in mod_wsgi

2013-01-13 Thread Daniel Gonzalez
Hi,

As part of my library, I have a module which I use to wrap some web2py 
components. Let's say I have simple.py:

from gluon.html import B

def my_b(txt):
return B(txt)

To successfully import this module, my pwd needs to be the directory where 
web2py is installed. Otherwise I get the following error:

 import web2pys.simple
Traceback (most recent call last):
  File stdin, line 1, in module
  File /my/modules/web2pys/simple.py, line 1, in module
from gluon.html import B
ImportError: No module named gluon.html

This means that my application is running fine whenever I run it with with 
built in Rockett server (python web2py.py), but serving with apache via 
mod_wsgi does not work. I set the python path in mod_wsgi, so that my 
modules can be found:

WSGIDaemonProcess web2py-https user=www-data group=www-data display-name=%{
GROUP} python-path=/my/modules

But no idea how make gluon accessible to mod_wsgi.

How can I install web2py in my system, so that gluon components can be 
imported normally, like any other python package?

Thanks,
Daniel

-- 





[web2py] Putting the session in memcache does not work

2013-01-13 Thread Daniel Gonzalez
Hi,

I have 0_memcache.py in my models, with following content:

from gluon.contrib.memcache import MemcacheClient
memcache_servers = ['127.0.0.1:11211']
cache.memcache = MemcacheClient(request, memcache_servers)
cache.ram = cache.disk = cache.memcache

Now in my db.py model, I have defined (close to the top of the file, before 
session is used):

from gluon.contrib.memdb import MEMDB
session.connect(request,response,db=MEMDB(cache.memcache))

After clearing the sessions directory, and logging-in to my application, I 
see that the sessions are still being created on the file system. Why is 
this, and what can I do to activate memcache for sessions?

(Memcache is installed and running fine on the localhost)

Thanks,
Daniel

-- 





[web2py] Re: Putting the session in memcache does not work

2013-01-13 Thread Daniel Gonzalez
Thanks Niphlod, you hit it right again!

On Sunday, January 13, 2013 1:26:32 PM UTC+1, Niphlod wrote:

 I think that you need to restart web2py completely because for 
 performances reasons the location of the session (meaning filesystem, 
 cookie, memcache, redis) is evaluated one-time-only  can you try 
 restarting the web2py process (or apache, or uwsgi, depending on your 
 setup...) ?

 On Sunday, January 13, 2013 12:31:24 PM UTC+1, Daniel Gonzalez wrote:

 Hi,

 I have 0_memcache.py in my models, with following content:

 from gluon.contrib.memcache import MemcacheClient
 memcache_servers = ['127.0.0.1:11211']
 cache.memcache = MemcacheClient(request, memcache_servers)
 cache.ram = cache.disk = cache.memcache

 Now in my db.py model, I have defined (close to the top of the file, 
 before session is used):

 from gluon.contrib.memdb import MEMDB
 session.connect(request,response,db=MEMDB(cache.memcache))

 After clearing the sessions directory, and logging-in to my application, 
 I see that the sessions are still being created on the file system. Why is 
 this, and what can I do to activate memcache for sessions?

 (Memcache is installed and running fine on the localhost)

 Thanks,
 Daniel



-- 





[web2py] Invalidated RAM cache from outside web2py to handle refreshing of asynchronous data

2013-01-11 Thread Daniel Gonzalez
Hi,

I am serving some data which is expensive to compute with 
a @service.jsonrpc controller. I want to cache the result in RAM, using 
something like:

@cache(request.env.path_info,time_expire=1000,cache_model=cache.ram)

My data will not change very often, so I want to have a big ttl (actually, 
I would like a ttl forever, is this possible?)

But my main problem is this: in my architecture, web2py does not know when 
new data is available (the data is in a third-party database, completely 
out of control of web2py). Changes to the data happen asynchronously, 
according to business processes.

I have three pieces:

   1. web2py serving the data to the clients, via jsonrpc
   2. a small script which knows (long-polling) when changes in the 
   third-party database occur
   3. a library to process the information in the third-party database. 
   Calling this must be avoided at all costs, *except* when we have actual 
   changes (which is why I want to add the cache)
   
The easiest implementation for me would be to be able, from the external 
script, to invalidate the web2py cache whenever I detect changes relevant 
to the active sessions (not the whole cache, just the part related to my 
jsonrpc controller)

Is this possible? Maybe by calling a web2py controller which is in charge 
of invalidating the cache?

What about the session? I assume the web2py cache is session-related. My 
script should call the web2py controller using the correct session, but I 
do not know how to handle this.

Thanks,
Daniel

-- 





[web2py] Re: Invalidated RAM cache from outside web2py to handle refreshing of asynchronous data

2013-01-11 Thread Daniel Gonzalez
Thanks, that makes sense. In that context, I have two questions:

   1. How do I call cache.ram.clear from outside web2py. What web2py 
   modules should I include?
   2. How can I call a controller disguised as a user? I think this would 
   be the most robust way, if it is possible ...


On Friday, January 11, 2013 2:42:37 PM UTC+1, Niphlod wrote:

 Cache is always related to a key. In your function, that key is request.
 env.path_info
 Let's assume your key is *the_key*
 If you need to invalidate the cache, you should use cache.ram.clear(*
 the_key*) or cache.ram(*the_key*, None). From here one, there are 2 
 paths ahead of you:
 - you have an empty cache and it will be filled at the 1st request coming 
 from an user after you called clear()
 - you want to fill that key after clear() ASAP

 In the 1st case, after calling clear() you don't have to do nothing.

 In the 2nd case, either you call the controller disguised as a user or 
 you process the data and store it using cache.ram(*the_key*, thevalue)

 Il giorno venerdì 11 gennaio 2013 13:07:08 UTC+1, Daniel Gonzalez ha 
 scritto:

 Hi,

 I am serving some data which is expensive to compute with 
 a @service.jsonrpc controller. I want to cache the result in RAM, using 
 something like:

 @cache(request.env.path_info,time_expire=1000,cache_model=cache.ram)

 My data will not change very often, so I want to have a big ttl 
 (actually, I would like a ttl forever, is this possible?)

 But my main problem is this: in my architecture, web2py does not know 
 when new data is available (the data is in a third-party database, 
 completely out of control of web2py). Changes to the data happen 
 asynchronously, according to business processes.

 I have three pieces:

1. web2py serving the data to the clients, via jsonrpc
2. a small script which knows (long-polling) when changes in the 
third-party database occur
3. a library to process the information in the third-party database. 
Calling this must be avoided at all costs, *except* when we have actual 
changes (which is why I want to add the cache)

 The easiest implementation for me would be to be able, from the external 
 script, to invalidate the web2py cache whenever I detect changes relevant 
 to the active sessions (not the whole cache, just the part related to my 
 jsonrpc controller)

 Is this possible? Maybe by calling a web2py controller which is in charge 
 of invalidating the cache?

 What about the session? I assume the web2py cache is session-related. My 
 script should call the web2py controller using the correct session, but I 
 do not know how to handle this.

 Thanks,
 Daniel



-- 





[web2py] Re: Invalidated RAM cache from outside web2py to handle refreshing of asynchronous data

2013-01-11 Thread Daniel Gonzalez
Thanks Niphlod. With that I can proceed to implementation.

I am also considering another option: use memcached. This is not integrated 
with web2py (as far as I know), but would maybe simplify my implementation.

Do you think the performance impact of using memcached (which is accessed 
via tcp) compared to using web2py's cache.ram (which lives in the web2py 
memory map) is very big?

On Friday, January 11, 2013 3:06:40 PM UTC+1, Niphlod wrote:

 1. if you use cache.ram you can't access the ram that your web2py process 
 is using from outside that process. 
In that case you can code a controller that does the trick and call 
 it, e.g., with curl from the commandline.
 2. same thing, curl from the commandline, or use urllib2, or something 
 that basically does a request to your webserver.

 Il giorno venerdì 11 gennaio 2013 14:53:27 UTC+1, Daniel Gonzalez ha 
 scritto:

 Thanks, that makes sense. In that context, I have two questions:

1. How do I call cache.ram.clear from outside web2py. What web2py 
modules should I include?
2. How can I call a controller disguised as a user? I think this 
would be the most robust way, if it is possible ...


 On Friday, January 11, 2013 2:42:37 PM UTC+1, Niphlod wrote:

 Cache is always related to a key. In your function, that key is 
 request.env.path_info
 Let's assume your key is *the_key*
 If you need to invalidate the cache, you should use cache.ram.clear(*
 the_key*) or cache.ram(*the_key*, None). From here one, there are 2 
 paths ahead of you:
 - you have an empty cache and it will be filled at the 1st request 
 coming from an user after you called clear()
 - you want to fill that key after clear() ASAP

 In the 1st case, after calling clear() you don't have to do nothing.

 In the 2nd case, either you call the controller disguised as a user or 
 you process the data and store it using cache.ram(*the_key*, thevalue)

 Il giorno venerdì 11 gennaio 2013 13:07:08 UTC+1, Daniel Gonzalez ha 
 scritto:

 Hi,

 I am serving some data which is expensive to compute with 
 a @service.jsonrpc controller. I want to cache the result in RAM, using 
 something like:

 @cache(request.env.path_info,time_expire=1000,cache_model=cache.ram)

 My data will not change very often, so I want to have a big ttl 
 (actually, I would like a ttl forever, is this possible?)

 But my main problem is this: in my architecture, web2py does not know 
 when new data is available (the data is in a third-party database, 
 completely out of control of web2py). Changes to the data happen 
 asynchronously, according to business processes.

 I have three pieces:

1. web2py serving the data to the clients, via jsonrpc
2. a small script which knows (long-polling) when changes in the 
third-party database occur
3. a library to process the information in the third-party 
database. Calling this must be avoided at all costs, *except* when we 
 have 
actual changes (which is why I want to add the cache)

 The easiest implementation for me would be to be able, from the 
 external script, to invalidate the web2py cache whenever I detect changes 
 relevant to the active sessions (not the whole cache, just the part 
 related 
 to my jsonrpc controller)

 Is this possible? Maybe by calling a web2py controller which is in 
 charge of invalidating the cache?

 What about the session? I assume the web2py cache is session-related. 
 My script should call the web2py controller using the correct session, but 
 I do not know how to handle this.

 Thanks,
 Daniel



-- 





[web2py] Running some code at the end of the request

2013-01-11 Thread Daniel Gonzalez
Hi,

I would like to run some code when the request has been processed, but I do 
not want to modify all my controllers for this.
To run something at the beginning of every request, I just need to put my 
code on the models/db.py.
Is it possible to run code at the end of the request processing too?

Thanks,
Daniel

-- 





[web2py] Establishin a session with contrib.WebClient

2012-12-24 Thread Daniel Gonzalez
Hi,

I am trying to test my application with WebClient. My application has a 
non-standard login process, based on a couple of redirects.
When login manually in the browser, everything works fine. Taking a look at 
the requests, I see that after the first redirect a session cookie appears 
in the request.

When doing the same POST request with WebClient, the session cookie does 
not appear after the first redirect.

I wonder if the redirects are handled internally in web2py, or if they 
communicate with the client (browser / WebClient).

Eventually the cookie is sent back in the reply to WebClient, but in 
between redirects the session is not yet set (only when testing with 
WebClient), which makes my test fail because session specific data which is 
setup during the redirect phase can not be configured.

How to handle the redirects with WebClient?

Thanks,

Daniel Gonzalez

-- 





[web2py] Re: Establishin a session with contrib.WebClient

2012-12-24 Thread Daniel Gonzalez
Trying to answer some of my questions.
The redirects are handled by the client. In the case of WebClient probably 
by the urrlib2 library.
Now my question is: how do I tell the urllib2 library used by WebClient to 
properly setup the cookies when following a redirect?

Thanks,
Daniel

-- 





[web2py] Re: Using contrib.webclient to test JSONRPC interfaces

2012-12-24 Thread Daniel Gonzalez
Mmm, thanks. I have not taken a look at that yet. I will.
Nevertheless, I like the idea of having an integrated client to handle all 
kind of requests (including jsonrpc), which makes it easier for me for 
statistics and performance gathering.

On Monday, December 24, 2012 6:44:59 AM UTC+1, Massimo Di Pierro wrote:

 Hello Daniel,

 getting back at this. Why use webclient for this instead of using 
 gluon/contrib/simplejsonrpc.py?  its seems to me it does not belong there.

 On Monday, 17 December 2012 14:01:18 UTC-6, Daniel Gonzalez wrote:

 I have slightly modified the WebClient to support jsonrpc. I am not sure 
 everything is correctly covered, but it is suiting my needs.

 In case you are interested, you can see the changes here:

 https://github.com/gonvaled/web2py/tree/webclient_add_jsonrpc

 The biggest problem I had was 
 that opener.addheaders.append((key,str(value))) is not working as (I) 
 expected: the content-type is not rewritten:

 http://stackoverflow.com/questions/13920211/not-possible-to-set-content-type-to-application-json-using-urllib2

 On Monday, December 17, 2012 6:38:30 PM UTC+1, Daniel Gonzalez wrote:

 Hi,

 I am trying to understand how to use the included WebClient to test a 
 JSONRPC interface. One showstopper for me at the moment is that I see the 
 following in WebClient.post:

 # time the POST request
 data = urllib.urlencode(data)
 t0 = time.time()
 self.response = opener.open(self.url,data)
 self.time = time.time()-t0

 When doing JSONRPC accesses I do not want the data to be urlencoded. 
 Actually, I will prepare the data with json.dump, and I want WebClient to 
 POST it transparently (I guess this goes in the body of the POST request). 
 Is this at all possible? Is there an example of WebClient usage 
 for JSONRPC interfaces somewhere?

 Thanks,
 Daniel Gonzalez



-- 





[web2py] Re: Establishin a session with contrib.WebClient

2012-12-24 Thread Daniel Gonzalez
I found a workaround: first send a login request without cookies to *get* 
the session cookie from web2py, and then do a second login request with the 
cookie, to give web2py a chance to set the session data. This sets up my 
tester with a valid session cookie, which corresponds to valid session data 
in web2py, and my testing can start.

This is a dirty way of handling the redirect (actually, it is *not* 
handling the redirect, which is still handled internally - twice - in 
urrlib2), but since I do not yet know how to modify WebClient to properly 
handle redirects, I will have to settle with this for the time being.

On Monday, December 24, 2012 2:38:48 PM UTC+1, Daniel Gonzalez wrote:

 Trying to answer some of my questions.
 The redirects are handled by the client. In the case of WebClient probably 
 by the urrlib2 library.
 Now my question is: how do I tell the urllib2 library used by WebClient to 
 properly setup the cookies when following a redirect?

 Thanks,
 Daniel


-- 





[web2py] Re: Using contrib.webclient to test JSONRPC interfaces

2012-12-18 Thread Daniel Gonzalez
Indeed Massimo, that is the file.

Some comments:

   - I am forcing Content-Type to 'application/json-rpc' in WebClient.post
   - The data must be already json encoded
   - The opener.addheaders is still used, but since I am using 
   a urllib2.Request (to *really* force the Content-Type, which can not be 
   done with addheaders, as you can see in the previously linked StackOverflow 
   question), I would say the headers set with addheaders are not really 
   active.
   - That means self.detault_headers are probably not used
   - for jsonrpc post I have disabled form processing
   - and last but not least, my changes are based on 2.0.2. I assume no big 
   changes have been done for the WebClient since then, but I have not 
   verified.

I am not sure what are the implicactions of all these changes. Maybe some 
corrections are in order.

On Tuesday, December 18, 2012 4:27:26 AM UTC+1, Massimo Di Pierro wrote:

  you point me to the file? Is it this one?


 https://github.com/gonvaled/web2py/blob/webclient_add_jsonrpc/gluon/contrib/webclient.py


 On Monday, 17 December 2012 14:01:18 UTC-6, Daniel Gonzalez wrote:

 I have slightly modified the WebClient to support jsonrpc. I am not sure 
 everything is correctly covered, but it is suiting my needs.

 In case you are interested, you can see the changes here:

 https://github.com/gonvaled/web2py/tree/webclient_add_jsonrpc

 The biggest problem I had was 
 that opener.addheaders.append((key,str(value))) is not working as (I) 
 expected: the content-type is not rewritten:

 http://stackoverflow.com/questions/13920211/not-possible-to-set-content-type-to-application-json-using-urllib2

 On Monday, December 17, 2012 6:38:30 PM UTC+1, Daniel Gonzalez wrote:

 Hi,

 I am trying to understand how to use the included WebClient to test a 
 JSONRPC interface. One showstopper for me at the moment is that I see the 
 following in WebClient.post:

 # time the POST request
 data = urllib.urlencode(data)
 t0 = time.time()
 self.response = opener.open(self.url,data)
 self.time = time.time()-t0

 When doing JSONRPC accesses I do not want the data to be urlencoded. 
 Actually, I will prepare the data with json.dump, and I want WebClient to 
 POST it transparently (I guess this goes in the body of the POST request). 
 Is this at all possible? Is there an example of WebClient usage 
 for JSONRPC interfaces somewhere?

 Thanks,
 Daniel Gonzalez



-- 





[web2py] Web2py thread management

2012-12-18 Thread Daniel Gonzalez
Hi,

How are threads managed in web2py? I am stress testing with a multithreaded 
programm, and I see that web2py spawns 14 worker threads.
These threads are not created/destroyed, but seem to run forever.

python,8698 web2py.py -a 
  |-{python},9005
  |-{python},9023
  |-{python},9042
  |-{python},9043
  |-{python},9044
  |-{python},9050
  |-{python},9051
  |-{python},9053
  |-{python},9054
  |-{python},9055
  |-{python},9057
  |-{python},9058
  |-{python},9059
  `-{python},9060

I have several questions:

   - How do these threads map to the requests? Does each thread serve a 
   request?
   - That means web2py can maximally cope with 14 parallel requests?
   - Is this number (14) configurable?
   - Are the objects defined in the models initialized at thread creation, 
   and then reused for all requests?

Thanks,

Daniel

-- 





[web2py] Using contrib.webclient to test JSONRPC interfaces

2012-12-17 Thread Daniel Gonzalez
Hi,

I am trying to understand how to use the included WebClient to test a 
JSONRPC interface. One showstopper for me at the moment is that I see the 
following in WebClient.post:

# time the POST request
data = urllib.urlencode(data)
t0 = time.time()
self.response = opener.open(self.url,data)
self.time = time.time()-t0

When doing JSONRPC accesses I do not want the data to be urlencoded. 
Actually, I will prepare the data with json.dump, and I want WebClient to 
POST it transparently (I guess this goes in the body of the POST request). 
Is this at all possible? Is there an example of WebClient usage 
for JSONRPC interfaces somewhere?

Thanks,
Daniel Gonzalez

-- 





Re: [web2py] Specify password strengh, with error feedback

2012-12-17 Thread Daniel Gonzalez
Thanks, this was very helpful.

On Monday, December 17, 2012 4:05:02 AM UTC+1, Massimo Di Pierro wrote:

 Which you can find here:


 http://web2py.com/examples/static/epydoc/web2py.gluon.validators.IS_STRONG-class.html

 On Sunday, 16 December 2012 17:49:51 UTC-6, Jonathan Lundell wrote:

 On 16 Dec 2012, at 3:47 PM, Daniel Gonzalez gonv...@gmail.com wrote:

 Is is possible to specify what kind of password is allowed? For example, 
 let's say I want:

- length =8
- at least 1 uppercase
- at least 1 lowercase
- at least 1 number
- at least 1 char in a pre-defined set()

 I would also like to give the end-user information about why the password 
 did not pass the cut, like At least one uppercase is needed.

 How would this be done in web2py?


 Have a look at IS_STRONG. 



-- 





[web2py] Re: Using contrib.webclient to test JSONRPC interfaces

2012-12-17 Thread Daniel Gonzalez
I have slightly modified the WebClient to support jsonrpc. I am not sure 
everything is correctly covered, but it is suiting my needs.

In case you are interested, you can see the changes here:

https://github.com/gonvaled/web2py/tree/webclient_add_jsonrpc

The biggest problem I had was 
that opener.addheaders.append((key,str(value))) is not working as (I) 
expected: the content-type is not rewritten:
http://stackoverflow.com/questions/13920211/not-possible-to-set-content-type-to-application-json-using-urllib2

On Monday, December 17, 2012 6:38:30 PM UTC+1, Daniel Gonzalez wrote:

 Hi,

 I am trying to understand how to use the included WebClient to test a 
 JSONRPC interface. One showstopper for me at the moment is that I see the 
 following in WebClient.post:

 # time the POST request
 data = urllib.urlencode(data)
 t0 = time.time()
 self.response = opener.open(self.url,data)
 self.time = time.time()-t0

 When doing JSONRPC accesses I do not want the data to be urlencoded. 
 Actually, I will prepare the data with json.dump, and I want WebClient to 
 POST it transparently (I guess this goes in the body of the POST request). 
 Is this at all possible? Is there an example of WebClient usage 
 for JSONRPC interfaces somewhere?

 Thanks,
 Daniel Gonzalez


-- 





[web2py] web2py performance, without db

2012-12-17 Thread Daniel Gonzalez
Hi,

I am trying to get some metrics on my installation. For that I have 
disabled the database (db=None) and I am requesting a very simple 
controller:

def hello1():
return Hello World

I have a multi-threaded test program which is sending requests to web2py 
(using WebClient). I have let my test run for several iterations, and I got 
the following metrics:

CLIENTS ROUNDS ELLAPSED (s)TOT REQ   AVG (ms)  REQ/s
  8 72 17.969576 31.197  32.05
  9 25  6.973225 30.991  32.27
  6  4  0.748 24 31.179  32.07
  7 17  3.645119 30.634  32.64
  7 58 12.340406 30.393  32.90
  3 73  6.751219 30.827  32.44
 10 12  3.399120 28.329  35.30
  4 32  3.941128 30.791  32.48
  1 27  0.742 27 27.496  36.37
  8 58 14.156464 30.508  32.78
  4 31  3.574124 28.819  34.70
  8 14  3.274112 29.232  34.21
  9 68 18.722612 30.591  32.69
  9 81 22.070729 30.275  33.03
  4 47  6.031188 32.079  31.17
  7 75 15.491525 29.506  33.89
  1 90  2.495 90 27.719  36.08
  8 38  9.495304 31.234  32.02
  2 60  4.000120 33.335  30.00
  2 81  5.057162 31.214  32.04

(CLIENTS is the number of active threads, ROUNDS is the number of requests 
that each thread performs)

As you see, I am getting quite stable speed of between 30 and 36 requests/s.
This is fine, but 32 req/s is quite low. My system is (this is my 
development system, an HP 635):

   - web2py 2.0.2
   - 2 cores, AMD E-450 
   - 4 GB RAM
   - Linux 2.6.32-5-686
   - CrunchBang Linux statler
   - Python 2.7.2
   - I am using Rocket
   - No apache (or any other frontend). Directly accessing localhost:8000
   - web2py and my test program are sharing the same machine.

I would like to optimize these parameters before moving to production. Is 
there something obvious that I could try to improve these metrics?
Is 30 req/s an expected value for such a simple test? I expected more than 
100 req/s.

Now that I am writing and thinking about this, I am not even sure if the 
limiting factor is web2py or my test program ... How could I know which 
party is saturating?

Thanks,

Daniel

-- 





[web2py] Reusing expensive objects

2012-12-17 Thread Daniel Gonzalez
Hi,

My application uses some objects which are quite slow to setup. I create 
this object in the models file, so that they are available for all 
controllers.

Specifically, most of my processing is delegated to a celery queue (based 
on rabbitmq). The interface to this queue is wrapped by a class 
(MessageQueueClient) which I instantiate in the model file db.py. If I 
understand things correctly, this object will be instantiated for each 
request coming to web2py.

Would it be possible to reuse these objects, so that successive requests do 
not need to create them again? How could this be done?

Thanks,
Daniel

-- 





[web2py] Re: Prevent calling compute when doing an update

2012-12-16 Thread Daniel Gonzalez
Mmmm ... I see. I actually went another route: I am passing all existing 
parameters to the update_record function, changing only the password. By 
passing the existing parameters, it seems the compute function is not 
called.

On Saturday, December 15, 2012 3:26:41 PM UTC+1, Massimo Di Pierro wrote:

 You can set 

 db.table.field.compute = lambda: 

 only in the actions that need it.

 On Saturday, 15 December 2012 04:26:33 UTC-6, Daniel Gonzalez wrote:

 Hi,

 I am implementing a password update feature. I am doing something like 
 this:

 def change_pass(email, new_pass):
 my_query = db[auth.settings.table_user_name].email == email
 my_set   = db(my_query)
 my_set.update(password = new_pass)

 The problem is that this is calling one of my compute definitions in one 
 of the fields.

 Field('third_party_entity', compute=
 big_and_ugly_code_only_intended_for_new_entries)

 My compute is not intended to be used for updates, but only for new 
 record creations.
 I do not want update to call the compute functions. Actually, I do not 
 want update to do *anything* except updating the field that I 
 am explicitly giving. Is this possible?

 Thanks,
 Daniel Gonzalez



-- 





[web2py] Specify password strengh, with error feedback

2012-12-16 Thread Daniel Gonzalez
Hi,

Is is possible to specify what kind of password is allowed? For example, 
let's say I want:

   - length =8
   - at least 1 uppercase
   - at least 1 lowercase
   - at least 1 number
   - at least 1 char in a pre-defined set()

I would also like to give the end-user information about why the password 
did not pass the cut, like At least one uppercase is needed.

How would this be done in web2py?

Thanks,
Daniel

-- 





[web2py] Moving from 2.0.2 to R-2.3.1: undefined with globals in models

2012-12-16 Thread Daniel Gonzalez
Hi,

My application is using 2.0.2 I have some global variables defined in db.py 
which I am using in my controllers.
Now I have tried to move to the latest web2py version (2.3.1), and those 
globals can not be accessed from the controllers.

Has there been any important change in this regard? Do I need to import 
the models in my controllers now, in order to access the global variables 
defined there?

Thanks,
Daniel

-- 





[web2py] Prevent calling compute when doing an update

2012-12-15 Thread Daniel Gonzalez
Hi,

I am implementing a password update feature. I am doing something like this:

def change_pass(email, new_pass):
my_query = db[auth.settings.table_user_name].email == email
my_set   = db(my_query)
my_set.update(password = new_pass)

The problem is that this is calling one of my compute definitions in one of 
the fields.

Field('third_party_entity', compute=
big_and_ugly_code_only_intended_for_new_entries)

My compute is not intended to be used for updates, but only for new record 
creations.
I do not want update to call the compute functions. Actually, I do not want 
update to do *anything* except updating the field that I 
am explicitly giving. Is this possible?

Thanks,
Daniel Gonzalez

-- 





[web2py] Forcing minus for converted parameter names in form helpers

2012-11-20 Thread Daniel Gonzalez
Hi,

I am trying to create a radio component in a custom web2py form, using 
twitter bootstrap styles, as explained 
herehttp://twitter.github.com/bootstrap/javascript.html#buttons
.
In order for the button group to behave like a radio button, we need to 
specify the 'data-toggle=buttons-radio' modifier.
I have tried to do this in web2py with '_data_toggle=buttons-radio', but 
web2py is generating data_toggle instead of data-toggle (underscore instead 
of minus).
Is there a way to tell web2py to convert the underscores in the parameter 
names to minus instead of underscore?

This is my code:

def get_bootstrap_radio(options):
'''div class=btn-group data-toggle=buttons-radio
   button class=btn type=button1/button
   button class=btn type=button2/button
   button class=btn type=button3/button
   /div'''
i = []
for value in options:
 i.append(BUTTON(value, _type=button, _class=btn))
return DIV(*i, _class='btn-group', _data_toggle=buttons-radio)

Thanks,
Daniel

-- 





[web2py] Re: Forcing minus for converted parameter names in form helpers

2012-11-20 Thread Daniel Gonzalez
Thanks Niphlod, this is working. For the record:

def get_bootstrap_radio(options):
'''div class=btn-group data-toggle=buttons-radio
   button class=btn type=button1/button
   button class=btn type=button2/button
   button class=btn type=button3/button
   /div'''
i = []

for value in options:
i.append(BUTTON(value, _type=button, _class=btn))
return DIV(*i, _class='btn-group', **{'_data-toggle': buttons-radio })



On Tuesday, November 20, 2012 9:50:48 AM UTC+1, Niphlod wrote:

 this is beginning to be a FAQ

 http://web2py.com/books/default/chapter/29/05?search=data-

 On Tuesday, November 20, 2012 9:37:34 AM UTC+1, Daniel Gonzalez wrote:

 Hi,

 I am trying to create a radio component in a custom web2py form, using 
 twitter bootstrap styles, as explained 
 herehttp://twitter.github.com/bootstrap/javascript.html#buttons
 .
 In order for the button group to behave like a radio button, we need to 
 specify the 'data-toggle=buttons-radio' modifier.
 I have tried to do this in web2py with '_data_toggle=buttons-radio', 
 but web2py is generating data_toggle instead of data-toggle (underscore 
 instead of minus).
 Is there a way to tell web2py to convert the underscores in the parameter 
 names to minus instead of underscore?

 This is my code:

 def get_bootstrap_radio(options):
 '''div class=btn-group data-toggle=buttons-radio
button class=btn type=button1/button
button class=btn type=button2/button
button class=btn type=button3/button
/div'''
 i = []
 for value in options:
  i.append(BUTTON(value, _type=button, _class=btn))
 return DIV(*i, _class='btn-group', _data_toggle=buttons-radio)

 Thanks,
 Daniel



-- 





[web2py] Showing a fixed URL for a web2py application

2012-10-29 Thread Daniel Gonzalez
Hi,

In my application, I would like the URL being shown to the user to be 
always the same (http://www.myapp.com), no matter what page the user is 
currently browsing.
The idea is that the user should not be confused about the internal 
structure of my application. The links in the page would remain as they 
are, but the browser would show always the same address.

Is this at all possible with web2py? What side-effects could this have?

Thanks,
Daniel

-- 





[web2py] Implementing a self-modifying form in web2py

2012-10-28 Thread Daniel Gonzalez
Hello,

I am trying to implement a contact form (similar to the one in gmail) with 
web2py. I have problems implementing the following feature: the user should 
be able to expand the form, by adding new entries to the contact (for other 
telephone numbers, or other information). The user is presented at first 
with a simple form, and then a Add button should show a new input field. 
This field should be:

   - added *without* forcing a reload of the page
   - it should be processed by web2py when the form is submitted.

I guess this is only possible to be implemented with complicated jQuery 
logic (or similar client-side programming). Or is there a simple way to 
implement this in web2py?

Thanks,
Daniel

-- 





[web2py] Display a list of dictionaries as an html table

2012-10-26 Thread Daniel Gonzalez
Hello,

I am generating some data on the fly (no database), which I would like to 
display using a controller / view. The data is organized as a list of 
dictionaries, like this:

headers = [ 'header1', 'header2' ]
data = [
  { 'col1' : 'valA', 'col2' : 'valB' },
  { 'col1' : 'valC', 'col2' : 'valD },
]  

How can I code a controller to return an already prepared table for my view?

Thanks,
Daniel

-- 





[web2py] Using PYTHONOPTIMIZE with web2py

2012-09-21 Thread Daniel Gonzalez
Hi,

I am running web2py via apache wsgi. What is the suggested way to run the 
python interpreter with PYTHONOPTIMIZE?
Are there any known incompatibilities between web2py and PYTHONOPTIMIZE?

Thanks,
Daniel

-- 





[web2py] Submitting a form with a link

2012-09-10 Thread Daniel Gonzalez
Hi,

I am preparing a customized log-in form. I want to add a link to recover 
the password, which is implemented with the A(..) element.
In the controller function where I want to send an email, I need to access 
the email given by the user. I do that with request.vars.email.
The problem is that, since the form was not submitted, the email is empty.

How can I submit the form with an A() element?
Please note that I *do not* want to have an extra button with Lost 
Password to submit the form. I really want it to be a link.

Is this possible?

Thanks,
Daniel

-- 





  1   2   3   >