Re: [web2py] Re: How to iterate through column items and display its rows data

2018-04-30 Thread Maurice Waka
Now another error :invalid syntax: random _number =
random.randrange(0,rows.count())

On Tue, 1 May 2018, 06:55 pbreit  wrote:

> Very sorry. Try:
>
> random_number = random.randrange(0, len(rows))
>
>
>
> On Monday, April 30, 2018 at 8:03:45 PM UTC-7, Maurice Waka wrote:
>>
>> I get this error : AttributeError: 'Rows' object has no attribute 'count'
>>
>> On Mon, 30 Apr 2018, 22:10 pbreit  wrote:
>>
>>> I would think something like:
>>>
>>> rows = db(db.person.id>0).select()
>>> random_number = random.randrange(0, rows.count())
>>> row = rows[random_number]
>>> return row
>>>
>>> --
>>> 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/ynBOuIdufso/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to
>>> web2py+un...@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 a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/web2py/ynBOuIdufso/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: How to iterate through column items and display its rows data

2018-04-30 Thread Maurice Waka
Thanks. I got the count.

On Tue, 1 May 2018, 06:41 Sandeep Patel  wrote:

>  Try this
> rows = db(db.person.id>0).count()
>
>
> On Tue, May 1, 2018 at 8:33 AM, Maurice Waka 
> wrote:
>
>> I get this error : AttributeError: 'Rows' object has no attribute 'count'
>>
>> On Mon, 30 Apr 2018, 22:10 pbreit  wrote:
>>
>>> I would think something like:
>>>
>>> rows = db(db.person.id>0).select()
>>> random_number = random.randrange(0, rows.count())
>>> row = rows[random_number]
>>> return row
>>>
>>> --
>>> 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/ynBOuIdufso/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.
>>
>
> --
> 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/ynBOuIdufso/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: How to iterate through column items and display its rows data

2018-04-30 Thread pbreit
Very sorry. Try:

random_number = random.randrange(0, len(rows))



On Monday, April 30, 2018 at 8:03:45 PM UTC-7, Maurice Waka wrote:
>
> I get this error : AttributeError: 'Rows' object has no attribute 'count' 
>
> On Mon, 30 Apr 2018, 22:10 pbreit > 
> wrote:
>
>> I would think something like:
>>
>> rows = db(db.person.id>0).select()
>> random_number = random.randrange(0, rows.count())
>> row = rows[random_number]
>> return row
>>
>> -- 
>> 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/ynBOuIdufso/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to 
>> web2py+un...@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: VIEW NAME NOT ID

2018-04-30 Thread pbreit
Are you trying to do something like this?

http://www.web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Grouping-and-counting

-- 
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 iterate through column items and display its rows data

2018-04-30 Thread Sandeep Patel
 Try this
rows = db(db.person.id>0).count()


On Tue, May 1, 2018 at 8:33 AM, Maurice Waka  wrote:

> I get this error : AttributeError: 'Rows' object has no attribute 'count'
>
> On Mon, 30 Apr 2018, 22:10 pbreit  wrote:
>
>> I would think something like:
>>
>> rows = db(db.person.id>0).select()
>> random_number = random.randrange(0, rows.count())
>> row = rows[random_number]
>> return row
>>
>> --
>> 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/ynBOuIdufso/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.
>

-- 
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] DAL return all Fields

2018-04-30 Thread Maurice Waka
What would f, v be.
I get this error : ValueError : too many values to unpack

On Mon, 30 Apr 2018, 20:38 Richard Vézina 
wrote:

