[web2py] Re: Dealing with db objects on duplicated app

2018-04-16 Thread Sergio Romero
I used the starter app example of mjbeller

I have the same app code on each app to instantiate the DAL but with 
different appconfig.ini

appconfig.ini of app1

uri= sqlite://storage.sqlite
migrate= true
pool_size  = 10 ; ignored for sqlite


appconfig.ini of app2

uri= sqlite://storage2.sqlite
migrate= false
pool_size  = 10 ; ignored for sqlite


I used the same code to instantiate the DAL object on each app

## app configuration made easy. Look inside private/appconfig.ini
from gluon.contrib.appconfig import AppConfig
## once in production, remove reload=True to gain full speed
myconf = AppConfig(reload=True)
myconf_env = myconf.get('environment.type')

if not request.env.web2py_runtime_gae:
## if NOT running on Google App Engine use SQLite or other DB
db = DAL(myconf.get(myconf_env + 'db.uri'),
 pool_size = myconf.get(myconf_env + 'db.pool_size'),
 migrate_enabled = myconf.get(myconf_env + 'db.migrate'),
 check_reserved = ['mysql', 'postgres'])  # ['all'])
else:
## connect to Google BigTable (optional 'google:datastore://namespace')
db = DAL('google:datastore+ndb')
## store sessions and tickets there
session.connect(request, response, db=db)


Thanks

El martes, 17 de abril de 2018, 2:03:20 (UTC+2), Anthony escribió:
>
> They are not sharing the same db object just by virtue of it having the 
> same name in the code. The code of each app is executed independently 
> within requests for each app. Please show the code you are using to 
> instantiate the DAL object in each app.
>
> Anthony
>
> On Monday, April 16, 2018 at 7:58:03 PM UTC-4, Sergio Romero wrote:
>>
>> Hi there. 
>>
>> I have to deal with a duplicate example app on the same rocket server 
>> instance. I have modified the sqlite file with each application interact 
>> but both of the applicattions has the same db dal object name. 
>>
>> When I start the server each applications shares the users and have some 
>> problems with the foreign keys when I try to insert a row on a table of 
>> app1 if the same table exists on app2 
>>
>> How can I deal with this situation without refactor the db object name of 
>> one of the application to isolate both applications and don't share the 
>> instantiate db object between them. 
>>
>> Thanks
>
>

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


Re: [web2py] Re: I cant access db data

2018-04-16 Thread Maurice Waka
Sorry, am still experiencing the same issue.
This module is one of the many that I import to the controller .
i.e.

controller:
from gluon import current
db = current.db
from ..path/to/module import my_module
some code..
def access_this():
class Filters(object):
@staticmethod
def Filter_read():
for item in strings.split():
for c in abnvalinterpret: here i access the data: strings,
lists etc. The data is then accessed by the function below
return my_module()


On Tue, Apr 17, 2018 at 7:31 AM, Maurice Waka  wrote:

> I hadn't done that. I'll redo
> Regards
>
> On Tue, Apr 17, 2018 at 7:26 AM, Dave S  wrote:
>
>>
>>
>> On Monday, April 16, 2018 at 9:04:35 PM UTC-7, Maurice Waka wrote:
>>>
>>> from this
>>> 
>>> link, i tried accessing values in db as follows:
>>>
>>>
>>> model:
>>>
>>> db.define_table('abnvalinterprets',
>>> Field('abnvalinterpret', length= 100),)
>>>
>>>
>>> Module:
>>>
>>> from gluon import current, DAL, Field
>>>
>>
>> [missing newline inserted]
>>
>>
>>> def abnvalinterpret():
>>> db = current.db
>>> db.define_table('abnvalinterprets',Field('abnvalinterpret', 'text',
>>> length=100))
>>> rows  = db().select(db.abnvalinterprets.abnvalinterpret.ALL)
>>> for row in rows:
>>> print row.abnvalinterpret
>>> abnvalinterpret()
>>>
>>>
>>>
>>>
>>> I keep getting this error:
>>> line 4, in abnvalinterpret
>>> db = current.db
>>> AttributeError: 'thread._local' object has no attribute 'db'
>>>
>>> Am testing if my module can access/print out data from the database. I
>>> hope that is the correct function too.
>>> Regards
>>>
>>
>>
>> Did you set current.db in the controller that calls your module?
>>
>> Also, I think you shouldn't re-define the table in your module.
>>
>> /dps
>>
>> --
>> Resources:
>> - http://web2py.com
>> - http://web2py.com/book (Documentation)
>> - http://github.com/web2py/web2py (Source code)
>> - https://code.google.com/p/web2py/issues/list (Report Issues)
>> ---
>> You received this message because you are subscribed to a topic in the
>> Google Groups "web2py-users" group.
>> To unsubscribe from this topic, visit https://groups.google.com/d/to
>> pic/web2py/wBVbeSdbc9o/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> web2py+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

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


Re: [web2py] Re: I cant access db data

2018-04-16 Thread Maurice Waka
I hadn't done that. I'll redo
Regards

On Tue, Apr 17, 2018 at 7:26 AM, Dave S  wrote:

>
>
> On Monday, April 16, 2018 at 9:04:35 PM UTC-7, Maurice Waka wrote:
>>
>> from this
>> 
>> link, i tried accessing values in db as follows:
>>
>>
>> model:
>>
>> db.define_table('abnvalinterprets',
>> Field('abnvalinterpret', length= 100),)
>>
>>
>> Module:
>>
>> from gluon import current, DAL, Field
>>
>
> [missing newline inserted]
>
>
>> def abnvalinterpret():
>> db = current.db
>> db.define_table('abnvalinterprets',Field('abnvalinterpret', 'text',
>> length=100))
>> rows  = db().select(db.abnvalinterprets.abnvalinterpret.ALL)
>> for row in rows:
>> print row.abnvalinterpret
>> abnvalinterpret()
>>
>>
>>
>>
>> I keep getting this error:
>> line 4, in abnvalinterpret
>> db = current.db
>> AttributeError: 'thread._local' object has no attribute 'db'
>>
>> Am testing if my module can access/print out data from the database. I
>> hope that is the correct function too.
>> Regards
>>
>
>
> Did you set current.db in the controller that calls your module?
>
> Also, I think you shouldn't re-define the table in your module.
>
> /dps
>
> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/web2py/wBVbeSdbc9o/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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: I cant access db data

