[web2py] Cant access Google Cloud SQL on GAE application

2017-10-12 Thread Bernardo Leon
Hello, me again. I am testing Google Cloud Platform along with pycharm (I 
added a new run configuration for gae inside pycharm) and I have the 
following model:

# -*- coding: utf-8 -*-
from gluon.tools import Auth

db = DAL('google:sql://trahello:trahello-db/trahello')

I have installed the google app engine local server and did their hello 
world tutorial so I think my installation is fine.

When I hit the run button my console gives no errors:

INFO 2017-10-13 04:40:50,304 sdk_update_checker.py:231] Checking for 
updates to the SDK.
INFO 2017-10-13 04:40:51,108 sdk_update_checker.py:259] The SDK is up 
to date.
INFO 2017-10-13 04:41:03,088 api_server.py:300] Starting API server at: 
http://localhost:36575
INFO 2017-10-13 04:41:03,146 dispatcher.py:251] Starting module 
"default" running at: http://127.0.0.1:8080
INFO 2017-10-13 04:41:03,147 admin_server.py:116] Starting admin server 
at: http://localhost:8000

but when I try to open my app url: http://localhost:8080/trahello I get the 
following error.

Traceback (most recent call last):
  File 
"/home/bernardo/PycharmProjects/w2p_trahello/web2py/gluon/restricted.py", 
line 219, in restricted
exec(ccode, environment)
  File 
"/home/bernardo/PycharmProjects/w2p_trahello/web2py/applications/trahello/models/modelo.py",
 
line 4, in 
db = DAL('google:sql://trahello:trahello-db/trahello')
  File 
"/home/bernardo/PycharmProjects/w2p_trahello/web2py/gluon/packages/dal/pydal/base.py",
 
line 170, in __call__
obj = super(MetaDAL, cls).__call__(*args, **kwargs)
  File 
"/home/bernardo/PycharmProjects/w2p_trahello/web2py/gluon/packages/dal/pydal/base.py",
 
line 475, in __init__
"Failure to connect, tried %d times:\n%s" % (attempts, tb)
RuntimeError: Failure to connect, tried 5 times:
Traceback (most recent call last):
  File 
"/home/bernardo/PycharmProjects/w2p_trahello/web2py/gluon/packages/dal/pydal/base.py",
 
line 455, in __init__
self._adapter = adapter(**kwargs)
  File 
"/home/bernardo/PycharmProjects/w2p_trahello/web2py/gluon/packages/dal/pydal/adapters/__init__.py",
 
line 40, in __call__
obj = super(AdapterMeta, cls).__call__(*args, **kwargs)
  File 
"/home/bernardo/PycharmProjects/w2p_trahello/web2py/gluon/packages/dal/pydal/adapters/base.py",
 
line 368, in __init__
super(SQLAdapter, self).__init__(*args, **kwargs)
  File 
"/home/bernardo/PycharmProjects/w2p_trahello/web2py/gluon/packages/dal/pydal/adapters/base.py",
 
line 50, in __init__
self._initialize_(do_connect)
  File 
"/home/bernardo/PycharmProjects/w2p_trahello/web2py/gluon/packages/dal/pydal/adapters/google.py",
 
line 32, in _initialize_
super(GoogleSQL, self)._initialize_(do_connect)
  File 
"/home/bernardo/PycharmProjects/w2p_trahello/web2py/gluon/packages/dal/pydal/adapters/mysql.py",
 
line 24, in _initialize_
user = self.credential_decoder(m.group('user'))
IndexError: no such group

Since the google adapter inherits from MySQL adapter it tries to run the 
_initialize_ method of the MySQL adapter which in turn tries to get the 
user and the password from the Google SQL URI. Is this an expected 
behaviour? 

How good is the Google Cloud Platform support on web2py? I am using the 
most recent stable version: Version 
2.15.4-stable+timestamp.2017.09.02.04.02.22

Thank you for any insight!

-- 
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: How to customize widgets to act like Onsen UI components

2017-09-16 Thread Bernardo Leon
You are right, thank you!

El sábado, 16 de septiembre de 2017, 17:58:36 (UTC-5), Anthony escribió:
>
> On Saturday, September 16, 2017 at 4:23:43 PM UTC-4, Bernardo Leon wrote:
>>
>> Awesome as always Anthony Thank you!
>>
>> Yes I am talking about the SQLFORM Field objects.
>>
>> So I will need to create a Widget by subclassing FormWidget and return 
>> the Ons tag object and later monkey patch. I will try this way. Thank you 
>> for your ideas :)
>>
>
> Note, you don't have to monkey patch SQLFORM.widgets -- that's only if you 
> want your custom widgets to be used by default without having to do:
>
> Field(..., widget=my_custom_widget)
>
> 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: How to customize widgets to act like Onsen UI components

2017-09-16 Thread Bernardo Leon
Awesome as always Anthony Thank you!

Yes I am talking about the SQLFORM Field objects.

So I will need to create a Widget by subclassing FormWidget and return the 
Ons tag object and later monkey patch. I will try this way. Thank you for 
your ideas :)


El sábado, 16 de septiembre de 2017, 13:50:31 (UTC-5), Anthony escribió:
>
> If you are talking about using SQLFORM with a DAL table, when you define 
> Field objects, you can specify a custom widget via the "widget" argument -- 
> it must be a callable object that takes a Field object and a value. For 
> more details, see 
> http://web2py.com/books/default/chapter/29/07/forms-and-validators#Widgets
> .
>
> Also, you can create any custom HTML tag using the TAG helper:
>
> TAG['ons-input'](_type='text', _value='hello')
>
> produces:
>
> 
>
> Note, if you simply use the TAG helper to generate markup, you won't get 
> the validation behavior of the standard INPUT helper. As an alternative, 
> you can create a custom tag based on the INPUT helper:
>
> class OnsInput(INPUT):
> tag = 'ons-input'
>
> You could then do:
>
> OnsInput(_type='text', _value='hello', requires=db.myfield.requires)
>
> The above will produce the same HTML markup, but the resulting Python 
> object will also be able to validate its input. You could do the same for 
> the SELECT helper.
>
> Based on the above, you could create custom widgets -- see the various 
> widget classes in gluon.sqlhtml. Once you've got some custom widgets, you 
> could then monkey patch SQLFORM.widgets by overwriting some or all of its 
> items with your custom classes -- then your custom widgets will be the 
> defaults used by SQLFORM.
>
> Anthony
>
> On Friday, September 15, 2017 at 10:46:38 PM UTC-4, Bernardo Leon wrote:
>>
>> I have been researching about UI Frameworks and stumbled upon Onsen UI 
>> <https://onsen.io/>. It seems easy and provides good results but to use 
>> this UI Framework I need to use their components which are html tags.
>>
>> If I have a field that is rendered as an html input how can I customize 
>> its widget so I can use  instead of  and so on? Thank you!
>>
>

-- 
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] How to customize widgets to act like Onsen UI components

2017-09-15 Thread Bernardo Leon
I have been researching about UI Frameworks and stumbled upon Onsen UI 
. It seems easy and provides good results but to use 
this UI Framework I need to use their components which are html tags.

If I have a field that is rendered as an html input how can I customize its 
widget so I can use  instead of  and so on? Thank you!

-- 
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: response.js does not execute in the oncreate callback

2017-07-22 Thread Bernardo Leon
Hi Massimo, done. The issue is #1693

Try to take a look at it please, thank you!

El sábado, 22 de julio de 2017, 15:35:57 (UTC-5), Massimo Di Pierro 
escribió:
>
> Please open a ticket about this it gets tracked.
>
> On Thursday, 20 July 2017 20:43:40 UTC-5, Bernardo Leon wrote:
>>
>> Hello, I have a component which has an SQLFORM.grid and an oncreate and 
>> ondelete callbacks on which I execute a response.js. When I delete a record 
>> the response.js javascript function is executed but when I create a record 
>> the response.js javascript function does not get executed (but the python's 
>> oncreate function gets executed)
>>
>> This is my controller code:
>>
>> def oncreate_empleado(form):
>> # This method executes but the response_gestor_empleados javascript 
>> function is not executed
>> response.js = 'response_gestor_empleados(%i);' % form.vars.id
>>
>>
>> def ondelete_empleado(table, id):
>> # Here the response_gestor_empleados javascript function gets executed
>> response.js = 'response_gestor_empleados(5);'
>>
>>
>> def index():
>>
>> grid_empleados = SQLFORM.grid(db.empleado,
>>   orderby=[db.empleado.apellidos, 
>> db.empleado.nombres],
>>   links=[dict(header='',
>>   body=lambda registro: 
>> crear_boton_seleccionar_empleado(registro))],
>>   details=False,
>>   csv=False,
>>   formname='grid_empleados',
>>   oncreate=oncreate_empleado,
>>   ondelete=ondelete_empleado)
>>
>> return dict(grid_empleados=grid_empleados)
>>
>> Is this a bug or am I doing something wrong? Thank you!
>>
>

-- 
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: Is a good practice add .table files to source control?

2017-07-21 Thread Bernardo Leon
You are right, maybe a development server and a production server could 
have different .table files but share the same model file. There is no 
problem for us to keep one of our versions with fake_migrate=True. Can we 
switch who is using migrate=True? What happens if both of us use 
migrate=True at the same time? Thank you!

El jueves, 20 de julio de 2017, 18:57:18 (UTC-5), Leonel Câmara escribió:
>
> I don't put the databases folder under source control. This way I can 
> update the in production version without worries. If you two are sharing 
> the same database in development, which I don't do in my team, then the 
> best is for one of you to always have migrations enabled with fake_migrate 
> True and the other one to have migrate True and fake_migrate 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: Page with four LOAD components is too slow