>
>
> On Mon, Apr 30, 2018 at 1:21 PM, Maurice Waka 
> wrote:
>
>> Sorry I tried to clarify by my new question :
>>
>> If I have a column with data like db.persons with data like
>> Carl
>> Junior
>> Maggie
>> Tom
>> Derrick
>>
>> And each column name has other fields with data such as:
>> persons.name persons.age persons.location persons.occupation
>> persons.interests
>> Carl 23 London Neuroscientist brainy stuff
>> Junior 25 Tokyo doctor medical research
>> Maggie 33 Nairobi farmer GMO research
>> Tom 25 Sydney teacher educational ideas
>> Derrick 21 Chicago surgeon Cutting through
>>
>>
>>
>> I want to iterate through the column  persons.nameand randomly pick a
>> name and using the rows object, display all data about the person.
>>
>> If I do
>> rows_name = db().select(db.persons.name).column()
>>
>
>
> The above should be :
>
> fields = db.persons.fields
> # You should have in fields a list of all fields names you migth want to
> remove "id" field by filtering it or find index and pop it out of the list
> # ex.: fields.pop(fields.index('id'))
>
>
>
>>
>>
>> rows = db(db.persons.ALL).select()
>>
>
> db(where_clause).select(fields_name_separated_by_comma)
>
> The above is completly wrong as you pass the fields instead of specifying
> your where clause parameter...
>
> In you example you really only need select like this :
>
> def some_func_name()
> rows = db(db.persons.id > 0).select(db.persons.ALL)
>
> rows_values = []
> for row in rows:
> row_value = []
> for f, v in row:
> if f != 'id':
> row_value.append(v)
> rows_values.append(row_value)
> return rows_values
>
> ret = some_func_name()
>
> for r in ret:
> print(' '.join(ret))
>
> I didn't tested it but the above should work...
>
> Good luck
>
>>
>> for row in rows:
>> if rows_name[0] == 'Maggie':
>> for row in rows:
>> return [row.age+' '+row.location+' '+row.occupation+' '+
>> row.interests]
>>
>> The problem is that if I query 'Carl' which is the first item, I get the
>> response but I cant query any other name .
>> 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 a topic in the
>> Google Groups "web2py-users" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/web2py/ynBOuIdufso/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.
>> I had been using python isle to test some modules. Now I just want to get
>> a clearer code by removing the long codes.
>>
>>
>> On Mon, 30 Apr 2018, 20:09 Richard Vézina 
>> wrote:
>>
>>> Man this is convulated...
>>>
>>> Not sure what is in name4 "name4 is a list that contains items found in
>>> db.health.name, as well as other dbs." what items are you referring
>>> at?? What other dbs?
>>>
>>> Why are you connecting to sqlite by your own...
>>>
>>> This check is just weird :
>>>
>>> if id == item in name4:
>>>
>>> I would suggest you don't use function to achieve what you try to do it
>>> just make it overcomplicated... Also never define functions in models files
>>> it will slow down your app as models files are executed at each request.
>>>
>>> My guess is that if you end with the final list that you showed us is
>>> because at some point you put the name of the fields you want instead of
>>> the value attached to them...
>>>
>>> But seriously it very difficult to help...
>>>
>>> You could show us all the models that are important to the problem and
>>> show us an example of what you want at the end.
>>>
>>>
>>> I also don't know from you field name in health table what they content.
>>>
>>> So for example let say
>>>
>>>
>>> You have a table name fruit
>>>
>>> rows = db(db.fruit.id > 0).select(db.fruit.ALL)
>>>
>>> With a fruit_name field
>>>
>>> for r in rows:
>>> print('A {0} is a fruit blah blah blah. A {0} when its green is
>>> bitter to taste. A {0} when ripe looks bright yellow and tastes
>>> sweet.'.format(r.fruit_name)
>>>
>>> That's it!!
>>>
>>> Richard
>>>
>>>
>>> On Sat, Apr 28, 2018 at 11:02 AM, Maurice Waka 
>>> wrote:
>>>
 Thanks, but I seem to be having a challenge when returning the rows
 from a specific id name or number. I tried this on a different app as
 follows:

 Model:

 db.define_table( "health",
 Field('name', 'string'),
 Field('definition', 'text', length= 100,
 default="We'll update soon.", notnull=True),
 Field('abnvals', 'text', length= 100,default="We'll
>>

Re: [web2py] Re: How to iterate through column items and display its rows data

2018-04-30 Thread Maurice Waka
I get this error : AttributeError: 'Rows' object has no attribute 'count'

On Mon, 30 Apr 2018, 22:10 pbreit  wrote:

> I would think something like:
>
> rows = db(db.person.id>0).select()
> random_number = random.randrange(0, rows.count())
> row = rows[random_number]
> return row
>
> --
> 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/ynBOuIdufso/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: VIEW NAME NOT ID

2018-04-30 Thread Ayron Rangel

>
> Sorry, man!
>

How can I put on my way?? based on my code!! 
 


 

-- 
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 iterate through column items and display its rows data

2018-04-30 Thread pbreit
I would think something like:

rows = db(db.person.id>0).select()
random_number = random.randrange(0, rows.count())
row = rows[random_number]
return row

-- 
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: VIEW NAME NOT ID

2018-04-30 Thread Dave S


On Monday, April 30, 2018 at 10:53:20 AM UTC-7, Ayron Rangel wrote:
>
>  I have this:
>
> db.py:
> db.define_table('product_input',
> Field('product', db.product, notnull=True),
> Field('total_price','decimal(7,2)', readable=False,writable=False),
> Field('amount', 'integer', readable=False,writable=False),
> Field('supplier', db.supplier, notnull=True),
> Field('location', db.location, notnull=True),
> Field('input_type', 'string'),
> auth.signature,
> format = lambda r: '%s %s %s %s  [%s]' % (r.product.model.model, 
> r.product.manufacturer.manufacturer, r.product.part_number, 
>r.product.serial_number, r.product.expiration_date)
> 
> )
>
> default.py: 
> def stock():
> count = db.product_input.id.count()
> results = db(db.product_input).select(db.product_input.product, count, 
> groupby=db.product)
> return locals()
>
> view: 
> {{for row in results:}}
> 
> {{=row[db.product_input.product]}}
> {{=row[count]}}
> 
> {{pass}}
>
>
> APPEARS JUST THIS:
>
> Product in Stock [Model]Amount
> 6 2
> 7 2
>
> HOW CAN APPEARS THE NAME NOT THE ID ON DE LINE?
>
>
You need to tell web2py to display a reference field by the appropriate 
value; the index value is the default.

See  
http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#format--Record-representation>

and the example in
http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#One-to-many-relation>

/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] VIEW NAME NOT ID

2018-04-30 Thread Ayron Rangel
 I have this:

db.py:
db.define_table('product_input',
Field('product', db.product, notnull=True),
Field('total_price','decimal(7,2)', readable=False,writable=False),
Field('amount', 'integer', readable=False,writable=False),
Field('supplier', db.supplier, notnull=True),
Field('location', db.location, notnull=True),
Field('input_type', 'string'),
auth.signature,
format = lambda r: '%s %s %s %s  [%s]' % (r.product.model.model, 
r.product.manufacturer.manufacturer, r.product.part_number, 
   r.product.serial_number, r.product.expiration_date)

)

default.py: 
def stock():
count = db.product_input.id.count()
results = db(db.product_input).select(db.product_input.product, count, 
groupby=db.product)
return locals()

view: 
{{for row in results:}}

{{=row[db.product_input.product]}}
{{=row[count]}}

{{pass}}


APPEARS JUST THIS:

Product in Stock [Model]Amount
6 2
7 2

HOW CAN APPEARS THE NAME NOT THE ID ON DE LINE?




-- 
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] DAL return all Fields

2018-04-30 Thread Maurice Waka
Thank you. Let me work on it.
Regards

On Mon, 30 Apr 2018, 20:38 Richard Vézina 
wrote:

>
>
> On Mon, Apr 30, 2018 at 1:21 PM, Maurice Waka 
> wrote:
>
>> Sorry I tried to clarify by my new question :
>>
>> If I have a column with data like db.persons with data like
>> Carl
>> Junior
>> Maggie
>> Tom
>> Derrick
>>
>> And each column name has other fields with data such as:
>> persons.name persons.age persons.location persons.occupation
>> persons.interests
>> Carl 23 London Neuroscientist brainy stuff
>> Junior 25 Tokyo doctor medical research
>> Maggie 33 Nairobi farmer GMO research
>> Tom 25 Sydney teacher educational ideas
>> Derrick 21 Chicago surgeon Cutting through
>>
>>
>>
>> I want to iterate through the column  persons.nameand randomly pick a
>> name and using the rows object, display all data about the person.
>>
>> If I do
>> rows_name = db().select(db.persons.name).column()
>>
>
>
> The above should be :
>
> fields = db.persons.fields
> # You should have in fields a list of all fields names you migth want to
> remove "id" field by filtering it or find index and pop it out of the list
> # ex.: fields.pop(fields.index('id'))
>
>
>
>>
>>
>> rows = db(db.persons.ALL).select()
>>
>
> db(where_clause).select(fields_name_separated_by_comma)
>
> The above is completly wrong as you pass the fields instead of specifying
> your where clause parameter...
>
> In you example you really only need select like this :
>
> def some_func_name()
> rows = db(db.persons.id > 0).select(db.persons.ALL)
>
> rows_values = []
> for row in rows:
> row_value = []
> for f, v in row:
> if f != 'id':
> row_value.append(v)
> rows_values.append(row_value)
> return rows_values
>
> ret = some_func_name()
>
> for r in ret:
> print(' '.join(ret))
>
> I didn't tested it but the above should work...
>
> Good luck
>
>>
>> for row in rows:
>> if rows_name[0] == 'Maggie':
>> for row in rows:
>> return [row.age+' '+row.location+' '+row.occupation+' '+
>> row.interests]
>>
>> The problem is that if I query 'Carl' which is the first item, I get the
>> response but I cant query any other name .
>> 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 a topic in the
>> Google Groups "web2py-users" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/web2py/ynBOuIdufso/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.
>> I had been using python isle to test some modules. Now I just want to get
>> a clearer code by removing the long codes.
>>
>>
>> On Mon, 30 Apr 2018, 20:09 Richard Vézina 
>> wrote:
>>
>>> Man this is convulated...
>>>
>>> Not sure what is in name4 "name4 is a list that contains items found in
>>> db.health.name, as well as other dbs." what items are you referring
>>> at?? What other dbs?
>>>
>>> Why are you connecting to sqlite by your own...
>>>
>>> This check is just weird :
>>>
>>> if id == item in name4:
>>>
>>> I would suggest you don't use function to achieve what you try to do it
>>> just make it overcomplicated... Also never define functions in models files
>>> it will slow down your app as models files are executed at each request.
>>>
>>> My guess is that if you end with the final list that you showed us is
>>> because at some point you put the name of the fields you want instead of
>>> the value attached to them...
>>>
>>> But seriously it very difficult to help...
>>>
>>> You could show us all the models that are important to the problem and
>>> show us an example of what you want at the end.
>>>
>>>
>>> I also don't know from you field name in health table what they content.
>>>
>>> So for example let say
>>>
>>>
>>> You have a table name fruit
>>>
>>> rows = db(db.fruit.id > 0).select(db.fruit.ALL)
>>>
>>> With a fruit_name field
>>>
>>> for r in rows:
>>> print('A {0} is a fruit blah blah blah. A {0} when its green is
>>> bitter to taste. A {0} when ripe looks bright yellow and tastes
>>> sweet.'.format(r.fruit_name)
>>>
>>> That's it!!
>>>
>>> Richard
>>>
>>>
>>> On Sat, Apr 28, 2018 at 11:02 AM, Maurice Waka 
>>> wrote:
>>>
 Thanks, but I seem to be having a challenge when returning the rows
 from a specific id name or number. I tried this on a different app as
 follows:

 Model:

 db.define_table( "health",
 Field('name', 'string'),
 Field('definition', 'text', length= 100,
 default="We'll update soon.", notnull=True),
 Field('abnvals', 'text', length= 100,default="We'll
 update soon.", notnull=True),
   

Re: [web2py] DAL return all Fields

2018-04-30 Thread Richard Vézina
On Mon, Apr 30, 2018 at 1:21 PM, Maurice Waka  wrote:

> Sorry I tried to clarify by my new question :
>
> If I have a column with data like db.persons with data like
> Carl
> Junior
> Maggie
> Tom
> Derrick
>
> And each column name has other fields with data such as:
> persons.name persons.age persons.location persons.occupation
> persons.interests
> Carl 23 London Neuroscientist brainy stuff
> Junior 25 Tokyo doctor medical research
> Maggie 33 Nairobi farmer GMO research
> Tom 25 Sydney teacher educational ideas
> Derrick 21 Chicago surgeon Cutting through
>
>
>
> I want to iterate through the column  persons.nameand randomly pick a
> name and using the rows object, display all data about the person.
>
> If I do
> rows_name = db().select(db.persons.name).column()
>


The above should be :

fields = db.persons.fields
# You should have in fields a list of all fields names you migth want to
remove "id" field by filtering it or find index and pop it out of the list
# ex.: fields.pop(fields.index('id'))



>
>
> rows = db(db.persons.ALL).select()
>

db(where_clause).select(fields_name_separated_by_comma)

The above is completly wrong as you pass the fields instead of specifying
your where clause parameter...

In you example you really only need select like this :

def some_func_name()
rows = db(db.persons.id > 0).select(db.persons.ALL)

rows_values = []
for row in rows:
row_value = []
for f, v in row:
if f != 'id':
row_value.append(v)
rows_values.append(row_value)
return rows_values

ret = some_func_name()

for r in ret:
print(' '.join(ret))

I didn't tested it but the above should work...

Good luck

>
> for row in rows:
> if rows_name[0] == 'Maggie':
> for row in rows:
> return [row.age+' '+row.location+' '+row.occupation+' '+
> row.interests]
>
> The problem is that if I query 'Carl' which is the first item, I get the
> response but I cant query any other name .
> 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 a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit https://groups.google.
> com/d/topic/web2py/ynBOuIdufso/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.
> I had been using python isle to test some modules. Now I just want to get
> a clearer code by removing the long codes.
>
>
> On Mon, 30 Apr 2018, 20:09 Richard Vézina 
> wrote:
>
>> Man this is convulated...
>>
>> Not sure what is in name4 "name4 is a list that contains items found in
>> db.health.name, as well as other dbs." what items are you referring at??
>> What other dbs?
>>
>> Why are you connecting to sqlite by your own...
>>
>> This check is just weird :
>>
>> if id == item in name4:
>>
>> I would suggest you don't use function to achieve what you try to do it
>> just make it overcomplicated... Also never define functions in models files
>> it will slow down your app as models files are executed at each request.
>>
>> My guess is that if you end with the final list that you showed us is
>> because at some point you put the name of the fields you want instead of
>> the value attached to them...
>>
>> But seriously it very difficult to help...
>>
>> You could show us all the models that are important to the problem and
>> show us an example of what you want at the end.
>>
>>
>> I also don't know from you field name in health table what they content.
>>
>> So for example let say
>>
>>
>> You have a table name fruit
>>
>> rows = db(db.fruit.id > 0).select(db.fruit.ALL)
>>
>> With a fruit_name field
>>
>> for r in rows:
>> print('A {0} is a fruit blah blah blah. A {0} when its green is
>> bitter to taste. A {0} when ripe looks bright yellow and tastes
>> sweet.'.format(r.fruit_name)
>>
>> That's it!!
>>
>> Richard
>>
>>
>> On Sat, Apr 28, 2018 at 11:02 AM, Maurice Waka 
>> wrote:
>>
>>> Thanks, but I seem to be having a challenge when returning the rows from
>>> a specific id name or number. I tried this on a different app as follows:
>>>
>>> Model:
>>>
>>> db.define_table( "health",
>>> Field('name', 'string'),
>>> Field('definition', 'text', length= 100,
>>> default="We'll update soon.", notnull=True),
>>> Field('abnvals', 'text', length= 100,default="We'll
>>> update soon.", notnull=True),
>>> Field('normvals', 'text', length= 100,default="We'll
>>> update soon.", notnull=True),
>>> def selections():
>>> code
>>> return name4# name4 is a list that contains items found in
>>> db.health.name, as well as other dbs.
>>>  def refer11():
>>> db = current.db
>>> 

Re: [web2py] DAL return all Fields

2018-04-30 Thread Maurice Waka
Sorry I tried to clarify by my new question :

If I have a column with data like db.persons with data like
Carl
Junior
Maggie
Tom
Derrick

And each column name has other fields with data such as:
persons.name persons.age persons.location persons.occupation
persons.interests
Carl 23 London Neuroscientist brainy stuff
Junior 25 Tokyo doctor medical research
Maggie 33 Nairobi farmer GMO research
Tom 25 Sydney teacher educational ideas
Derrick 21 Chicago surgeon Cutting through



I want to iterate through the column  persons.nameand randomly pick a name
and using the rows object, display all data about the person.

If I do
rows_name = db().select(db.persons.name).column()

rows = db(db.persons.ALL).select()
for row in rows:
if rows_name[0] == 'Maggie':
for row in rows:
return [row.age+' '+row.location+' '+row.occupation+' '+row.
interests]

The problem is that if I query 'Carl' which is the first item, I get the
response but I cant query any other name .
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 a topic in the
Google Groups "web2py-users" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/web2py/ynBOuIdufso/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.
I had been using python isle to test some modules. Now I just want to get a
clearer code by removing the long codes.


On Mon, 30 Apr 2018, 20:09 Richard Vézina 
wrote:

> Man this is convulated...
>
> Not sure what is in name4 "name4 is a list that contains items found in
> db.health.name, as well as other dbs." what items are you referring at??
> What other dbs?
>
> Why are you connecting to sqlite by your own...
>
> This check is just weird :
>
> if id == item in name4:
>
> I would suggest you don't use function to achieve what you try to do it
> just make it overcomplicated... Also never define functions in models files
> it will slow down your app as models files are executed at each request.
>
> My guess is that if you end with the final list that you showed us is
> because at some point you put the name of the fields you want instead of
> the value attached to them...
>
> But seriously it very difficult to help...
>
> You could show us all the models that are important to the problem and
> show us an example of what you want at the end.
>
>
> I also don't know from you field name in health table what they content.
>
> So for example let say
>
>
> You have a table name fruit
>
> rows = db(db.fruit.id > 0).select(db.fruit.ALL)
>
> With a fruit_name field
>
> for r in rows:
> print('A {0} is a fruit blah blah blah. A {0} when its green is
> bitter to taste. A {0} when ripe looks bright yellow and tastes
> sweet.'.format(r.fruit_name)
>
> That's it!!
>
> Richard
>
>
> On Sat, Apr 28, 2018 at 11:02 AM, Maurice Waka 
> wrote:
>
>> Thanks, but I seem to be having a challenge when returning the rows from
>> a specific id name or number. I tried this on a different app as follows:
>>
>> Model:
>>
>> db.define_table( "health",
>> Field('name', 'string'),
>> Field('definition', 'text', length= 100,
>> default="We'll update soon.", notnull=True),
>> Field('abnvals', 'text', length= 100,default="We'll
>> update soon.", notnull=True),
>> Field('normvals', 'text', length= 100,default="We'll
>> update soon.", notnull=True),
>> def selections():
>> code
>> return name4# name4 is a list that contains items found in db.health.name,
>> as well as other dbs.
>>  def refer11():
>> db = current.db
>> rows = db(db.health).iterselect()
>> for row in rows:
>> id = row.name
>> if id == item in name4:
>> #return [', '.join(item) for item in rows]# Gives a list of the titles
>> only as: ['name','definition','abnvals','normvals',]
>> #return [item for item in rows]# Gives this:
>> [
>> #return row# gives this : 
>> #return [item for item in row]# Gives a list of
>> the titles only as: ['name','definition','abnvals','normvals',]
>>
>> When using sql speak, this works well:
>> def refer11():
>> id = 0
>> location = ""
>> conn = sqlite3.connect('wellness.db')
>> c = conn.cursor()
>> c.execute('select * from health')
>> records = c.fetchall()
>> for record in records:
>> id = record[1]
>> for item in name4:
>> if id == item in name4:
>> return record[2:]
>>
>> If row.name has e.g. apple, mango, guava, pineapple, then
>>
>> and the fields contain info about the fruits e.g.
>>
>> if id/row.name picks mango, i want a list of these:
>>
>> definition data: A mango is a fruit blah blah blah.
>> abnvals data: A mango w

Re: [web2py] DAL return all Fields

2018-04-30 Thread Richard Vézina
Man this is convulated...

Not sure what is in name4 "name4 is a list that contains items found in
db.health.name, as well as other dbs." what items are you referring at??
What other dbs?

Why are you connecting to sqlite by your own...

This check is just weird :

if id == item in name4:

I would suggest you don't use function to achieve what you try to do it
just make it overcomplicated... Also never define functions in models files
it will slow down your app as models files are executed at each request.

My guess is that if you end with the final list that you showed us is
because at some point you put the name of the fields you want instead of
the value attached to them...

But seriously it very difficult to help...

You could show us all the models that are important to the problem and show
us an example of what you want at the end.


I also don't know from you field name in health table what they content.

So for example let say


You have a table name fruit

rows = db(db.fruit.id > 0).select(db.fruit.ALL)

With a fruit_name field

for r in rows:
print('A {0} is a fruit blah blah blah. A {0} when its green is bitter
to taste. A {0} when ripe looks bright yellow and tastes
sweet.'.format(r.fruit_name)

That's it!!

Richard


On Sat, Apr 28, 2018 at 11:02 AM, Maurice Waka 
wrote:

> Thanks, but I seem to be having a challenge when returning the rows from a
> specific id name or number. I tried this on a different app as follows:
>
> Model:
>
> db.define_table( "health",
> Field('name', 'string'),
> Field('definition', 'text', length= 100,
> default="We'll update soon.", notnull=True),
> Field('abnvals', 'text', length= 100,default="We'll
> update soon.", notnull=True),
> Field('normvals', 'text', length= 100,default="We'll
> update soon.", notnull=True),
> def selections():
> code
> return name4# name4 is a list that contains items found in db.health.name,
> as well as other dbs.
>  def refer11():
> db = current.db
> rows = db(db.health).iterselect()
> for row in rows:
> id = row.name
> if id == item in name4:
> #return [', '.join(item) for item in rows]# Gives a list of the titles
> only as: ['name','definition','abnvals','normvals',]
> #return [item for item in rows]# Gives this: [
> #return row# gives this : 
> #return [item for item in row]# Gives a list of
> the titles only as: ['name','definition','abnvals','normvals',]
>
> When using sql speak, this works well:
> def refer11():
> id = 0
> location = ""
> conn = sqlite3.connect('wellness.db')
> c = conn.cursor()
> c.execute('select * from health')
> records = c.fetchall()
> for record in records:
> id = record[1]
> for item in name4:
> if id == item in name4:
> return record[2:]
>
> If row.name has e.g. apple, mango, guava, pineapple, then
>
> and the fields contain info about the fruits e.g.
>
> if id/row.name picks mango, i want a list of these:
>
> definition data: A mango is a fruit blah blah blah.
> abnvals data: A mango when its green is bitter to taste.
> normvals data: A mango when ripe looks bright yellow and tastes sweet.
>
> so when doing return row
> I should get ['A mango is a fruit blah blah blah. A mango when its green
> is bitter to taste. A mango when ripe looks bright yellow and tastes
> sweet.]
> and not
> ['name','definition','abnvals','normvals',]
>
> On Fri, Apr 27, 2018 at 6:16 PM, Richard Vézina <
> ml.richard.vez...@gmail.com> wrote:
>
>> for f in db.table.fields:
>> print f
>>
>> or
>>
>> rows = db(db.fruits.id > 0).select(db.fruits.ALL)  # ALL means all fields
>>
>> for r in rows:
>> print(r)
>>
>> You can control which field you want with the previous example
>>
>> myfields = [f for f in db.table.fields if SOME_FILTERING_CHECK_OVER_THE_
>> FIELD_YOU_WANT]
>>
>>
>> for r in rows:
>> for f in myfields:
>> print(r[f])
>>
>>
>> You can play around that you should be able to figure out how you can do
>> what you wanna do.
>>
>> Richard
>>
>> On Fri, Apr 27, 2018 at 10:08 AM, Maurice Waka 
>> wrote:
>>
>>> Addendum
>>>
>>> I want a single list of  the items (the data from all fields)
>>>
>>> regards
>>>
>>> On Fri, Apr 27, 2018 at 5:06 PM, Maurice Waka 
>>> wrote:
>>>
 There are several fields in my db such as this:

 db.define_table('fruit', Field('id', 'reference auth_user'), 
 Field('apple','boolean',label=T('Apple')), 
 Field('apricot','boolean',label=T('Apricot')), 
 Field('cherry','boolean',label=T('Cherry')), Field('fig','boolean', 
 label=T('Fig')), Field('lychee','boolean', label=T('Lychee')), 
 Field('peach','boolean', label=T('Peach')), Field('pear','boolean', 
 label=T('Pear')), Field('plum','boolean', label=T('Plum')))
 If i want to print items from a specific field i would do:

 rows = db(db.fruits)select()for row in rows:
  return row.apple


 Now

[web2py] PRINT LIST:REFERENCE

2018-04-30 Thread Ayron Rangel
Hi have this structure:

db.py:

#DEFINE PRODUCT INPUT
db.define_table('product_input',
Field('product', db.product, notnull=True),
Field('total_price','decimal(7,2)', readable=False,writable=False),
Field('amount', 'integer', readable=False,writable=False),
Field('supplier', db.supplier, notnull=True),
Field('location', db.location, notnull=True),
Field('input_type', 'string'),
auth.signature,
format = lambda r: '%s %s %s %s  [%s]' % (r.product.model.model, 
r.product.manufacturer.manufacturer, r.product.part_number, 
   r.product.serial_number, r.product.expiration_date)

)

db.define_table('product_output',
Field('product', 'list:reference product_input', multiple=True),
Field('ship', db.ship, notnull=True),
Field('total_price', 'decimal(7,2)', writable=False),
Field('data_output', 'date', notnull=True),
Field('output_type', 'string', notnull=True),
auth.signature,
format = '%(product)s'
)

default.py:

def new_product_input():
form = SQLFORM(db.product_input)
if form.process().accepted:
session.flash = 'Registration Saved Successfully'
redirect(URL('product_input'))
elif form.errors:
response.flash = 'Attention: errors in the form.'
return dict(form=form)


view: 

{{extend 'new-layout.html'}}

{{=form.custom.begin}}






Stock Output Add{{=response.flash or ''}}



Product in Stock
{{=form.custom.widget.product_input.product}}Select the Product in Stock
Add New Product 
to Stock




I GET THIS ERROR: AttributeError: 'NoneType' object has no attribute 
'product'

HOW CAN I VIEW THE LIST IN HTML??

-- 
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 iterate through column items and display its rows data

2018-04-30 Thread Maurice Waka
If I have a column with data like db.persons with data like
Carl
Junior
Maggie
Tom
Derrick

And each column name has other fields with data such as:
persons.name persons.age persons.location persons.occupation 
persons.interests 
Carl 23 London Neuroscientist brainy stuff 
Junior 25 Tokyo doctor medical research 
Maggie 33 Nairobi farmer GMO research 
Tom 25 Sydney teacher educational ideas 
Derrick 21 Chicago surgeon Cutting through 
 


I want to iterate through the column  persons.name and randomly pick a name 
and using the rows object, display all data about the person.

If I do 
rows_name = db().select(db.persons.name).column()

rows = db(db.persons.ALL).select()
for row in rows:
if rows_name[0] == 'Maggie':
for row in rows:
return [row.age+' '+row.location+' '+row.occupation+' '+row.
interests]

The problem is that if I query 'Carl' which is the first item, I get the 
response but I cant query any other name .
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.