2018-04-16 Thread Dave S


On Monday, April 16, 2018 at 9:04:35 PM UTC-7, Maurice Waka wrote:
>
> from this 
>  
> link, i tried accessing values in db as follows:
>
>
> model:
>
> db.define_table('abnvalinterprets',
> Field('abnvalinterpret', length= 100),)
>
>
> Module:
>
> from gluon import current, DAL, Field
>

[missing newline inserted]
 

> def abnvalinterpret():
> db = current.db
> db.define_table('abnvalinterprets',Field('abnvalinterpret', 'text', 
> length=100))
> rows  = db().select(db.abnvalinterprets.abnvalinterpret.ALL)
> for row in rows:
> print row.abnvalinterpret
> abnvalinterpret()
>
>
>
>
> I keep getting this error:
> line 4, in abnvalinterpret
> db = current.db
> AttributeError: 'thread._local' object has no attribute 'db'
>
> Am testing if my module can access/print out data from the database. I 
> hope that is the correct function too.
> Regards
>


Did you set current.db in the controller that calls your module?

Also, I think you shouldn't re-define the table in your module.

/dps

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


[web2py] I cant access db data

2018-04-16 Thread Maurice Waka
from this 
 
link, i tried accessing values in db as follows:


model:

db.define_table('abnvalinterprets',
Field('abnvalinterpret', length= 100),)


Module:

from gluon import current, DAL, Fielddef abnvalinterpret():
db = current.db
db.define_table('abnvalinterprets',Field('abnvalinterpret', 'text', 
length=100))
rows  = db().select(db.abnvalinterprets.abnvalinterpret.ALL)
for row in rows:
print row.abnvalinterpret
abnvalinterpret()




I keep getting this error:
line 4, in abnvalinterpret
db = current.db
AttributeError: 'thread._local' object has no attribute 'db'

Am testing if my module can access/print out data from the database. I hope 
that is the correct function too.
Regards

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


[web2py] Re: Dealing with db objects on duplicated app

2018-04-16 Thread Anthony
They are not sharing the same db object just by virtue of it having the 
same name in the code. The code of each app is executed independently 
within requests for each app. Please show the code you are using to 
instantiate the DAL object in each app.

Anthony

On Monday, April 16, 2018 at 7:58:03 PM UTC-4, Sergio Romero wrote:
>
> Hi there. 
>
> I have to deal with a duplicate example app on the same rocket server 
> instance. I have modified the sqlite file with each application interact 
> but both of the applicattions has the same db dal object name. 
>
> When I start the server each applications shares the users and have some 
> problems with the foreign keys when I try to insert a row on a table of 
> app1 if the same table exists on app2 
>
> How can I deal with this situation without refactor the db object name of 
> one of the application to isolate both applications and don't share the 
> instantiate db object between them. 
>
> Thanks

-- 
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] Dealing with db objects on duplicated app

2018-04-16 Thread Sergio Romero
Hi there.

I have to deal with a duplicate example app on the same rocket server instance. 
I have modified the sqlite file with each application interact but both of the 
applicattions has the same db dal object name.

When I start the server each applications shares the users and have some 
problems with the foreign keys when I try to insert a row on a table of app1 if 
the same table exists on app2

How can I deal with this situation without refactor the db object name of one 
of the application to isolate both applications and don't share the instantiate 
db object between them.

Thanks

-- 
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: Web2py locks row at auth_user and web2py_session_* tables and doesn't unlock them

2018-04-16 Thread Lisandro
Hi, thank you both for your time and concern.

@Richard: this particular website was still running with sessions stored in 
Redis. As we have several websites, moving sessions to Redis is something 
that we will do progressively in the next weeks.

@Anthony: the database server is PostgreSQL, running in the same VPS, so I 
wouldn't say it's due to network problems. I do have pgBouncer and I limit 
the pool size to only 1 connection (with 2 of reserve pool) per database. 
The app didn't have much load (actually it almost never has), but in this 
situation, with that query hanging for 60 seconds, it's probable that the 
ticket error was because there were no more connections available for that 
db (for example, if the user with the problem tried simultaneously in a 
laptop, in a pc and in his mobile phone). 


