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

2018-04-17 Thread Maurice Waka
Thanks. It worked.

On Tue, 17 Apr 2018, 15:37 Anthony  wrote:

> On Tuesday, April 17, 2018 at 1:33:29 AM UTC-4, Maurice Waka wrote:
>>
>> 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
>>
>
> There is nothing in web2py that automatically adds the db object (or any
> object created by your own code) to the current object, so you must do
> this yourself. The above line should instead be the opposite assignment:
>
> current.db = db
>
> In other words, in a model file or controller, you can add objects to
> current, and then in a module, you can import current and access those
> objects.
>
> Alternatively, any object in the web2py global environment (including any
> created in the model files) can also be accessed via the current.globalenv
> dictionary. For example:
>
> current.globalenv['db']
>
> 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 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.


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

2018-04-17 Thread Anthony
On Tuesday, April 17, 2018 at 1:33:29 AM UTC-4, Maurice Waka wrote:
>
> 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
>

There is nothing in web2py that automatically adds the db object (or any 
object created by your own code) to the current object, so you must do this 
yourself. The above line should instead be the opposite assignment:

current.db = db

In other words, in a model file or controller, you can add objects to 
current, and then in a module, you can import current and access those 
objects.

Alternatively, any object in the web2py global environment (including any 
created in the model files) can also be accessed via the current.globalenv 
dictionary. For example:

current.globalenv['db']

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