2017-07-21 Thread Bernardo Leon
It seems that you are right, I set up a virtual machine with 4gb ram only 
for the database and I ran the code along with redis on my laptop with 16gb 
ram and my times now are nearly the 600ms. I think it is good enough. 
Having some components that don't perform selects rendering only a simple 
html taking nearly 500ms is suspicious though.

Thank you Leonel! Using redis and assigning more RAM seems to be the best 
tips to improve the request performance (besides the book recommendations 
like lazy_tables, pool_size, extraction functions to modules, etc)

Just for curiosity, what are the hardware specs of your server? Thank you

El viernes, 21 de julio de 2017, 6:19:48 (UTC-5), Leonel Câmara escribió:
>
> Yes I'm pretty sure it's a RAM issue, 48 free MB is way too low. You 
> easily start having to use virtual memory with a couple of requests.   
>   
> To give you an idea, on a similar setup but a much better machine, I have 
> a much much more complex page than yours appears to be, with quite a lot of 
> ajax calls and complex db queries loading everything in 700ms.  
>

-- 
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] response.js does not execute in the oncreate callback

2017-07-20 Thread Bernardo Leon
Hello, I have a component which has an SQLFORM.grid and an oncreate and 
ondelete callbacks on which I execute a response.js. When I delete a record 
the response.js javascript function is executed but when I create a record 
the response.js javascript function does not get executed (but the python's 
oncreate function gets executed)

This is my controller code:

def oncreate_empleado(form):
# This method executes but the response_gestor_empleados javascript 
function is not executed
response.js = 'response_gestor_empleados(%i);' % form.vars.id


def ondelete_empleado(table, id):
# Here the response_gestor_empleados javascript function gets executed
response.js = 'response_gestor_empleados(5);'


def index():

grid_empleados = SQLFORM.grid(db.empleado,
  orderby=[db.empleado.apellidos, 
db.empleado.nombres],
  links=[dict(header='',
  body=lambda registro: 
crear_boton_seleccionar_empleado(registro))],
  details=False,
  csv=False,
  formname='grid_empleados',
  oncreate=oncreate_empleado,
  ondelete=ondelete_empleado)

return dict(grid_empleados=grid_empleados)

Is this a bug or am I doing something wrong? Thank you!

-- 
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: Page with four LOAD components is too slow

2017-07-20 Thread Bernardo Leon
Yes, the application, redis and the database are in the same server. This 
server has 512 MB of RAM but I don't think I am using all the ram. I have 
48mb free right now. Regarding the code, it just makes simple selects on 
one or two tables (the querys arent doing anything weird). Do you still 
think it is a RAM issue?

What should be a normal load time for a component? Thank you!

El jueves, 20 de julio de 2017, 19:08:37 (UTC-5), Leonel Câmara escribió:
>
> That still seems slow actually. Is redis on that same machine or could you 
> have latency issues there too? If it is then it's hard to tell what's 
> causing the slowness now that everything is in the same machine. We would 
> need to know the machine specs and what your code is doing exactly. You may 
> simply need more RAM. 
>

-- 
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] Is a good practice add .table files to source control?

2017-07-20 Thread Bernardo Leon
If two developers use git to develop an application and obviously they have 
their model file on git do they need to have the same .table files?

I have a postgresql development database on a digitalocean server and my 
partner is unable to connect to the database that I created originally even 
if both of us have the same model file, does she need exactly my .table 
files? Do this files store the state of the database? if so Is it a good 
idea to add this files to source control? Thank you!

-- 
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: Page with four LOAD components is too slow

2017-07-20 Thread Bernardo Leon
Thank you to both of you. Anthony I was using redis to handle my sessions 
hence I can discard that bottleneck besides I need the session info on my 
components. 

It seems that web2py performs more querys to the database than expected. I 
have the database on digitalocean but was using web2py on my machine. I 
tried deploying the app in the same server of the database and now it is 
more responsive. I have reduced the time a component is loaded from 5-6 
seconds to 1.30 seconds max. 

I wasn't expecting this since I think the same quantity of information 
travels through internet on both cases 
[(local browser + local web2py  internet db) ~ (local browser  
internet web2py + internet db)] 

unless web2py makes more calls to the db than I supposed it to do.

Finally, is 1.30 seconds a good speed? My components perform only selects 
to tables with no more than 5 records so I don't think it is an application 
issue. Is it ok? Thank you

El miércoles, 19 de julio de 2017, 11:51:22 (UTC-5), Bernardo Leon escribió:
>
> Hi, I am facing a problem with performance. I have a view with four LOAD 
> calls that is taking almost 15 seconds to load. I know that two of this 
> components are loaded after the two first LOAD calls but 15 seconds is 
> still too much time. So I profiled the execution of my view and end up with 
> the runpythonrun image I am attaching.
>
> This is my DAL definition:
>
> db = DAL(gth_dev_db_connection_string,
>  lazy_tables=True,
>  pool_size=15,
>  migrate=False)
>
> And I don't have functions on my model file (I am importing them from 
> modules).
>
> What could be the problem?
>
> Thank you!
>
>
>

-- 
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: app slow on pythonanywhere

2017-07-19 Thread Bernardo Leon
I am using now redis for session handling on the same machine of the 
webserver and got rid of big fcntl.flock lock. Thank you so much for your 
help!

El martes, 18 de julio de 2017, 23:04:33 (UTC-5), Bernardo Leon escribió:
>
> Thank you for your answer, Indeed I am using several ajax requests and I 
> am not able to use session.forget(response) on my components since I need 
> the session information. I have installed redis to test but now I am facing 
> another problem that I have detailed here: 
> https://groups.google.com/forum/#!topic/web2py/fFdQES5Z6oM It seems that 
> now I am not able to log into the application if I try to store sessions on 
> redis, I am sorry to bother and thank you again!
>
> El lunes, 17 de julio de 2017, 19:23:55 (UTC-5), Leonel Câmara escribió:
>>
>> That's probably caused by sessions, file based sessions lock the file in 
>> the filesystem until you're done with them, you can spend some time there 
>> if you do a lot of parallel ajax requests.  
>>   
>> The first step is to call session.forget(response) as soon as you can in 
>> controllers that do not write to the session.
>>
>> If that doesn't solve your slowness problem it's time to look into using 
>> redis to store sessions.
>>
>>
>>

-- 
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: Can't log into the application if using redis for sessions

2017-07-19 Thread Bernardo Leon
Thank you so much! I've been as dumb as fry ;) Now I can log in without 
issues.

El miércoles, 19 de julio de 2017, 9:41:03 (UTC-5), Leonel Câmara escribió:
>
> Nevermind I found your problem. You are connecting the Session after 
> instantiating Auth. You need to do it before as Auth checks stuff in the 
> session on __init__
>

-- 
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: Can't log into the application if using redis for sessions

2017-07-19 Thread Bernardo Leon
Thank you for your answer, I installed redis as localhost and changed that 
line to use RConn() without parameters unfortunately I am still getting the 
same problem.
If I run: 
redis-cli KEYS "*"

I get  3 keys created 
1) "w2p:sess:app:serial"
2) "w2p:sess:app:1"
3) "w2p:sess:app:id_idx"

So I can see that web2py is accessing redis but for some reason the app is 
not loggin in

El miércoles, 19 de julio de 2017, 2:05:53 (UTC-5), Leonel Câmara escribió:
>
> Probably something wrong here:
> rconn = RConn('[ip]', 6379
>
> try without parameters:
> rconn = RConn()
>
> If this doesn't work you need to check which IP and port redis is actually 
> listening on.
>

-- 
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: app slow on pythonanywhere

2017-07-18 Thread Bernardo Leon
Thank you for your answer, Indeed I am using several ajax requests and I am 
not able to use session.forget(response) on my components since I need the 
session information. I have installed redis to test but now I am facing 
another problem that I have detailed here: 
https://groups.google.com/forum/#!topic/web2py/fFdQES5Z6oM It seems that 
now I am not able to log into the application if I try to store sessions on 
redis, I am sorry to bother and thank you again!

El lunes, 17 de julio de 2017, 19:23:55 (UTC-5), Leonel Câmara escribió:
>
> That's probably caused by sessions, file based sessions lock the file in 
> the filesystem until you're done with them, you can spend some time there 
> if you do a lot of parallel ajax requests.  
>   
> The first step is to call session.forget(response) as soon as you can in 
> controllers that do not write to the session.
>
> If that doesn't solve your slowness problem it's time to look into using 
> redis to store sessions.
>
>
>

-- 
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] Can't log into the application if using redis for sessions

2017-07-18 Thread Bernardo Leon
Hi, I want to use redis to handle my app sessions. I am using the next code 
in my model:

from gluon.tools import Auth
from gluon.contrib.redis_utils import RConn
from gluon.contrib.redis_session import RedisSession

gth_dev_db_connection_string = 'postgres://dev_db:dev_db@[ip]/dev_db'
db = DAL(gth_dev_db_connection_string,
 lazy_tables=True)

auth = Auth(db)
auth.define_tables(username=False, signature=True)

db._common_fields.append(auth.signature)

# Redis session
rconn = RConn('[ip]', 6379)
sessiondb = RedisSession(redis_conn=rconn, session_expiry=False)
session.connect(request, response, db=sessiondb)

If I comment the last line I am able to login to the application but if I 
try to use redis to handle my sessions the application tells me that I am 
logged in but the page is stuck in the Log In form. Is this a bug or am I 
doing something wrong? Thank you!