Some (weird) points about the problem:

   - While it presents in an specific account, other user accounts can 
   login and work perfectly with the app.
   - As an admin, I have the permission to impersonate other user accounts. 
   When the problem happens, I can impersonate any account but the one with 
   the problem (the impersonation is successfull, but the same timeout 
   presents after I'm impersonating the account).
   - Problem doesn't go away deleting all web2py_session_table records and 
   clearing cookies.
   - Problem doesn't go away changing the account email or password.
   - The only solution I've been applying last times it happened, was to 
   create a new account for the user and invalidate the old one.


Today, when the problem happened, I created the new account for the user 
and moved the sessions to Redis. Maybe I should have kept sessions in the 
db, in order to debug the problem with that account. Now it's not possible 
anymore, because I already moved to Redis. Of course I could move back 
sessions to db, but I don't like the idea of debugging at production in the 
website of a customer, specially one who had a recent issue with this.

So, I'll wait if it happens again, and I'll try to leave the account there 
to do some tests.
Thank you very much for your time!


El lunes, 16 de abril de 2018, 17:31:47 (UTC-3), Anthony escribió:
>
> Where is the database server running? Is it possible there are occasional 
> network problems connecting to it?
>
> Anthony
>
> On Monday, April 16, 2018 at 3:15:54 PM UTC-4, Lisandro wrote:
>>
>> Hi there, sorry to bother again, I have some additional info that could 
>> help.
>>
>> The problem happened again, exactly the same as the other times. 
>> But this time an error ticket was created with this traceback:
>>
>>- 
>>
>>Traceback (most recent call last):
>>  File "/var/www/medios/gluon/main.py", line 463, in wsgibase
>>session._try_store_in_db(request, response)
>>  File "/var/www/medios/gluon/globals.py", line 1152, in _try_store_in_db
>>if not table._db(table.id == record_id).update(**dd):
>>  File "/var/www/medios/gluon/packages/dal/pydal/objects.py", line 2117, 
>> in update
>>ret = db._adapter.update("%s" % table._tablename,self.query,fields)
>>  File "/var/www/medios/gluon/packages/dal/pydal/adapters/base.py", line 
>> 988, in update
>>raise e
>>DatabaseError: query_wait_timeout
>>server closed the connection unexpectedly
>>This probably means the server terminated abnormally
>>before or while processing the request.
>>
>>
>>
>> Could this indicate that for some reason web2py is failing to store the 
>> session?
>> Or could it still be that a deadlock in my app code is producing this 
>> error?
>>
>>
>> El viernes, 6 de abril de 2018, 18:59:28 (UTC-3), Lisandro escribió:
>>>
>>> Oh, I see, you made a good point there, I hadn't realised.
>>>
>>> I guess I will have to take a closer look to my app code. Considering 
>>> that the problem exists in specific accounts while others work ok, and 
>>> considering also that the problem happens with any request that that 
>>> specific user makes to any controller/function, I'm thinking: what does my 
>>> app do different for a user compared to another one at request level? For 
>>> "request level" I mean all the code the app runs in every request, to 
>>> start, the models/db.py
>>>
>>> I'll take a closer look to that and will post another message here if I 
>>> find something that could signal the root cause of the issue. 
>>>
>>> Thank you very much for your help!
>>>
>>>
>>>
>>> El viernes, 6 de abril de 2018, 16:05:13 (UTC-3), Anthony escribió:

 On Friday, April 6, 2018 at 10:58:56 AM UTC-4, Lisandro wrote:
>
> Yes, in fact, I've been running that SQL command to check for locks, 
> and sometimes I see that lock on other tables, but that other locks live 
> for less than a second. However, when the problem happens, the lock on 
> the 
> auth_user and web2py_session tables remains there for the whole 60 
> seconds.
>

 Yes, but that doesn't mean the 

[web2py] Re: Web2py locks row at auth_user and web2py_session_* tables and doesn't unlock them

2018-04-16 Thread Anthony
Where is the database server running? Is it possible there are occasional 
network problems connecting to it?

Anthony

On Monday, April 16, 2018 at 3:15:54 PM UTC-4, Lisandro wrote:
>
> Hi there, sorry to bother again, I have some additional info that could 
> help.
>
> The problem happened again, exactly the same as the other times. 
> But this time an error ticket was created with this traceback:
>
>- 
>
>Traceback (most recent call last):
>  File "/var/www/medios/gluon/main.py", line 463, in wsgibase
>session._try_store_in_db(request, response)
>  File "/var/www/medios/gluon/globals.py", line 1152, in _try_store_in_db
>if not table._db(table.id == record_id).update(**dd):
>  File "/var/www/medios/gluon/packages/dal/pydal/objects.py", line 2117, 
> in update
>ret = db._adapter.update("%s" % table._tablename,self.query,fields)
>  File "/var/www/medios/gluon/packages/dal/pydal/adapters/base.py", line 
> 988, in update
>raise e
>DatabaseError: query_wait_timeout
>server closed the connection unexpectedly
>This probably means the server terminated abnormally
>before or while processing the request.
>
>
>
> Could this indicate that for some reason web2py is failing to store the 
> session?
> Or could it still be that a deadlock in my app code is producing this 
> error?
>
>
> El viernes, 6 de abril de 2018, 18:59:28 (UTC-3), Lisandro escribió:
>>
>> Oh, I see, you made a good point there, I hadn't realised.
>>
>> I guess I will have to take a closer look to my app code. Considering 
>> that the problem exists in specific accounts while others work ok, and 
>> considering also that the problem happens with any request that that 
>> specific user makes to any controller/function, I'm thinking: what does my 
>> app do different for a user compared to another one at request level? For 
>> "request level" I mean all the code the app runs in every request, to 
>> start, the models/db.py
>>
>> I'll take a closer look to that and will post another message here if I 
>> find something that could signal the root cause of the issue. 
>>
>> Thank you very much for your help!
>>
>>
>>
>> El viernes, 6 de abril de 2018, 16:05:13 (UTC-3), Anthony escribió:
>>>
>>> On Friday, April 6, 2018 at 10:58:56 AM UTC-4, Lisandro wrote:

 Yes, in fact, I've been running that SQL command to check for locks, 
 and sometimes I see that lock on other tables, but that other locks live 
 for less than a second. However, when the problem happens, the lock on the 
 auth_user and web2py_session tables remains there for the whole 60 seconds.

>>>
>>> Yes, but that doesn't mean the lock or the database has anything to do 
>>> with the app hanging. The locks will be held for the duration of the 
>>> database transaction, and web2py wraps HTTP requests in a transaction, so 
>>> the transaction doesn't end until the request ends (unless you explicitly 
>>> call db.commit()). In other words, the app is not hanging because the locks 
>>> are being held, but rather the locks are being held because the app is 
>>> hanging. First you have to figure out why the app is hanging (it could be 
>>> the database, but could be something else).
>>>
>>> Anthony
>>>
>>

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


