[web2py] Re: Show "count()" result in view

2018-12-28 Thread Anthony
See 
http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Grouping-and-counting.

On Friday, December 28, 2018 at 6:46:25 AM UTC-5, Jonsubs wrote:
>
> Hi all,
> I'd like to know how to access the ".count()" result of a query from a 
> view.
>
> I have the following query in the controller:
>
> rows = 
> db(db.probdata).select(db.probdata.game,db.probdata.game.count(),groupby=db.probdata.game)
>
> And would like to show both the 'game' field and the number of entries for 
> each game. I tried the code below, but it crashes:
>
> 
> {{for r in rows:}}
> 
> {{=A(r.probdata.game,_href=URL('list_problems_by_game',args=r.probdata.game))}}
>  
> {{=r.probdata.game.count()}}
> {{pass}}
> 
>
> How should I access the result of the ".count()" part of the query from 
> the view?
> Thanks, Jon.
>

-- 
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: Show "count()" result in view

2018-12-28 Thread 黄祥
pardon, not sure got what you want to achieve
think if you want to count the rows data, should it better to count the 
data first (using compute in table constructor or count it manually before 
insert to the table) before put it on table?
or do the count calculation manually on the fly (on the view side, just 
extract the data n count it manually)

*ref:*
http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Table-constructor
http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#callbacks-on-record-insert-delete-and-update

best regards,
stifan

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


Re: [web2py] Re: an error while trying to combine an inner and outer joins

2018-12-28 Thread Eliezer (Vlad) Tseytkin
works like a charm!
thank you very much!



On Fri, Dec 28, 2018 at 5:11 AM Leonel Câmara 
wrote:

> Don't use fields=, fields is not a keyword argument so it's going into
> attributes, when it reaches select_wcols you endup having a fields keyword
> argument and a fields value in arguments which gives you that error.
>
> Change this too:
>
> cofounders = db((db.cofounder.company==company_id)&(db.cofounder.
> created_by==auth.user)).select(
> db.auth_user.first_name.with_alias('first_name'),
> db.auth_user.last_name.with_alias('last_name'),
> db.cofounder.note,
> db.cofounder_proposal.status.with_alias('status'),
> join=db.auth_user.on(db.cofounder.cofounder==db.auth_user.id),
> left=db.cofounder_proposal.on(db.cofounder_proposal.cofounder==db.
> cofounder.cofounder))
>
>
>
> --
> 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: Show "count()" result in view

2018-12-28 Thread Jon Subscripted
Thanks Stifan,
I see how can I do that for the whole query.

How can I do this row-wise? Can I create a "count_db" variable per row? As
I'm grouping by game and counting how many entries I have per game (after
grouping them), I would like to show the count per row.

The closest I got so far is by printing the whole row using:

{{=r}}
{{=A(r.probdata.game,_href=URL('list_problems_by_game',args=r.probdata.game))}}

And getting the result below:

   -  338841246
   
   -  338978835
   
   -  338995915
   

But I just want the  {'COUNT("probdata"."game")': 1L} part of the row.
Which for the lines above it would be something like this:


   - Game 338841246
   
1
   - Game 338978835
   
2
   - Game 338995915
   
2

Thanks & regards, Jon.

On Fri, Dec 28, 2018 at 1:52 PM 黄祥  wrote:

> just assign it to variable then pass it to the view
> *e.g. (not tested)*
> *controllers/default.py*
> def index():
> count_db = db(db.person.id > 0).count()
> dict(count_db = count_db)
>
> *views/default/index.html*
> {{= count_db}}
>
> *ref:*
>
> http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#count-isempty-delete-update
>
> best regards,
> stifan
>
> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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: @auth.requires_signature() vs @auth.requires_login()

2018-12-28 Thread Eliezer (Vlad) Tseytkin
So generally a perfect scenario could be if I use requireslogin on the
first step that requires login, and the subsequent steps from there I would
specify as requiresignature only, and this way all the subsequent steps
practically speaking would be under double protection, login AND signature,
as the only way to get to the subsequent steps is through the first one
(which required login).
Does this make sense?

On Fri, Dec 28, 2018, 5:21 AM Leonel Câmara  You may want to generate a link that a not logged in user can use. You may
> want to use signature to validate that a user comes from a specific step
> where he acquires the signature.
>
> --
> 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: Show "count()" result in view

2018-12-28 Thread 黄祥
just assign it to variable then pass it to the view
*e.g. (not tested)*
*controllers/default.py*
def index():
count_db = db(db.person.id > 0).count()
dict(count_db = count_db)

*views/default/index.html*
{{= count_db}}

*ref:*
http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#count-isempty-delete-update

best regards,
stifan

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


[web2py] Show "count()" result in view

2018-12-28 Thread Jon Subscripted
Hi all,
I'd like to know how to access the ".count()" result of a query from a view.

I have the following query in the controller:

rows =
db(db.probdata).select(db.probdata.game,db.probdata.game.count(),groupby=db.probdata.game)

And would like to show both the 'game' field and the number of entries for
each game. I tried the code below, but it crashes:


{{for r in rows:}}

{{=A(r.probdata.game,_href=URL('list_problems_by_game',args=r.probdata.game))}}
{{=r.probdata.game.count()}}
{{pass}}


How should I access the result of the ".count()" part of the query from the
view?
Thanks, Jon.

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


[web2py] Re: @auth.requires_signature() vs @auth.requires_login()

2018-12-28 Thread Leonel Câmara
You may want to generate a link that a not logged in user can use. You may 
want to use signature to validate that a user comes from a specific step 
where he acquires the signature.

-- 
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: an error while trying to combine an inner and outer joins

2018-12-28 Thread Leonel Câmara
Don't use fields=, fields is not a keyword argument so it's going into 
attributes, when it reaches select_wcols you endup having a fields keyword 
argument and a fields value in arguments which gives you that error.

Change this too:

cofounders = db((db.cofounder.company==company_id)&(db.cofounder.
created_by==auth.user)).select(
db.auth_user.first_name.with_alias('first_name'), 
db.auth_user.last_name.with_alias('last_name'), 
db.cofounder.note, 
db.cofounder_proposal.status.with_alias('status'), 
join=db.auth_user.on(db.cofounder.cofounder==db.auth_user.id),
left=db.cofounder_proposal.on(db.cofounder_proposal.cofounder==db.
cofounder.cofounder))



-- 
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] an error while trying to combine an inner and outer joins

2018-12-28 Thread Vlad
I am taking the table cofounder and making an inner join with auth_user and 
an outer join with cofounder_proposal: 

cofounders = 
db((db.cofounder.company==company_id)&(db.cofounder.created_by==auth.user)).select(
fields=[db.auth_user.first_name.with_alias('first_name'), 
db.auth_user.last_name.with_alias('last_name'), 
db.cofounder.note, 
db.cofounder_proposal.status.with_alias('status')], 
join=db.auth_user.on(db.cofounder.cofounder==db.auth_user.id),

left=db.cofounder_proposal.on(db.cofounder_proposal.cofounder==db.cofounder.cofounder))

It gives me an error: 
 _select_wcols() got multiple values for argument 
'fields'

I can't figure it out, as I am really deining fields just once - it's not 
specified otherwise anywhere. 

Any ideas?

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