-- 
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: app slow on pythonanywhere

2017-07-17 Thread Bernardo Leon
I am sorry for resurrecting this post but I am facing the same problem. 
Using the web2py -F profile option and then reading that dump with 
runsnakerun I see that fcntl.flock is where more time is spent. I have 
disabled migrations in the appconfig.ini and in the DAL constructor but I 
am still having fcntl.flock slowing my requests.

What fcntl.flock does? Is it directly related to migrations? If so how can 
I definitely get rid of this bootleneck?

Thank you.



El lunes, 5 de septiembre de 2016, 10:25:12 (UTC-5), Scott Hunter escribió:
>
> I found the problem; migrations weren't being disabled because, while I 
> had the correct settings in appconfig.ini, they were not being used 
> properly in creating the db object.
>
> - Scott
>
> On Saturday, September 3, 2016 at 1:01:39 PM UTC-4, Scott Hunter wrote:
>>
>> I have an app which runs *much* slower than expected on pythonanywhere.
>>
>> I enabled the profiler, and one thing stood out: on pythonanywhere, the 
>> function the most time was spent in, by far, is fcntl.flock from inside 
>> portalocker while loading the models.  In fact, when run locally, 
>> portalocker isn't even being called: it goes straight from save_dbt to 
>> cPickle.dump.
>>
>> Is there some configuration specific to web2py that might address this, 
>> or is it something I should take up w/ the people at PA?
>>
>> - Scott
>>
>

-- 
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: best way to put together components that interact between them

2017-02-28 Thread Bernardo Leon
Thank you, I don't have a blog or similar so I wouldn't know where to post 
this hehe I have seen web2py slices but I think it is abandoned now

El lunes, 27 de febrero de 2017, 22:03:02 (UTC-5), Marlysson Silva escribió:
>
> Awesome , You could to write a post explain this :D .
>
> Em sexta-feira, 24 de fevereiro de 2017 18:25:42 UTC-3, Bernardo Leon 
> escreveu:
>>
>> Hi, I am trying to create a page that uses 3 components. I want each 
>> component to be reusable.
>>
>> The first component is a search box, based on the search box result I 
>> want to load the second component (a grid) with the first result as a 
>> parameter. When I click on a link in the second component grid I want to 
>> load a third component based on wich link I pressed in the second component.
>>
>> What would be the best way to accomplish this? Making this 3 components 
>> interact while maintaining an elegant code and reusability of the 
>> components?
>>
>> Thank you!
>>
>

-- 
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: best way to put together components that interact between them

2017-02-26 Thread Bernardo Leon
Hi! Thank you for your time. I am satisfied with the results, I didn't knew 
that response.js or _onclick for instance can execute code in the parent 
component, that way I could solve this problem.

When I write OOP I create classes which do only one thing and in the end I 
have a client class/script/whatever where I use this classes objects to 
solve the problem at hand. I wanted to replicate this way of development on 
web2py and was able to do it.

In my case I wanted to compose a page with a search employee component, a 
contracts of the employee component and finally a absentism of the employee 
on that specific contract. As you may see it is a cascading master -> 
detail -> detail database schema.

my search component is this:

# -*- coding: utf-8 -*-


def index():
form_busqueda = SQLFORM.factory(Field('apellidos_nombres', 'string'),
Field('cedula', 'string', 
requires=IS_NOT_EMPTY()),
submit_button='Buscar')

form_busqueda.element(_name='apellidos_nombres')['_readonly'] = True

if form_busqueda.process(keepvalues=True).accepted:
empleado = db(db.empleado.cedula == 
form_busqueda.vars.cedula).select(db.empleado.id,

  db.empleado.apellidos,

  db.empleado.nombres).first()

apellidos_nombres = '%s %s' % (empleado.apellidos, empleado.nombres)

form_busqueda.element(_name='apellidos_nombres').update(_value=apellidos_nombres.upper())

response.flash = None
response.js = 'response_busqueda_empleado(%i);' % empleado.id

return dict(form_busqueda=form_busqueda)


As you may see I use response.js to call a javascript function. I see this 
function like an OOP interface therefore my client page will have to 
implement this function.

This is my client view:

{{extend 'layout.html'}}


Ausentismos




{{=LOAD('busqueda_empleado', 'index.load', ajax=True, 
target='div_busqueda_empleado')}}




{{=LOAD('contratos_empleado', 'index.load', ajax=True, 
target='div_contratos_empleado')}}




{{=LOAD('ausentismos_contrato', 'index.load', ajax=True, 
target='div_ausentismos_contrato')}}



function response_busqueda_empleado(id_empleado) {
web2py_component("{{=URL('contratos_empleado', 'index.load')}}"
.concat('?id_empleado=').concat(id_empleado), 
"div_contratos_empleado");
}
function response_contratos_empleado(id_contrato) {
web2py_component("{{=URL('ausentismos_contrato', 'index.load')}}"
.concat('?id_contrato=').concat(id_contrato), 
"div_ausentismos_contrato");
}


Here, where I LOAD my component I implement as well the 
response_busqueda_empleado function. For another component I have used 
_onclick inside an A helper to achieve exactly the same as response.js.

So this is the principle I could reproduce. There is a client (this view) 
who uses a component and implements some sort of callback for this 
component, in this callback I load the cascading components. Now I have 
components that do only one thing and can be reused on another pages, this 
is really awesome!

The last bit missing is that I had to write: 

{{=URL('ausentismos_contrato', 'index.load')}}"
.concat('?id_contrato=').concat(id_contrato)

because I was having problems with the vars parameter of URL. I know that 
this could have to do with id_contrato existing only in client side after 
the view rendered in the server but It would be great if someone could 
point me to an elegant solution for this part of creating a URL that passes 
vars arguments when the client side code executes.

Thank you and this is the way I did it and I think it is solving my problem 
and I hope it helps anyone looking for a solution like this!


El domingo, 26 de febrero de 2017, 14:54:33 (UTC-5), Marlysson Silva 
escribió:
>
> Try on action in a component ( click , submit , any event ) make this:
>
>
> http://web2py.com/books/default/chapter/29/12/components-and-plugins?search=load#Reload-another-component
>
> Reload other component .. but before of the reload the component , use the 
> javascript to show it and so perform the feature..
> I think
>
> The documentation too use the .reload method of jquery lib to reload the 
> div that contains the component ( Other approach )
>
> Em sexta-feira, 24 de fevereiro de 2017 18:25:42 UTC-3, Bernardo Leon 
> escreveu:
>>
&

[web2py] Re: best way to put together components that interact between them

2017-02-26 Thread Bernardo Leon
The second option. Many pages loaded by the load (or w2p_component) function

El sábado, 25 de febrero de 2017, 16:52:24 (UTC-5), Marlysson Silva 
escribió:
>
> Are you using the some frontend framework? As Vuejs , angular , react ..
>
> Or many pages html loaded by the *load *function ?
>
> Em sexta-feira, 24 de fevereiro de 2017 18:25:42 UTC-3, Bernardo Leon 
> escreveu:
>>
>> Hi, I am trying to create a page that uses 3 components. I want each 
>> component to be reusable.
>>
>> The first component is a search box, based on the search box result I 
>> want to load the second component (a grid) with the first result as a 
>> parameter. When I click on a link in the second component grid I want to 
>> load a third component based on wich link I pressed in the second component.
>>
>> What would be the best way to accomplish this? Making this 3 components 
>> interact while maintaining an elegant code and reusability of the 
>> components?
>>
>> Thank you!
>>
>

-- 
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] best way to put together components that interact between them

2017-02-24 Thread Bernardo Leon
Hi, I am trying to create a page that uses 3 components. I want each 
component to be reusable.

The first component is a search box, based on the search box result I want 
to load the second component (a grid) with the first result as a parameter. 
When I click on a link in the second component grid I want to load a third 
component based on wich link I pressed in the second component.

What would be the best way to accomplish this? Making this 3 components 
interact while maintaining an elegant code and reusability of the 
components?

Thank you!

-- 
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: Problem while integrating Sweet Alert with web2py in a component

2017-01-03 Thread Bernardo Leon
When using the component in isolation everything works fine (the parameters 
are passed fine) but I have this problem when running the parent page that 
LOADs several instances of this component. I have printed the values of 
vuelo.id and preorden_vuelo.pedido on my template and, while they are 
printed in the same order as the loaded components and print their 
respective values fine, I noted that doesn't matter in what component I 
execute the action it always pass the last printed parameters (even if the 
component loaded first).

In the parent page I am not able to see the entire code with the DOM 
inspector because in that page I have only a bunch of LOAD calls but not 
the code for each component, that is why I started to print vuelo.id and 
preorden_vuelo.pedido in the component template.