Re: [web2py] Re: Web2py locks row at auth_user and web2py_session_* tables and doesn't unlock them

2018-04-16 Thread Richard Vézina
Hello LIsandro,

I recall you have ask question about session in redis... Could there are
remaining stuff of experiment with redis that haven't been commented out
completly??

Richard

On Mon, Apr 16, 2018 at 3:15 PM, Lisandro 
wrote:

> Hi there, sorry to bother again, I have some additional info that could
> help.
>
> The problem happened again, exactly the same as the other times.
> But this time an error ticket was created with this traceback:
>
>-
>
>Traceback (most recent call last):
>  File "/var/www/medios/gluon/main.py", line 463, in wsgibase
>session._try_store_in_db(request, response)
>  File "/var/www/medios/gluon/globals.py", line 1152, in _try_store_in_db
>if not table._db(table.id == record_id).update(**dd):
>  File "/var/www/medios/gluon/packages/dal/pydal/objects.py", line 2117, 
> in update
>ret = db._adapter.update("%s" % table._tablename,self.query,fields)
>  File "/var/www/medios/gluon/packages/dal/pydal/adapters/base.py", line 
> 988, in update
>raise e
>DatabaseError: query_wait_timeout
>server closed the connection unexpectedly
>This probably means the server terminated abnormally
>before or while processing the request.
>
>
>
> Could this indicate that for some reason web2py is failing to store the
> session?
> Or could it still be that a deadlock in my app code is producing this
> error?
>
>
> El viernes, 6 de abril de 2018, 18:59:28 (UTC-3), Lisandro escribió:
>>
>> Oh, I see, you made a good point there, I hadn't realised.
>>
>> I guess I will have to take a closer look to my app code. Considering
>> that the problem exists in specific accounts while others work ok, and
>> considering also that the problem happens with any request that that
>> specific user makes to any controller/function, I'm thinking: what does my
>> app do different for a user compared to another one at request level? For
>> "request level" I mean all the code the app runs in every request, to
>> start, the models/db.py
>>
>> I'll take a closer look to that and will post another message here if I
>> find something that could signal the root cause of the issue.
>>
>> Thank you very much for your help!
>>
>>
>>
>> El viernes, 6 de abril de 2018, 16:05:13 (UTC-3), Anthony escribió:
>>>
>>> On Friday, April 6, 2018 at 10:58:56 AM UTC-4, Lisandro wrote:

 Yes, in fact, I've been running that SQL command to check for locks,
 and sometimes I see that lock on other tables, but that other locks live
 for less than a second. However, when the problem happens, the lock on the
 auth_user and web2py_session tables remains there for the whole 60 seconds.

>>>
>>> Yes, but that doesn't mean the lock or the database has anything to do
>>> with the app hanging. The locks will be held for the duration of the
>>> database transaction, and web2py wraps HTTP requests in a transaction, so
>>> the transaction doesn't end until the request ends (unless you explicitly
>>> call db.commit()). In other words, the app is not hanging because the locks
>>> are being held, but rather the locks are being held because the app is
>>> hanging. First you have to figure out why the app is hanging (it could be
>>> the database, but could be something else).
>>>
>>> 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.
>

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


Re: [web2py] Re: How to redirect http to https?

2018-04-16 Thread Anthony
On Monday, April 16, 2018 at 11:21:57 AM UTC-4, Ramos wrote:
>
> i prefer this tip from other post
>
> in models...
> session.secure()
> if not request.is_https:
>redirect(URL(scheme='https', args=request.args, vars=request.vars))
>

request.requires_https() is preferable to the above, as it does the same, 
but also ensures there is no redirect in case the code is being run by the 
web2py shell, the scheduler, or a cron job. It also forgets the session 
before the redirect so anything added to the session during the initial 
http request is not persisted into the https session.

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: Reverse relationships

2018-04-16 Thread Anthony


On Monday, April 16, 2018 at 11:47:28 AM UTC-4, Leonel Câmara wrote:
>
> Note that in web2py you can actually do something like this:
>
> db.define_table('tag', Field('name'))
>
> db.define_table('debate'. Field('title'))
>
> db.define_table('debate_tag', Field('tag', 'reference tag'), 
> Field('debate', 'reference debate'))
>
> Then say you want to know the tags debate with id 1 has
>
> db.debate[1].debate_tag.select()
>

Also, note that db.debate[1].debate_tag is a DAL Set object, which can be 
called and passed an additional query to further refine the results:

db.debate[1].debate_tag((db.debate_tag.tag == db.tag.id) & (db.tag.name.
startswith('a')).select(db.tag.name)

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: Web2py locks row at auth_user and web2py_session_* tables and doesn't unlock them

2018-04-16 Thread Lisandro
Hi there, sorry to bother again, I have some additional info that could 
help.

The problem happened again, exactly the same as the other times. 
But this time an error ticket was created with this traceback:

   - 
   
   Traceback (most recent call last):
 File "/var/www/medios/gluon/main.py", line 463, in wsgibase
   session._try_store_in_db(request, response)
 File "/var/www/medios/gluon/globals.py", line 1152, in _try_store_in_db
   if not table._db(table.id == record_id).update(**dd):
 File "/var/www/medios/gluon/packages/dal/pydal/objects.py", line 2117, in 
update
   ret = db._adapter.update("%s" % table._tablename,self.query,fields)
 File "/var/www/medios/gluon/packages/dal/pydal/adapters/base.py", line 
988, in update
   raise e
   DatabaseError: query_wait_timeout
   server closed the connection unexpectedly
   This probably means the server terminated abnormally
   before or while processing the request.
   
   

Could this indicate that for some reason web2py is failing to store the 
session?
Or could it still be that a deadlock in my app code is producing this error?


El viernes, 6 de abril de 2018, 18:59:28 (UTC-3), Lisandro escribió:
>
> Oh, I see, you made a good point there, I hadn't realised.
>
> I guess I will have to take a closer look to my app code. Considering that 
> the problem exists in specific accounts while others work ok, and 
> considering also that the problem happens with any request that that 
> specific user makes to any controller/function, I'm thinking: what does my 
> app do different for a user compared to another one at request level? For 
> "request level" I mean all the code the app runs in every request, to 
> start, the models/db.py
>
> I'll take a closer look to that and will post another message here if I 
> find something that could signal the root cause of the issue. 
>
> Thank you very much for your help!
>
>
>
> El viernes, 6 de abril de 2018, 16:05:13 (UTC-3), Anthony escribió:
>>
>> On Friday, April 6, 2018 at 10:58:56 AM UTC-4, Lisandro wrote:
>>>
>>> Yes, in fact, I've been running that SQL command to check for locks, and 
>>> sometimes I see that lock on other tables, but that other locks live for 
>>> less than a second. However, when the problem happens, the lock on the 
>>> auth_user and web2py_session tables remains there for the whole 60 seconds.
>>>
>>
>> Yes, but that doesn't mean the lock or the database has anything to do 
>> with the app hanging. The locks will be held for the duration of the 
>> database transaction, and web2py wraps HTTP requests in a transaction, so 
>> the transaction doesn't end until the request ends (unless you explicitly 
>> call db.commit()). In other words, the app is not hanging because the locks 
>> are being held, but rather the locks are being held because the app is 
>> hanging. First you have to figure out why the app is hanging (it could be 
>> the database, but could be something else).
>>
>> 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: table name created as a string in db model is not reference-able as a DB object in the controller

2018-04-16 Thread Michael Cowen
Apologies.  That's pretty fundamental to how all this works.  Thank you !


On Monday, April 16, 2018 at 9:53:08 AM UTC-5, Michael Cowen wrote:
>
> In the model file …/Models/db.py I have the following code
>
>  
>
> *# Connect to a local postgres instance*
>
> *db = DAL(**"postgres://user@localhost/DBName"**)*
>
>  
>
> *# Create some fields*
>
> *_name *   *= Field(**'name'**, *   *type=**'string'**, * *length=*
> *'256'** )*
>
> *_author* * = Field(**'author'**, * *type=**'string'**, * *length=*
> *'256'** )*
>
> *_created = Field(**'created'**, type=**'datetime'* * )*
>
>  
>
> *# Create a table from those fields*
>
> *db.define_table( **'project_common'**, _name, _author, _created )*
>
>  
>
>  
>
>  
>
> In the controller default.py I have the following code
>
>  
>
> *# Connect to a local postgres instance*
>
> *db = DAL(**"postgres://user@localhost/DBName"**)*
>
>  
>
> *# Insert or Update the row*
>
> *db.project_common.update_or_insert( * *\*
>
> *db.project_common.**name** == _**name**, \*
>
> *name= _name, **\*
>
> *author  = _author, *  *\*
>
> *created = _create, *  *\*
>
> *description = _description )*
>
>  
>
>  
>
> But I get an error the execution of the last statement above (
> *update_or_insert*) saying that  *db*  does not have an attribute  
> *project_common*
>
>  
>
> This feels like one of those posts where I am about to get pounded on for 
> something so basic.  I am new to web2py and comparing it to some other 
> alternatives.  Just making up silly test cases to try and experience it 
> before deciding what system to use.  Seems like a wonderful system that 
> absolutely blows away PHP development, has similarities to GAE, and 
> tremendous simplicity to install.  Very portable as well.  But I am 
> struggling with some basics of DAL.  Thanks for the help
>
>  
>

-- 
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: Reverse relationships

2018-04-16 Thread Leonel Câmara
Note that in web2py you can actually do something like this:

db.tag(Field('name'))

db.debate(Field('title'))