El martes, 3 de enero de 2017, 12:24:48 (UTC-5), Anthony escribió:
>
> Using the browser's DOM inspector, confirm that the URL in the following 
> code has the expected value of pid:
>
> ajax(' ':preorden_vuelo.pedido})?>', [], target=null
>
> If so, what happens when you click the action button? Does the browser 
> make an Ajax request to that exact URL, and does your pedir() function then 
> receive the proper value of pid?
>
> Anthony
>
> On Tuesday, January 3, 2017 at 11:06:33 AM UTC-5, Bernardo Leon wrote:
>>
>> Hi, I have a component which has a button that performs an action when 
>> clicked but I want the user accept some terms before executing that action.
>> I found Sweet Alert (http://t4t5.github.io/sweetalert/) so I am trying 
>> to use their confirm dialog between the click and the action. Since Sweet 
>> Alert is entirely javascript (and css) I am calling my action using the 
>> *ajax* method passing the parameters the controller gives to the view. 
>>
>> The problem I am facing is that the action receives wrong values in 
>> request.vars. Every time I click the action button I receive a different 
>> parameter. Why is that?
>>
>> This is my component controller:
>>
>> def vuelo_ofertante():
>> response.delimiters = ('')
>> vuelo_id = request.vars['vid']
>> pedido_id = request.vars['pid']
>> vuelo = db(db.viajes.id == vuelo_id).select(db.viajes.ALL).first()
>> lugar_vuelo = db(db.lugares.id == 
>> vuelo.lugar).select(db.lugares.nombre, db.lugares.lugar_padre).first()
>>
>> if lugar_vuelo is None:
>> texto_lugar = ''
>> else:
>> lugar_padre_vuelo = db(db.lugares.id == 
>> lugar_vuelo.lugar_padre).select(db.lugares.nombre).first()
>> if lugar_padre_vuelo is not None:
>> texto_lugar = lugar_vuelo.nombre + ' (' + 
>> lugar_padre_vuelo.nombre + ')'
>> else:
>> texto_lugar = lugar_vuelo.nombre
>>
>> preorden_vuelo = db((db.preordenes.viaje == vuelo.id) & 
>> (db.preordenes.pedido == pedido_id)).select(db.preordenes.ALL).first()
>>
>> return dict(vuelo=vuelo, lugar_vuelo=texto_lugar, 
>> *preorden_vuelo=preorden_vuelo*) (1)
>>
>> def pedir():
>> id_viaje = request.vars['vid']
>> *id_pedido = request.vars['pid'] #*I always get a random value here 
>> where I expect to get* the preorden_vuelo.pedido *(1) value that I am 
>> returning in the vuelo_ofertante method
>>
>> and this is my component's .load view:
>>
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> $
>> 
>> 
>> > onclick='confirmacion();'> 
>>  
>> 
>> 
>> function swal_aceptado(){
>> swal({
>> title: "<?=T('Muchas gracias!')?>",
>> text: "<h4><?=T('Nos comunicaremos con 
>> usted.')?></h4>",
>> html: true,
>> type: "success",
>> allowEscapeKey: false,
>> confirmButtonText: "<?=T('Entendido')?>"
>>  }, function(){
>> eval("ajax('<?=URL('confirmar_pedido', 
>> 'redireccionar')?>', [], target=null)");
>>  });
>> }
>>
>> function confirmacion(){
>> swal({
&g

[web2py] Problem while integrating Sweet Alert with web2py in a component

2017-01-03 Thread Bernardo Leon
Hi, I have a component which has a button that performs an action when 
clicked but I want the user accept some terms before executing that action.
I found Sweet Alert (http://t4t5.github.io/sweetalert/) so I am trying to 
use their confirm dialog between the click and the action. Since Sweet 
Alert is entirely javascript (and css) I am calling my action using the 
*ajax* method passing the parameters the controller gives to the view. 

The problem I am facing is that the action receives wrong values in 
request.vars. Every time I click the action button I receive a different 
parameter. Why is that?

This is my component controller:

def vuelo_ofertante():
response.delimiters = ('')
vuelo_id = request.vars['vid']
pedido_id = request.vars['pid']
vuelo = db(db.viajes.id == vuelo_id).select(db.viajes.ALL).first()
lugar_vuelo = db(db.lugares.id == 
vuelo.lugar).select(db.lugares.nombre, db.lugares.lugar_padre).first()

if lugar_vuelo is None:
texto_lugar = ''
else:
lugar_padre_vuelo = db(db.lugares.id == 
lugar_vuelo.lugar_padre).select(db.lugares.nombre).first()
if lugar_padre_vuelo is not None:
texto_lugar = lugar_vuelo.nombre + ' (' + 
lugar_padre_vuelo.nombre + ')'
else:
texto_lugar = lugar_vuelo.nombre

preorden_vuelo = db((db.preordenes.viaje == vuelo.id) & 
(db.preordenes.pedido == pedido_id)).select(db.preordenes.ALL).first()

return dict(vuelo=vuelo, lugar_vuelo=texto_lugar, 
*preorden_vuelo=preorden_vuelo*) (1)

def pedir():
id_viaje = request.vars['vid']
*id_pedido = request.vars['pid'] #*I always get a random value here 
where I expect to get* the preorden_vuelo.pedido *(1) value that I am 
returning in the vuelo_ofertante method

and this is my component's .load view:

















$


 
 


function swal_aceptado(){
swal({
title: "",
text: "

", html: true, type: "success", allowEscapeKey: false, confirmButtonText: "" }, function(){ eval("ajax('', [], target=null)"); }); } function confirmacion(){ swal({ title: "", text: '

', html: true, type: "info", showCancelButton: true, allowOutsideClick: true, confirmButtonText: "", cancelButtonText: "", closeOnConfirm: false, showLoaderOnConfirm: true }, function() { setTimeout(function(){ ajax('', [], target=null); //eval("ajax('', [], target=null)"); swal_aceptado(); }, 500); }); } Any help will be greatly appreciated. Thank you guys! -- 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] Is it possible to run doctests for scheduler tasks?

2016-10-31 Thread Bernardo Leon
Hi, I have seen in the book that running web2py with the -T flag I can run 
doctests for my controllers but I want to run doctests for my scheduler 
tasks. Is it possible? How?

Thank you!

-- 
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: Why cant fetch rows using select when importing models using the -M option?

2016-10-04 Thread Bernardo Leon
Yeah, you nailed it, I didn't even knew that the ignore_common_filters 
parameter even existed (I guess I forgot about my common_filter in the 
logged_user field). Now my query is returning everything ok.

Thank you! and my table's name is not 'my_table' I only use those names to 
simplify my questions ;)

El martes, 4 de octubre de 2016, 11:19:50 (UTC-5), Anthony escribió:
>
> On Tuesday, October 4, 2016 at 10:36:57 AM UTC-4, Bernardo Leon wrote:
>>
>> Now if I only run
>>
>> db(db.my_table.logged_user == 1)._select()
>>
>> I get:
>>
>> 'SELECT  my_table.id, my_table.my_column, my_table.logged_user FROM 
>> my_table WHERE ((my_table.logged_user = 1) AND (my_table.logged_user IS 
>> NULL));'
>>
>> Why is the query is trying to validate that the logged_user is null? 
>> thanks!
>>
>
> Seems odd. Do you have a common filter defined somewhere? What do you get 
> with:
>
> db(db.my_table.logged_user == 1, ignore_common_filters=True)._select()
>
> What does the table definition look like? Is there some code you're not 
> showing (presumably the real table name is not "my_table")?
>
> You may need to attach an app that reproduces the problem.
>
> 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: Why cant fetch rows using select when importing models using the -M option?

2016-10-04 Thread Bernardo Leon
Now if I only run

db(db.my_table.logged_user == 1)._select()

I get:

'SELECT  my_table.id, my_table.my_column, my_table.logged_user FROM 
my_table WHERE ((my_table.logged_user = 1) AND (my_table.logged_user IS 
NULL));'

Why is the query is trying to validate that the logged_user is null? thanks!


El lunes, 3 de octubre de 2016, 12:20:21 (UTC-5), Bernardo Leon escribió:
>
> Thanks for noting it, now I am passing the user id as part of pvars of the 
> task but with not much progress, though
>
> If I run that query I get an empty list: []
>
> El lunes, 3 de octubre de 2016, 12:01:22 (UTC-5), Anthony escribió:
>>
>> Note, auth.user_id will be None in the shell.
>>
>> What happens if you do (note the ._select rather than .select):
>>
>> db.executesql(db(db.my_table.logged_user == 1)._select())
>>
>> Anthony
>>
>> On Monday, October 3, 2016 at 12:40:09 PM UTC-4, Bernardo Leon wrote:
>>>
>>> I load my application in this way:
>>> $ python web2py.py -M -S myexistingapp
>>>
>>>
>>> if I run:
>>>
>>> db(db.my_table.logged_user == auth.user_id).select()
>>>
>>> I get: 
>>>
>>> even if I run:
>>>
>>> db(db.my_table.logged_user == 1).select()
>>>
>>> or 
>>>
>>> db(db.my_table.logged_user == 1L).select()
>>>
>>> I get: 
>>>
>>> but if I run:
>>>
>>> db.executesql('select * from my_table where logged_user = 1;')
>>>
>>> I get my list of rows.
>>>
>>> Why is this happening? I found this issue because I was getting >> (0)> on my scheduler.py task.
>>>
>>> Thanks in advance for any help I get with this issue.
>>>
>>>

-- 
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: Why cant fetch rows using select when importing models using the -M option?

2016-10-03 Thread Bernardo Leon
Thanks for noting it, now I am passing the user id as part of pvars of the 
task but with not much progress, though

If I run that query I get an empty list: []

El lunes, 3 de octubre de 2016, 12:01:22 (UTC-5), Anthony escribió:
>
> Note, auth.user_id will be None in the shell.
>
> What happens if you do (note the ._select rather than .select):
>
> db.executesql(db(db.my_table.logged_user == 1)._select())
>
> Anthony
>
> On Monday, October 3, 2016 at 12:40:09 PM UTC-4, Bernardo Leon wrote:
>>
>> I load my application in this way:
>> $ python web2py.py -M -S myexistingapp
>>
>>
>> if I run:
>>
>> db(db.my_table.logged_user == auth.user_id).select()
>>
>> I get: 
>>
>> even if I run:
>>
>> db(db.my_table.logged_user == 1).select()
>>
>> or 
>>
>> db(db.my_table.logged_user == 1L).select()
>>
>> I get: 
>>
>> but if I run:
>>
>> db.executesql('select * from my_table where logged_user = 1;')
>>
>> I get my list of rows.
>>
>> Why is this happening? I found this issue because I was getting > (0)> on my scheduler.py task.
>>
>> Thanks in advance for any help I get with this issue.
>>
>>

-- 
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] Why cant fetch rows using select when importing models using the -M option?

2016-10-03 Thread Bernardo Leon
I load my application in this way:
$ python web2py.py -M -S myexistingapp


if I run:

db(db.my_table.logged_user == auth.user_id).select()

I get: 

even if I run:

db(db.my_table.logged_user == 1).select()

or 

db(db.my_table.logged_user == 1L).select()

I get: 

but if I run:

db.executesql('select * from my_table where logged_user = 1;')

I get my list of rows.

Why is this happening? I found this issue because I was getting  
on my scheduler.py task.

Thanks in advance for any help I get with this issue.

-- 
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: Scheduler task runs before it is supposed to run

2016-09-21 Thread Bernardo Leon
Niphlod I will use postgresql in production and your solution as well. 
Thank you for helping me! ;)

El miércoles, 21 de septiembre de 2016, 2:33:30 (UTC-5), Niphlod escribió:
>
> that error is due - mostly - when the backend is too much pressured (i.e. 
> you're using sqlite, or too many workers, or a too low heatbeat)
>
> this is the fix  https://github.com/web2py/web2py/pull/1453 . you can 
> subscribe to it to know when it'll be merged.
>
> On Tuesday, September 20, 2016 at 5:38:08 PM UTC+2, Bernardo Leon wrote:
>>
>> Thank you for your reply. Can you reply this thread when the fix is 
>> published?
>>
>> I don't know if this is related to the same bug but in my worker process 
>> terminal I have this message:
>>
>> ERROR:web2py.scheduler.cedia-Satellite-L55-C#18606:error popping tasks
>>
>> why do I have this error? Thanks.
>>
>> El lunes, 19 de septiembre de 2016, 13:37:05 (UTC-5), Niphlod escribió:
>>>
>>> sorry, a bug slipped in. In the wait for the fix, please use 
>>> next_run_time in addition to start_time.
>>>
>>> On Monday, September 19, 2016 at 6:27:28 PM UTC+2, Bernardo Leon wrote:
>>>>
>>>> Hi, I am trying to run tasks in the future based on a time the user 
>>>> specifies but as soon as the task is queued it is executed, what am I 
>>>> doing 
>>>> wrong?
>>>>
>>>> I am using web2py Version 2.14.6-stable+timestamp.2016.05.10.00.21.47
>>>>
>>>> This is my model.db (part of it)
>>>>
>>>> db = DAL('sqlite://recomendadorexpertos.db')
>>>>
>>>> db.define_table('topicos',
>>>>Field('curso', 'reference cursos'),
>>>>Field('nombre', 'string', required=True, length=512),
>>>>Field('palabras_clave', 'text', readable=False, 
>>>> required=True, length=2048),
>>>>Field('fecha_inicio_identificacion', 'date', 
>>>> required=True, comment=T('Indica la fecha desde la cual se empezará a 
>>>> buscar expertos.')),
>>>>Field('fecha_fin_identificacion', 'date', required=True, 
>>>> comment=T('Indica la fehca en la cual se publicarán las recomendaciónes de 
>>>> expertos.')),
>>>>Field('fecha_fin_publicacion', 'date', comment=T('Indica 
>>>> la fecha hasta cuando se publicaran las recomendaciones de expertos 
>>>> (opcional)')),
>>>>Field('timestamp_get_tweets_etiquetado', 'datetime', 
>>>> readable=False, writable=False), #Para mostrar al usuario desde cuando se 
>>>> estan descargando tweets para etiquetado.
>>>>Field('link_descarga_tweets_etiquetado', 'string', 
>>>> readable=False, writable=False, length=2048),
>>>>Field('upload_archivo_etiquetado', 'upload', 
>>>> length=524288, 
>>>> uploadfolder='/var/www/web2py/applications/RecomendadorExpertos/archivos_etiquetados/',
>>>>  
>>>> autodelete=True, comment=T('Primero inicie el proceso de descarga de 
>>>> tweets 
>>>> para este topico, descargue el archivo para etiquetado, etiquetelo y 
>>>> subalo 
>>>> aqui.'), label=T('Subir archivo etiquetado'), readable=False), #Cambiar el 
>>>> nombre del archivo que suba a [nombre_topico].csv
>>>>Field('path_modelo', 'string', readable=False, 
>>>> writable=False, length=2048), #Ruta del modelo entrenado
>>>>Field('topico_configurado_completamente', 'integer', 
>>>> readable=True, writable=False, default=1, 
>>>> represent=representTopicoConfigurado), #Sirve para mostrar un check alado 
>>>> del archivo subido una vez terminado de generarse el modelo, para que el 
>>>> profesor sepa que ya esta todo bien.
>>>>Field('id_scheduler_task_descarga_tweets', 'integer', 
>>>> readable=False, writable=False),
>>>>Field('id_scheduler_task_identificacion_expertos', 
>>>> 'integer', readable=False, writable=False),
>>>>Field('id_scheduler_task_publicacion_expertos',

[web2py] Re: Scheduler task runs before it is supposed to run

2016-09-20 Thread Bernardo Leon
Thank you for your reply. Can you reply this thread when the fix is 
published?

I don't know if this is related to the same bug but in my worker process 
terminal I have this message:

ERROR:web2py.scheduler.cedia-Satellite-L55-C#18606:error popping tasks

why do I have this error? Thanks.

El lunes, 19 de septiembre de 2016, 13:37:05 (UTC-5), Niphlod escribió:
>
> sorry, a bug slipped in. In the wait for the fix, please use next_run_time 
> in addition to start_time.
>
> On Monday, September 19, 2016 at 6:27:28 PM UTC+2, Bernardo Leon wrote:
>>
>> Hi, I am trying to run tasks in the future based on a time the user 
>> specifies but as soon as the task is queued it is executed, what am I doing 
>> wrong?
>>
>> I am using web2py Version 2.14.6-stable+timestamp.2016.05.10.00.21.47
>>
>> This is my model.db (part of it)
>>
>> db = DAL('sqlite://recomendadorexpertos.db')
>>
>> db.define_table('topicos',
>>Field('curso', 'reference cursos'),
>>Field('nombre', 'string', required=True, length=512),
>>Field('palabras_clave', 'text', readable=False, 
>> required=True, length=2048),
>>Field('fecha_inicio_identificacion', 'date', 
>> required=True, comment=T('Indica la fecha desde la cual se empezará a 
>> buscar expertos.')),
>>Field('fecha_fin_identificacion', 'date', required=True, 
>> comment=T('Indica la fehca en la cual se publicarán las recomendaciónes de 
>> expertos.')),
>>Field('fecha_fin_publicacion', 'date', comment=T('Indica 
>> la fecha hasta cuando se publicaran las recomendaciones de expertos 
>> (opcional)')),
>>Field('timestamp_get_tweets_etiquetado', 'datetime', 
>> readable=False, writable=False), #Para mostrar al usuario desde cuando se 
>> estan descargando tweets para etiquetado.
>>Field('link_descarga_tweets_etiquetado', 'string', 
>> readable=False, writable=False, length=2048),
>>Field('upload_archivo_etiquetado', 'upload', 
>> length=524288, 
>> uploadfolder='/var/www/web2py/applications/RecomendadorExpertos/archivos_etiquetados/',
>>  
>> autodelete=True, comment=T('Primero inicie el proceso de descarga de tweets 
>> para este topico, descargue el archivo para etiquetado, etiquetelo y subalo 
>> aqui.'), label=T('Subir archivo etiquetado'), readable=False), #Cambiar el 
>> nombre del archivo que suba a [nombre_topico].csv
>>Field('path_modelo', 'string', readable=False, 
>> writable=False, length=2048), #Ruta del modelo entrenado
>>Field('topico_configurado_completamente', 'integer', 
>> readable=True, writable=False, default=1, 
>> represent=representTopicoConfigurado), #Sirve para mostrar un check alado 
>> del archivo subido una vez terminado de generarse el modelo, para que el 
>> profesor sepa que ya esta todo bien.
>>Field('id_scheduler_task_descarga_tweets', 'integer', 
>> readable=False, writable=False),
>>Field('id_scheduler_task_identificacion_expertos', 
>> 'integer', readable=False, writable=False),
>>Field('id_scheduler_task_publicacion_expertos', 'integer', 
>> readable=False, writable=False))
>>
>>
>> This is my Scheduler.py
>>
>> def task_iniciar_descarga_tweets(row):
>> return 'descarga de tweets terminada'
>>
>> def task_iniciar_identificacion_expertos(nombre_topico):
>> return 'identificacion de expertos terminada'
>>
>> def task_publicar_expertos(nombre_topico):
>> return 'publicacion de expertos terminada'
>>
>> dbScheduler = DAL('sqlite://scheduler.db')
>> scheduler = Scheduler(dbScheduler, 
>> tasks={'task_iniciar_descarga_tweets':task_iniciar_descarga_tweets,
>>   
>> 'task_iniciar_identificacion_expertos':task_iniciar_identificacion_expertos,
>>   
>> 'task_publicar_expertos':task_publicar_expertos})
>>
>>
>> And this is my default.py controller (part of it)
>>
>> @auth.requires_login()
>> def onCreateTopico(form):
>> row_task_iniciar_identific

[web2py] Scheduler task runs before it is supposed to run

2016-09-19 Thread Bernardo Leon
Hi, I am trying to run tasks in the future based on a time the user 
specifies but as soon as the task is queued it is executed, what am I doing 
wrong?

I am using web2py Version 2.14.6-stable+timestamp.2016.05.10.00.21.47

This is my model.db (part of it)

db = DAL('sqlite://recomendadorexpertos.db')

db.define_table('topicos',
   Field('curso', 'reference cursos'),
   Field('nombre', 'string', required=True, length=512),
   Field('palabras_clave', 'text', readable=False, 
required=True, length=2048),
   Field('fecha_inicio_identificacion', 'date', required=True, 
comment=T('Indica la fecha desde la cual se empezará a buscar expertos.')),
   Field('fecha_fin_identificacion', 'date', required=True, 
comment=T('Indica la fehca en la cual se publicarán las recomendaciónes de 
expertos.')),
   Field('fecha_fin_publicacion', 'date', comment=T('Indica la 
fecha hasta cuando se publicaran las recomendaciones de expertos 
(opcional)')),
   Field('timestamp_get_tweets_etiquetado', 'datetime', 
readable=False, writable=False), #Para mostrar al usuario desde cuando se 
estan descargando tweets para etiquetado.
   Field('link_descarga_tweets_etiquetado', 'string', 
readable=False, writable=False, length=2048),
   Field('upload_archivo_etiquetado', 'upload', length=524288, 
uploadfolder='/var/www/web2py/applications/RecomendadorExpertos/archivos_etiquetados/',
 
autodelete=True, comment=T('Primero inicie el proceso de descarga de tweets 
para este topico, descargue el archivo para etiquetado, etiquetelo y subalo 
aqui.'), label=T('Subir archivo etiquetado'), readable=False), #Cambiar el 
nombre del archivo que suba a [nombre_topico].csv
   Field('path_modelo', 'string', readable=False, 
writable=False, length=2048), #Ruta del modelo entrenado
   Field('topico_configurado_completamente', 'integer', 
readable=True, writable=False, default=1, 
represent=representTopicoConfigurado), #Sirve para mostrar un check alado 
del archivo subido una vez terminado de generarse el modelo, para que el 
profesor sepa que ya esta todo bien.
   Field('id_scheduler_task_descarga_tweets', 'integer', 
readable=False, writable=False),
   Field('id_scheduler_task_identificacion_expertos', 
'integer', readable=False, writable=False),
   Field('id_scheduler_task_publicacion_expertos', 'integer', 
readable=False, writable=False))


This is my Scheduler.py

def task_iniciar_descarga_tweets(row):
return 'descarga de tweets terminada'

def task_iniciar_identificacion_expertos(nombre_topico):
return 'identificacion de expertos terminada'

def task_publicar_expertos(nombre_topico):
return 'publicacion de expertos terminada'

dbScheduler = DAL('sqlite://scheduler.db')
scheduler = Scheduler(dbScheduler, 
tasks={'task_iniciar_descarga_tweets':task_iniciar_descarga_tweets,
  
'task_iniciar_identificacion_expertos':task_iniciar_identificacion_expertos,
  
'task_publicar_expertos':task_publicar_expertos})


And this is my default.py controller (part of it)

@auth.requires_login()
def onCreateTopico(form):
row_task_iniciar_identificacion = 
scheduler.queue_task('task_iniciar_identificacion_expertos', 
pvars={'nombre_topico':form.vars.nombre}, 
start_time=datetime.datetime.combine(form.vars.fecha_inicio_identificacion, 
datetime.time.min), 
stop_time=datetime.datetime.combine(form.vars.fecha_fin_identificacion, 
datetime.time.min), retry_failed=3)

row_task_iniciar_publicacion = 
scheduler.queue_task('task_publicar_expertos', 
pvars={'nombre_topico':form.vars.nombre}, 
start_time=datetime.datetime.combine(form.vars.fecha_fin_identificacion, 
datetime.time.min), retry_failed=3)


db(db.topicos.id==form.vars.id).update(id_scheduler_task_identificacion_expertos=row_task_iniciar_identificacion.id,
 
id_scheduler_task_publicacion_expertos=row_task_iniciar_publicacion.id)
db.commit()

For instance, if I queue the task "task_iniciar_identificacion_expertos" 
with a future start_time the worker executes this task inmediately, how can 
I set the worker to execute this task in the future?

Thank you!

-- 
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: Is it possible reload my model.py from an ajax request?

2016-08-12 Thread Bernardo Leon
Yeah, you were right, now it works! :)

My final code is like this:

the model remains the same.

controller:

def redTrafico():
red_trafico = SQLFORM.grid(db.red_trafico)
return locals()

def canal():
canal = SQLFORM.grid(db.canal)
return locals()

def onChangeRedTrafico():
options = []
for opcion in db(db.canal.id_red_trafico == 
request.vars.red_trafico).select(db.canal.ALL):
options.append(OPTION(opcion.nombre, _value=opcion.id))

return SELECT(options)

@auth.requires_login()
def index():
formulario = SQLFORM.grid(db.formulario)
formulario_red_trafico = 
formulario.element('select[id=formulario_red_trafico]')
if formulario_red_trafico is not None:
formulario_red_trafico['_onchange'] = 'onChangeRedTrafico()'

return dict(formulario=formulario)

And finally my view:

{{left_sidebar_enabled,right_sidebar_enabled=False,('message' in 
globals())}}
{{extend 'layout.html'}}


console.log('seccion javascript ejecutada')
function onChangeRedTrafico(){
eval("ajax('{{=URL('default', 'onChangeRedTrafico')}}', 
['red_trafico'], 'formulario_canal')");
}


Red Trafico

Canal

{{=formulario}}

Thank you Anthony for your explanation! ("...if you need the HTML on the 
page to change as the result of an Ajax request, then the Ajax request must 
actually return the new HTML (or return the relevant data needed for the JS 
code to construct the HTML).")

El viernes, 5 de agosto de 2016, 16:18:04 (UTC-5), Anthony escribió:
>
> Yeah, that's not going to work. All your Ajax callback does is set the 
> validator for the field in question, but it doesn't do or return anything. 
> That change is only in effect for the duration of the Ajax request itself. 
> It will not change any HTML on the page (as you do not return an HTML), nor 
> will it affect any subsequent requests (e.g., the form submission).
>
> Note, your application code is executed on every request, so changing an 
> attribute in one request does not persist to subsequent requests. If you 
> need the validator to have a particular value upon form submission, you 
> will need to set that value within the same request as the submission 
> itself. Also, if you need the HTML on the page to change as the result of 
> an Ajax request, then the Ajax request must actually return the new HTML 
> (or return the relevant data needed for the JS code to construct the HTML).
>
> Anthony
>
> On Friday, August 5, 2016 at 4:19:22 PM UTC-4, Bernardo Leon wrote:
>>
>> The thing is I have already tried that but I got no luck, I know my 
>> controller method is executed but the child selector still uses the 
>> validator defined in the model file. If I don't declare the validator in 
>> the model file expecting that my controller code assign a new validator it 
>> also does nothing.
>>
>> This is my model file:
>>
>> # -*- coding: utf-8 -*-
>> from gluon.tools import Auth
>>
>> db = DAL('sqlite://modelo.db')
>> auth=Auth(db)
>> auth.define_tables(username=False, signature=True)
>>
>> db.define_table('red_trafico',
>>Field('nombre', 'string'))
>>
>> db.define_table('canal',
>>Field('id_red_trafico', 'reference red_trafico'),
>>Field('nombre', 'string'))
>>
>> db.define_table('formulario',
>>Field('red_trafico', 'reference red_trafico'),
>>Field('canal', 'reference canal'))
>>
>> db.canal.id_red_trafico.requires = IS_IN_DB(db, 'red_trafico.id', 
>> '%(nombre)s')
>> db.formulario.red_trafico.requires = IS_IN_DB(db, 'red_trafico.id', 
>> '%(nombre)s')
>> db.formulario.canal.requires = IS_IN_DB(db, 'canal.id', '%(nombre)s')
>>
>>
>>
>> this is my controller:
>>
>> formulario = SQLFORM.grid(db.formulario)
>>
>> def redTrafico():
>> red_trafico = SQLFORM.grid(db.red_trafico)
>> return locals()
>>
>> def canal():
>> canal = SQLFORM.grid(db.canal)
>> return locals()
>>
>> def onChangeRedTrafico():
>> db.formulario.canal.requires = IS_IN_DB(db(db.canal.id_red_trafico == 
>> request.vars.red_trafico), 'canal.id', '%(nombre)s')
>> print 'requires modificado'
>>
>> def index():
>> """
>> example action using the internationalization operator 

[web2py] Re: Is it possible reload my model.py from an ajax request?

2016-08-05 Thread Bernardo Leon
The thing is I have already tried that but I got no luck, I know my 
controller method is executed but the child selector still uses the 
validator defined in the model file. If I don't declare the validator in 
the model file expecting that my controller code assign a new validator it 
also does nothing.

This is my model file:

# -*- coding: utf-8 -*-
from gluon.tools import Auth

db = DAL('sqlite://modelo.db')
auth=Auth(db)
auth.define_tables(username=False, signature=True)

db.define_table('red_trafico',
   Field('nombre', 'string'))

db.define_table('canal',
   Field('id_red_trafico', 'reference red_trafico'),
   Field('nombre', 'string'))

db.define_table('formulario',
   Field('red_trafico', 'reference red_trafico'),
   Field('canal', 'reference canal'))

db.canal.id_red_trafico.requires = IS_IN_DB(db, 'red_trafico.id', 
'%(nombre)s')
db.formulario.red_trafico.requires = IS_IN_DB(db, 'red_trafico.id', 
'%(nombre)s')
db.formulario.canal.requires = IS_IN_DB(db, 'canal.id', '%(nombre)s')



this is my controller:

formulario = SQLFORM.grid(db.formulario)

def redTrafico():
red_trafico = SQLFORM.grid(db.red_trafico)
return locals()

def canal():
canal = SQLFORM.grid(db.canal)
return locals()

def onChangeRedTrafico():
db.formulario.canal.requires = IS_IN_DB(db(db.canal.id_red_trafico == 
request.vars.red_trafico), 'canal.id', '%(nombre)s')
print 'requires modificado'

def index():
"""
example action using the internationalization operator T and flash
rendered by views/default/index.html or views/generic.html

if you need a simple wiki simply replace the two lines below with:
return auth.wiki()
"""
formulario_red_trafico = 
formulario.element('select[id=formulario_red_trafico]')
formulario_red_trafico['_onchange'] = 'onChangeRedTrafico()'
return dict(formulario=formulario)


And this is my view:

{{left_sidebar_enabled,right_sidebar_enabled=False,('message' in 
globals())}}
{{extend 'layout.html'}}


console.log('seccion javascript ejecutada')
function onChangeRedTrafico(){
eval("ajax('{{=URL('default', 'onChangeRedTrafico')}}', 
['red_trafico'], '')");
}


Red Trafico

Canal

{{=formulario}}

I am using web2py version: Version 
2.14.6-stable+timestamp.2016.05.10.00.21.47

Is something wrong with my code? Because my onChangeRedTrafico() controller 
method (where I change the validator) gets called but nothing happens

Thanks


El viernes, 5 de agosto de 2016, 13:58:02 (UTC-5), Anthony escribió:
>
> On Friday, August 5, 2016 at 12:28:44 PM UTC-4, Bernardo Leon wrote:
>>
>> Hi, I have an SQLFORM.grid form and when I am inserting data I want to 
>> make the selectors work in cascade. I have seen some recipies where they 
>> create by hand the form using plain html and throw some jQuery in the 
>> middle but I dont like it, I like the cleaness of web2py so I am looking 
>> for a cleaner way to accomplish this.
>>
>> So far I am trying with ajax request and I have been able to call a 
>> function in my controller passing the id of the parent selector to finally 
>> change the child's selector IS_IN_DB validator. That was my idea, but it 
>> seems I cannot change the validator from de controller, only from the 
>> model; so is there a way to reload the model within an ajax request so I 
>> can change the behavior of my form at runtime? Is there a better/cleaner 
>> way to accomplish this?
>>
>
> First, note that the model file is re-executed on every request, so indeed 
> it does "reload" when you make an Ajax request. The problem is, your model 
> includes no logic to change the validator when the Ajax request is made. 
> You could add such logic, perhaps by sending some flag with the Ajax 
> request, or simply setting the alternative validator whenever request.ajax 
> == True.
>
> However, there is no need to make the change in the model file where the 
> table is initially defined, as you can change the validators for a given 
> field at any point in your code, such as in the controller. So, in the 
> controller that handles the Ajax request, you could do:
>
> db.mytable.myfield.requires = new_validator
>
> 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: Is it possible reload my model.py from an ajax request?

2016-08-05 Thread Bernardo Leon
It seems to be an interesting library but it is kind of expensive from what 
I see and I think it does not integrate with web2py, at least not with 
SQLFORM.crud. Thanks for the suggestion anyway!

El viernes, 5 de agosto de 2016, 12:57:40 (UTC-5), Ron Chatterjee escribió:
>
> http://demos.telerik.com/kendo-ui/dropdownlist/cascadingdropdownlist
>
> might help
>
> On Friday, August 5, 2016 at 1:28:01 PM UTC-4, Bernardo Leon wrote:
>>
>> No, I am trying to get the cascade dropdowns working.
>>
>> I want to make an AJAX call from the parent dropdown AND refresh the child
>>
>> El viernes, 5 de agosto de 2016, 12:23:04 (UTC-5), Antonio Salazar 
>> escribió:
>>>
>>> Are you saying you managed to cascade the dropdowns, or just make an 
>>> AJAX call from the parent dropdown without refreshing the child?
>>>
>>> On Friday, August 5, 2016 at 11:28:44 AM UTC-5, Bernardo Leon wrote:
>>>>
>>>> Hi, I have an SQLFORM.grid form and when I am inserting data I want to 
>>>> make the selectors work in cascade. I have seen some recipies where they 
>>>> create by hand the form using plain html and throw some jQuery in the 
>>>> middle but I dont like it, I like the cleaness of web2py so I am looking 
>>>> for a cleaner way to accomplish this.
>>>>
>>>> So far I am trying with ajax request and I have been able to call a 
>>>> function in my controller passing the id of the parent selector to finally 
>>>> change the child's selector IS_IN_DB validator. That was my idea, but it 
>>>> seems I cannot change the validator from de controller, only from the 
>>>> model; so is there a way to reload the model within an ajax request so I 
>>>> can change the behavior of my form at runtime? Is there a better/cleaner 
>>>> way to accomplish this?
>>>>
>>>> Thank you!
>>>>
>>>

-- 
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: Is it possible reload my model.py from an ajax request?

2016-08-05 Thread Bernardo Leon
No, I am trying to get the cascade dropdowns working.

I want to make an AJAX call from the parent dropdown AND refresh the child

El viernes, 5 de agosto de 2016, 12:23:04 (UTC-5), Antonio Salazar escribió:
>
> Are you saying you managed to cascade the dropdowns, or just make an AJAX 
> call from the parent dropdown without refreshing the child?
>
> On Friday, August 5, 2016 at 11:28:44 AM UTC-5, Bernardo Leon wrote:
>>
>> Hi, I have an SQLFORM.grid form and when I am inserting data I want to 
>> make the selectors work in cascade. I have seen some recipies where they 
>> create by hand the form using plain html and throw some jQuery in the 
>> middle but I dont like it, I like the cleaness of web2py so I am looking 
>> for a cleaner way to accomplish this.
>>
>> So far I am trying with ajax request and I have been able to call a 
>> function in my controller passing the id of the parent selector to finally 
>> change the child's selector IS_IN_DB validator. That was my idea, but it 
>> seems I cannot change the validator from de controller, only from the 
>> model; so is there a way to reload the model within an ajax request so I 
>> can change the behavior of my form at runtime? Is there a better/cleaner 
>> way to accomplish this?
>>
>> Thank you!
>>
>

-- 
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] Is it possible reload my model.py from an ajax request?

2016-08-05 Thread Bernardo Leon
Hi, I have an SQLFORM.grid form and when I am inserting data I want to make 
the selectors work in cascade. I have seen some recipies where they create 
by hand the form using plain html and throw some jQuery in the middle but I 
dont like it, I like the cleaness of web2py so I am looking for a cleaner 
way to accomplish this.

So far I am trying with ajax request and I have been able to call a 
function in my controller passing the id of the parent selector to finally 
change the child's selector IS_IN_DB validator. That was my idea, but it 
seems I cannot change the validator from de controller, only from the 
model; so is there a way to reload the model within an ajax request so I 
can change the behavior of my form at runtime? Is there a better/cleaner 
way to accomplish this?

Thank you!

-- 
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: auth.settings.auth_two_factor_enabled = True gives me setting key 'auth_two_factor_enabled' does not

2016-07-18 Thread Bernardo Leon
Thanks for your reply, I was making a mistake.

I have been calling
auth.define_tables(...)
before
auth.settings.extra_fields['auth_user'] = [Field()]

I have switched between them and now I have my field in the database so 
thank you :)

Now I have Google authentication working, thank you guys for your help!

This is my working code:

db = DAL('sqlite://amanda2.db')
auth = Auth(db)
auth.settings.auth_two_factor_enabled = True
auth.settings.extra_fields['auth_user'] = [Field('motp_secret', 'password', 
length=512, default='', label='MOTP Secret')]
auth.define_tables(username=True, signature=True)

def _set_two_factor(user, auth_two_factor):
return None

def verificar_otp(user, otp):
import pyotp
totp = pyotp.TOTP(user.motp_secret)
if totp.verify(otp):
return otp

auth.settings.two_factor_methods = [_set_two_factor]
auth.settings.two_factor_onvalidation = [verificar_otp]




El domingo, 17 de julio de 2016, 16:57:16 (UTC-5), 黄祥 escribió:
>
> pls try :
> *models/db.py*
> from gluon.tools import Auth, Service, PluginManager
>
> auth = Auth(db, host_names=myconf.get('host.names'))
> service = Service()
> plugins = PluginManager()
>
> auth.settings.extra_fields['auth_user'] = [Field('motp_secret', 
> 'password', length=512, default='', label='MOTP Secret')]
>
> auth.define_tables(username=False, signature=False)
>
> *ref:*
>
> http://web2py.com/books/default/chapter/29/09/access-control#Customizing-Auth
>
> best regards,
> stifan
>

-- 
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: auth.settings.auth_two_factor_enabled = True gives me setting key 'auth_two_factor_enabled' does not

2016-07-17 Thread Bernardo Leon
Thanks, with the last version 2.14.6-stable+timestamp.2016.05.10.00.21.47 I 
don't have any errors but I have noticed that my extra_field is not being 
created in my database even if I leave my DAL like this:

db = DAL('sqlite://database.db')

so I can not set the value of my extra_field

Another thing that I notice is that despite my app is asking me for my 
authentication code I am not able to go back to the log in screen. What if 
I have two accounts in the app and I want to login in another account? It 
seems that it is not possible.

Is this behaviour expected?

Can you help me with the extra_field issue? What am I doing wrong?
And thank you for your help ;)

El domingo, 17 de julio de 2016, 12:22:21 (UTC-5), Anthony escribió:
>
> On Sunday, July 17, 2016 at 12:53:40 PM UTC-4, Bernardo Leon wrote:
>>
>> Thank you for your reply
>>
>> my web2py version is: Version 2.12.3-stable+timestamp.2015.08.19.00.18.03
>>
>
> The settings and functionality you are attempting to use were not released 
> until version 2.13.1 (there was prior support for two-factor 
> authentication, but it was more basic and did not include the settings in 
> question).
>  
>
>> And finally thanks for your observation about lambdas, If I understand 
>> you I should leave it like this?:
>>
>> auth.settings.two_factor_methods = [_set_two_factor(user, auth_two_factor
>> )]
>> auth.settings.two_factor_onvalidation = [verify_otp(user, otp)]
>>
>
> No, you just need to specify the functions:
>
> auth.settings.two_factor_methods = [_set_two_factor]
> auth.settings.two_factor_onvalidation = [verify_otp]
>
> Note, that lambda x: func(x) is simply equivalent to func. The reason you 
> often see a lambda function is because the function you ultimately want to 
> call does not have the proper signature, so you use the lambda to generate 
> a new function with the required signature, and then let the lambda call 
> the ultimate function with the proper arguments. However, if the ultimate 
> function already has the proper signature, there is no reason to wrap it in 
> a lambda with the exact same signature. Ultimately, the callback just needs 
> to be any callable object (whether a normal function, a lambda function, a 
> static method of a class, or an instance of a callable class) with the 
> proper signature (i.e., that accepts the arguments that the caller will 
> pass to it).
>
> 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: auth.settings.auth_two_factor_enabled = True gives me setting key 'auth_two_factor_enabled' does not

2016-07-17 Thread Bernardo Leon
Thank you for yor reply

my web2py version is: Version 2.12.3-stable+timestamp.2015.08.19.00.18.03

I am defining one extra field

auth.settings.extra_fields['auth_user'] = [Field('motp_secret', 'password', 
length=512, default='', label='MOTP Secret')]

What I am trying to do is implementing google authenticator which as I 
understand only needs a secret key (and not a secret pin like in the book 
example), that is why I am adding only one extra field

And finally thanks for your observation about lambdas, If I understand you 
I should leave it like this?:

auth.settings.two_factor_methods = [_set_two_factor(user, auth_two_factor)]
auth.settings.two_factor_onvalidation = [verify_otp(user, otp)]

Regards

El viernes, 15 de julio de 2016, 21:46:31 (UTC-5), Anthony escribió:
>
> Which version of web2py?
>
> Also, note that you must define extra fields before calling 
> auth.define_tables.
>
> And there is no reason to wrap your two callback functions in lamdas - 
> they already have the proper signature as is.
>
> 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: dumbest question ever: how do you jump to line in the w2p ide

2016-07-15 Thread Bernardo Leon


El viernes, 3 de junio de 2016, 16:51:01 (UTC-5), Mark Billion escribió:
>
> I cant find this anywhere, but Ive seen it somewhere.  Say Im editing in 
> the admin application and want to jump to line 1000.  Whats the key binding 
> for it?
>
> Feel free to heckle as long as you also provide the answer ;)
>

-- 
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: dumbest question ever: how do you jump to line in the w2p ide

2016-07-15 Thread Bernardo Leon
Mmm I have no idea but can I suggest you to use pycharm? After all it 
integrates with web2py and being a full teatured IDE you can jump to lines, 
set breakpoints, code completion and more, check 
this: https://www.jetbrains.com/help/pycharm/2016.1/web2py.html

El viernes, 3 de junio de 2016, 16:51:01 (UTC-5), Mark Billion escribió:
>
> I cant find this anywhere, but Ive seen it somewhere.  Say Im editing in 
> the admin application and want to jump to line 1000.  Whats the key binding 
> for it?
>
> Feel free to heckle as long as you also provide the answer ;)
>

-- 
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] auth.settings.auth_two_factor_enabled = True gives me setting key 'auth_two_factor_enabled' does not

2016-07-15 Thread Bernardo Leon
Hello, I am trying to use two factor authentication for my entire app so I 
have my model like this:

db = DAL('sqlite://database.db', migrate_enabled=False, lazy_tables=True)
auth = Auth(db)
auth.define_tables(username=True, signature=True)
auth.settings.actions_disabled.append('register')
auth.settings.auth_two_factor_enabled = True
auth.settings.extra_fields['auth_user'] = [Field('motp_secret', 'password', 
length=512, default='', label='MOTP Secret')]

def _set_two_factor(user, auth_two_factor):
return None

def verify_otp(user, otp):
import pyotp
totp = pyotp.TOTP(user.motp_secret)
return totp.verify(int(otp))

auth.settings.two_factor_methods = [lambda user, auth_two_factor: 
_set_two_factor(user, auth_two_factor)]
auth.settings.two_factor_onvalidation = [lambda user, otp: verify_otp(user, 
otp)]


Buy when I try to load my site it gives a ticket which says: setting key 
'auth_two_factor_enabled' does not exist

What am I doing wrong?
Can anyone help me?

Thank you in advance.

-- 
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: 'Query' object has no attribute 'tablename' when using show_if

2016-06-21 Thread Bernardo Leon
Thank you anthony, it worked!

El lunes, 20 de junio de 2016, 18:25:13 (UTC-5), Anthony escribió:
>
> This is not the intended purpose of show_if. It is only used to 
> dynamically hide or show fields in the form, based on the values of other 
> fields in the form (so, the query must refer to other fields in the same 
> table). Ultimately, the query does not hit the database but is simply 
> converted to Javascript for use in the browser.
>
> In this case, it looks like you simply what to control whether a given 
> field appears in the form based on the user's Auth role, so you probably 
> want something like:
>
> db.table.field.readable = db.table.field.writable = auth.has_membership(2) 
>
> Anthony
>
> On Monday, June 20, 2016 at 5:53:27 PM UTC-4, Bernardo Leon wrote:
>>
>> Hi, a am using show_if to show a field only if the user is a member of a 
>> certain group, I am using this query:
>>
>> *db.table.field.show_if = **(db.auth_membership.user_id == auth.user_id) 
>> & (db.auth_membership.group_id == 2)*
>>
>> but it gives me this error: 'Query' object has no attribute 'tablename'
>>
>> What is the problem?
>>
>> Thanks in advance!
>>
>

-- 
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] 'Query' object has no attribute 'tablename' when using show_if

2016-06-20 Thread Bernardo Leon
Hi, a am using show_if to show a field only if the user is a member of a 
certain group, I am using this query:

*db.table.field.show_if = **(db.auth_membership.user_id == auth.user_id) & 
(db.auth_membership.group_id == 2)*

but it gives me this error: 'Query' object has no attribute 'tablename'

What is the problem?

Thanks in advance!

-- 
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: default_application does not work on 2.14.6 version

2016-05-16 Thread Bernardo Leon
This is the workaround I have found so far:

Since the name of the application is obtained in layout.html and 
layout.html uses response.title (or request.application but I am sticking 
to response.title) to change the app name (even if the app folder is called 
init) we just need to add this line in the model file:

response.title = 'yourappname'

And that's it, I hope it could help to someone else.

El domingo, 15 de mayo de 2016, 10:48:35 (UTC-5), Bernardo Leon escribió:
>
> Good morning, I just clone the github repository and then create a 
> routes.py file in the web2py folder. This file only have one line:
>
> default_application = 'myapplication'
>
> but it does not, when I try to load my site it defaults to the welcome 
> application, the only way it works is changing its name to 'init' but in 
> the browser I dont want my tab called 'init' but 'myapplication'
>
> Can you help me with this?
>
> I am behind a nginx server if it helps.
>
> Thank you for any answer!
>

-- 
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] default_application does not work on 2.14.6 version

2016-05-15 Thread Bernardo Leon
Good morning, I just clone the github repository and then create a 
routes.py file in the web2py folder. This file only have one line:

default_application = 'myapplication'

but it does not, when I try to load my site it defaults to the welcome 
application, the only way it works is changing its name to 'init' but in 
the browser I dont want my tab called 'init' but 'myapplication'

Can you help me with this?

I am behind a nginx server if it helps.

Thank you for any answer!

-- 
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] How can I set the column width of a SQLFORM.grid table?

2016-05-02 Thread Bernardo Leon
Hello, I have this table in my model:

db.define_table('data', 
  Field('description', 'string'), 
  Field('value', 'integer'))

this controller in default.py:

def index():
 tableN = SQLFORM.grid(db.data, maxtextlengths={'data.description':500})
 return locals()

and this view:


{{=tableN}}


Thanks to maxtextlengths I can show all the description texts but since 
they are large I can't see their respective value in the table that 
SQLFORM.grid generates unless i use the horizontal scroll. Is there a way I 
can still show all the description data but in a column with a small width? 
It doesn't matter if the height of the cell grows but I dont want to use 
the scroll because the table is big and I dont want to scroll all the time 
I want to compare a description with their value. How can I achieve this? 
Thank you!

-- 
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.