db.debate_tag(Field('tag', 'reference tag'), Field('debate', 'reference 
debate'))

Then say you want to know the tags debate with id 1 has

db.debate[1].debate_tag.select()

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


Re: [web2py] Re: How to redirect http to https?

2018-04-16 Thread António Ramos
i prefer this tip from other post

in models...
session.secure()
if not request.is_https:
   redirect(URL(scheme='https', args=request.args, vars=request.vars))

2018-04-16 15:51 GMT+01:00 Anthony :

> Another option is to configure your web server to do the redirect.
>
>
> On Monday, April 16, 2018 at 9:32:36 AM UTC-4, Leonel Câmara wrote:
>>
>> You can just put this in your model:
>>
>> request.requires_https()
>>
> --
> 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.
>

-- 
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: Requires web2py 2.15.5 or newer?

2018-04-16 Thread Anthony
On Sunday, April 15, 2018 at 11:45:02 PM UTC-4, Tarek Doha wrote:
>
> Hello,
>
> How to solve this?
>
> Requires web2py 2.15.5 or newer
>

Are you using the scaffolding app from web2py 2.15.5 with an earlier 
version of web2py? If so, you may run into problems, particularly with 
appadmin and web2py.js.

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: Customizing Fields the lazy way

2018-04-16 Thread Anthony
Looks good. A few suggestions:

   - There is no benefit to using a class with a single static method here 
   -- just extract the new() method and make it a standalone function (maybe 
   call it field_factory).
   - If you rename kwargs in the new() function to something else (e.g., 
   fargs), then there is no need to make a copy of it -- just refer to it 
   directly in the inner function. So, you can drop the first line of both 
   new() and inner().
   - The .get() method already returns None if the key does not exist, so 
   no need to add False or None as the second argument.

Anthony

On Monday, April 16, 2018 at 12:37:18 AM UTC-4, Joe Barnhart wrote:
>
> Actually, I borrowed Anthony's excellent idea and made a "factory" class 
> for my field definitions.
>
> First I defined a factory class:
>
> class Field_Factory(object):
> from gluon import Field
> @staticmethod
> def new(**kwargs):
> default = dict(**kwargs)
> def inner(name, **kwargs):
> args = dict(default)
> args.update(**kwargs)
> if args.pop('hidden',False):
> args.update(dict(readable=False,writable=False))
> req = args.get('requires', None)
> if req and (args.get('represent',None)=='formatter'):
> args['represent'] = req.formatter
> if args.pop('optional',False) and req:
> args['requires'] = IS_EMPTY_OR(req)
> rend = args.pop('render',None)
> rtn = Field(name, **args)
> if rend:
> rtn.render = rend
> return rtn
> return inner
>
> factory = Field_Factory()
>
> Then I used it to create a bunch of field generators:
>
> phone_field = factory.new(
> type='string', length=20,
> requires=IS_PHONE(), optional=True,
> widget=lambda fld,val: SQLFORM.widgets.string.widget(
> fld, val, _type='tel', _class='form-control')
> )
>
> email_field = factory.new(
> type='string', length=50,
> requires=IS_EMAIL(), optional=True,
> widget=lambda fld,val: SQLFORM.widgets.string.widget(
> fld, val, _type='email', _class='form-control')
> )
>
> date_field = factory.new(
> type='date',
> requires=IS_DATE(format='%m-%d-%Y'), optional=True,
> represent=lambda v,r: v.strftime('%m-%d-%Y'),
> widget=lambda fld,val:SQLFORM.widgets.date.widget(
> fld, val, _class="date form-control")
> )
>
> datetime_field = factory.new(
> type='datetime',
> requires=IS_DATETIME(format='%m-%d-%Y %I:%M:%S %p'), optional=True,
> represent=lambda v,r: v.strftime('%m-%d-%Y %I:%M:%S %p'),
> widget=lambda fld,val: SQLFORM.widgets.datetime.widget(
> fld, val, _class="datetime form-control")
> )
>
> zipcode_field = factory.new(
> type='string', length=10,
> requires=IS_ZIPCODE(),
> widget=lambda fld,val: SQLFORM.widgets.string.widget(
> fld, val, _type="zip", _class='zipcode form-control')
> )
>
> Finally, when I use the field generators in any table definitions, I can 
> further customize them and the changes are passed through.  
>
> define_table('joes_table',
>. . .
>date_field("birth", label=T("Birth date")),
>phone_field('homephone', label=T("Home phone")),
>phone_field('workphone', label=T("Work phone")),
>phone_field('cellphone', label=T("Cell phone")),
>. . .
>
>
>
> It all works really well and gives me the single point of control I want. 
>  It requires no changes in web2py and works with current, past, and future 
> versions.  And the lazy programmer in me marvels at all the code I don't 
> have to type.
>
> -- Joe
>
> On Thursday, March 23, 2017 at 12:54:58 PM UTC-7, Joe Barnhart wrote:
>>
>> Here is a bit of syntactic sugar I use for creating fields with less 
>> typing.  And better consistency, of course -- there always has to be a good 
>> reason for my lazy keyboard-saving shortcuts!
>>
>> I have a number of fields which are for specific data types, such as 
>> phone numbers.  I gather the "common" parts of the Field definition into a 
>> dictionary:
>>
>> phone_fld = {'requires':IS_EMPTY_OR(IS_PHONE()),
>>  'widget':lambda fld,val: SQLFORM.widgets.string.widget(fld,
>> val,_type='tel',_class='form-control')}
>>
>> When defining the field in a table, I invoke the dictionary at the end of 
>> the Field definition:
>>
>> Field("homephone","string",length=20,label=T("Home phone"),**phone_fld),
>> Field("workphone","string",length=20,label=T("Work phone"),**phone_fld),
>> Field("cellphone","string",length=20,label=T("Cell phone"),**phone_fld),
>>
>> Now the field is created exactly as I want.  I keep a list of these 
>> "helpers" in a module which I can call out when creating tables.  It really 
>> saves the typing and allow me to control how my fields are rendered on one 
>> place instead of scattered among all the tables.
>>
>> -- Joe
>>
>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- 

[web2py] Re: table name created as a string in db model is not reference-able as a DB object in the controller

2018-04-16 Thread Anthony


> In the controller default.py I have the following code
>
>  
>
> *# Connect to a local postgres instance*
>
> *db = DAL(**"postgres://user@localhost/DBName"**)*
>

You should not re-create the db object in the controller, as it has already 
been created in the model file. The code in the model files runs on every 
request (unless you use the conditional models functionality), so anything 
defined in the models will be available in the controller. You are creating 
a fresh db object in the controller, so none of the tables defined in the 
models will be there any longer.

Anthony

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


Re: [web2py] Re: Customizing Fields the lazy way

2018-04-16 Thread Richard Vézina
Thanks Joe,

I will have a better read... I had fix my issue, my customization of the
plugin introduce a couple of problem... I ends up refactoring the and only
load data when all the controlled field has to be updated "once". It fix
80% of the loading time issue the rest of the issue is user related because
they don't actualize record status.

The workaround above wasn't really necessary.

Richard

On Mon, Apr 16, 2018 at 12:37 AM, Joe Barnhart 
wrote:

> Actually, I borrowed Anthony's excellent idea and made a "factory" class
> for my field definitions.
>
> First I defined a factory class:
>
> class Field_Factory(object):
> from gluon import Field
> @staticmethod
> def new(**kwargs):
> default = dict(**kwargs)
> def inner(name, **kwargs):
> args = dict(default)
> args.update(**kwargs)
> if args.pop('hidden',False):
> args.update(dict(readable=False,writable=False))
> req = args.get('requires', None)
> if req and (args.get('represent',None)=='formatter'):
> args['represent'] = req.formatter
> if args.pop('optional',False) and req:
> args['requires'] = IS_EMPTY_OR(req)
> rend = args.pop('render',None)
> rtn = Field(name, **args)
> if rend:
> rtn.render = rend
> return rtn
> return inner
>
> factory = Field_Factory()
>
> Then I used it to create a bunch of field generators:
>
> phone_field = factory.new(
> type='string', length=20,
> requires=IS_PHONE(), optional=True,
> widget=lambda fld,val: SQLFORM.widgets.string.widget(
> fld, val, _type='tel', _class='form-control')
> )
>
> email_field = factory.new(
> type='string', length=50,
> requires=IS_EMAIL(), optional=True,
> widget=lambda fld,val: SQLFORM.widgets.string.widget(
> fld, val, _type='email', _class='form-control')
> )
>
> date_field = factory.new(
> type='date',
> requires=IS_DATE(format='%m-%d-%Y'), optional=True,
> represent=lambda v,r: v.strftime('%m-%d-%Y'),
> widget=lambda fld,val:SQLFORM.widgets.date.widget(
> fld, val, _class="date form-control")
> )
>
> datetime_field = factory.new(
> type='datetime',
> requires=IS_DATETIME(format='%m-%d-%Y %I:%M:%S %p'), optional=True,
> represent=lambda v,r: v.strftime('%m-%d-%Y %I:%M:%S %p'),
> widget=lambda fld,val: SQLFORM.widgets.datetime.widget(
> fld, val, _class="datetime form-control")
> )
>
> zipcode_field = factory.new(
> type='string', length=10,
> requires=IS_ZIPCODE(),
> widget=lambda fld,val: SQLFORM.widgets.string.widget(
> fld, val, _type="zip", _class='zipcode form-control')
> )
>
> Finally, when I use the field generators in any table definitions, I can
> further customize them and the changes are passed through.
>
> define_table('joes_table',
> . . .
> date_field("birth", label=T("Birth date")),
> . . .
>
>
> It all works really well and gives me the single point of control I want.
> It requires no changes in web2py and works with current, past, and future
> versions.  And the lazy programmer in me marvels at all the code I don't
> have to type.
>
> -- Joe
>
> On Thursday, March 23, 2017 at 12:54:58 PM UTC-7, Joe Barnhart wrote:
>>
>> Here is a bit of syntactic sugar I use for creating fields with less
>> typing.  And better consistency, of course -- there always has to be a good
>> reason for my lazy keyboard-saving shortcuts!
>>
>> I have a number of fields which are for specific data types, such as
>> phone numbers.  I gather the "common" parts of the Field definition into a
>> dictionary:
>>
>> phone_fld = {'requires':IS_EMPTY_OR(IS_PHONE()),
>>  'widget':lambda fld,val: SQLFORM.widgets.string.widget(fld,
>> val,_type='tel',_class='form-control')}
>>
>> When defining the field in a table, I invoke the dictionary at the end of
>> the Field definition:
>>
>> Field("homephone","string",length=20,label=T("Home phone"),**phone_fld),
>> Field("workphone","string",length=20,label=T("Work phone"),**phone_fld),
>> Field("cellphone","string",length=20,label=T("Cell phone"),**phone_fld),
>>
>> Now the field is created exactly as I want.  I keep a list of these
>> "helpers" in a module which I can call out when creating tables.  It really
>> saves the typing and allow me to control how my fields are rendered on one
>> place instead of scattered among all the tables.
>>
>> -- Joe
>>
>> --
> 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, 

[web2py] table name created as a string in db model is not reference-able as a DB object in the controller

2018-04-16 Thread Michael Cowen


In the model file …/Models/db.py I have the following code

 

*# Connect to a local postgres instance*

*db = DAL(**"postgres://user@localhost/DBName"**)*

 

*# Create some fields*

*_name *   *= Field(**'name'**, *   *type=**'string'**, * *length=*
*'256'** )*

*_author* * = Field(**'author'**, * *type=**'string'**, * *length=*
*'256'** )*

*_created = Field(**'created'**, type=**'datetime'* * )*

 

*# Create a table from those fields*

*db.define_table( **'project_common'**, _name, _author, _created )*

 

 

 

In the controller default.py I have the following code

 

*# Connect to a local postgres instance*

*db = DAL(**"postgres://user@localhost/DBName"**)*

 

*# Insert or Update the row*

*db.project_common.update_or_insert( * *\*

*db.project_common.**name** == _**name**, \*

*name= _name, **\*

*author  = _author, *  *\*

*created = _create, *  *\*

*description = _description )*

 

 

But I get an error the execution of the last statement above (
*update_or_insert*) saying that  *db*  does not have an attribute  
*project_common*

 

This feels like one of those posts where I am about to get pounded on for 
something so basic.  I am new to web2py and comparing it to some other 
alternatives.  Just making up silly test cases to try and experience it 
before deciding what system to use.  Seems like a wonderful system that 
absolutely blows away PHP development, has similarities to GAE, and 
tremendous simplicity to install.  Very portable as well.  But I am 
struggling with some basics of DAL.  Thanks for the help

 

-- 
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 redirect http to https?

2018-04-16 Thread Anthony
Another option is to configure your web server to do the redirect.

On Monday, April 16, 2018 at 9:32:36 AM UTC-4, Leonel Câmara wrote:
>
> You can just put this in your model:
>
> request.requires_https()
>

-- 
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 redirect http to https?

2018-04-16 Thread Leonel Câmara
You can just put this in your model:

request.requires_https()

-- 
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 redirect http to https?

2018-04-16 Thread António Ramos
hello i have a public web2py server on http.
Now i have to switch to https but i have a lot of users.
What is the best way to have them all loggin via https and not http?

regards

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


Re: [web2py] Re: Problem with a virtual field, SQLFORM.grid and the fields parameter

2018-04-16 Thread Martin Weissenboeck
Thank you, I'll try it!

icodk  schrieb am Mo., 16. Apr. 2018, 09:28:

> I had a similar issue and using the latest master branch fixed it for me
> (after the release of 2.16.1)
>
> On Saturday, April 14, 2018 at 10:52:10 PM UTC+2, mweissen wrote:
>>
>> I have a model with a virtual field:
>>
>> db.define_table("tt",
>> Field("f"),
>> Field("gg"),
>> Field.Virtual("ff", lambda r:r.tt.f)
>> )
>>
>>
>> And a grid:
>>
>> def t():
>> form = SQLFORM.grid(
>> db.tt,
>> )
>> return dict(form=form)
>>
>>
>> Works fine.
>> But with the *field argument* I get an error:
>>
>> def t():
>> form = SQLFORM.grid(
>> db.tt,
>> *fields=[**db.tt.ff]*
>> )
>> return dict(form=form)
>>
>>
>> Error ticket for "gridtest"
>> Ticket ID
>>
>> 194.118.190.134.2018-04-14.22-40-01.bc6da3b6-bd21-4dbe-8c78-f50c4a349fec
>> Version
>> web2py™ Version 2.15.4-stable+timestamp.2017.09.02.04.02.22
>> Python Python 2.7.12: /usr/local/bin/uwsgi (prefix: /usr/local)Traceback
>>
>> 1.
>> 2.
>> 3.
>> 4.
>> 5.
>> 6.
>> 7.
>> 8.
>> 9.
>> 10.
>> 11.
>> 12.
>> 13.
>> 14.
>>
>> Traceback (most recent call last):
>>   File "/home/www-data/web2py/gluon/restricted.py", line 219, in restricted
>> exec(ccode, environment)
>>   File "/home/www-data/web2py/applications/gridtest/controllers/default.py" 
>> , 
>> line 105, in 
>>   File "/home/www-data/web2py/gluon/globals.py", line 414, in 
>> self._caller = lambda f: f()
>>   File "/home/www-data/web2py/applications/gridtest/controllers/default.py" 
>> , 
>> line 16, in t
>> db.tt.ff,
>>   File "/home/www-data/web2py/gluon/sqlhtml.py", line 2886, in grid
>> value = row[str(field)]
>>   File "/home/www-data/web2py/gluon/packages/dal/pydal/objects.py", line 84, 
>> in __getitem__
>> raise KeyError
>> KeyError
>>
>> What is wrong?
>>
>>
>> Regards Martin
>>
>>
>> --
> 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.
>

-- 
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] Datetime onSelect event

2018-04-16 Thread tomasz bandura
Hello,

I need to do some action after selecting value in datetime field.
After my investigation it looks the one way is to create  my own datetime
component with implemented 'onSelect' event.

Another option  is to use another datetime (jquery) control.

I'd like to avoid it but i have no an idea how to add an event listener to
datetime control on a page.

Has anyone already met such an issue?

Tomasz

-- 
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 with a virtual field, SQLFORM.grid and the fields parameter

2018-04-16 Thread icodk
I had a similar issue and using the latest master branch fixed it for me
(after the release of 2.16.1)

On Saturday, April 14, 2018 at 10:52:10 PM UTC+2, mweissen wrote:
>
> I have a model with a virtual field:
>
> db.define_table("tt", 
> Field("f"),
> Field("gg"),
> Field.Virtual("ff", lambda r:r.tt.f)
> )
>
>
> And a grid:
>
> def t():
> form = SQLFORM.grid(
> db.tt,
> )
> return dict(form=form)
>
>
> Works fine.
> But with the *field argument* I get an error:
>
> def t():
> form = SQLFORM.grid(
> db.tt,
> *fields=[**db.tt.ff]*
> )
> return dict(form=form)
>
>
> Error ticket for "gridtest"
> Ticket ID
>
> 194.118.190.134.2018-04-14.22-40-01.bc6da3b6-bd21-4dbe-8c78-f50c4a349fec
> Version
> web2py™ Version 2.15.4-stable+timestamp.2017.09.02.04.02.22
> Python Python 2.7.12: /usr/local/bin/uwsgi (prefix: /usr/local)Traceback
>
> 1.
> 2.
> 3.
> 4.
> 5.
> 6.
> 7.
> 8.
> 9.
> 10.
> 11.
> 12.
> 13.
> 14.
>
> Traceback (most recent call last):
>   File "/home/www-data/web2py/gluon/restricted.py", line 219, in restricted
> exec(ccode, environment)
>   File "/home/www-data/web2py/applications/gridtest/controllers/default.py" 
> , 
> line 105, in 
>   File "/home/www-data/web2py/gluon/globals.py", line 414, in 
> self._caller = lambda f: f()
>   File "/home/www-data/web2py/applications/gridtest/controllers/default.py" 
> , 
> line 16, in t
> db.tt.ff,
>   File "/home/www-data/web2py/gluon/sqlhtml.py", line 2886, in grid
> value = row[str(field)]
>   File "/home/www-data/web2py/gluon/packages/dal/pydal/objects.py", line 84, 
> in __getitem__
> raise KeyError
> KeyError
>
> What is wrong?
>
>
> Regards Martin
>
>
>

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