Re: [web2py] Re: Creating table on the fly with the app in production

2019-03-08 Thread Gualter Portella
Thanks, Leonel! I will try it out tomorrow. 
Cheers 

Enviado do meu iPhone

Em 8 de mar de 2019, à(s) 19:58, Leonel Câmara  
escreveu:

> The simple stuff you talk about should simply work:
> 
> 0. backup the database, this is just good practice...
> 1. if you're running the scheduler you should stop it until migration is 
> finished and migrate is disabled
> 2. update the code making sure migrate is True.
> 3. visit appadmin to make sure all tables migrated even if they're lazy
> 4. disable migrations
> 5. restart scheduler
> 
> We should probably have a command line to do 2,3 and 4...
> -- 
> 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/QppWmXa4iSY/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: Open a new page in the browser from redirect or URL

2019-03-08 Thread icodk
My be it is an idea for improving the grid by add (yet another)  option  
 to have radio buttons instead of checkboxes

On Saturday, March 9, 2019 at 12:08:50 AM UTC+1, icodk wrote:
>
> I would do it in javascript in the view and simulate radio buttons, which 
> means that every time the user is selecting a checkbox the script will 
> clear the former selected checkbox. This way you don't have to deal with 
> informing the user, about multiple selections.
>
> On Friday, March 8, 2019 at 9:07:55 PM UTC+1, João Matos wrote:
>>
>> The problem is that my origin page has a grid with extra buttons, using 
>> the selectable option.
>> And that option does not allow using _target or anything similar. It can 
>> only call a function (which is the function on the 1st message).
>> That function checks if there is only 1 record selected in the grid and 
>> if so calls the button action (add, edit, ...)
>> What I would like is for this action to open a new page.
>>
>> Do you see some solution?
>>
>> sexta-feira, 8 de Março de 2019 às 19:39:06 UTC, Leonel Câmara escreveu:
>>>
>>> It's sort of possible using response.js = "window.open(url, '_blank')" 
>>> however any modern browser will consider this a popup and block it because 
>>> it's a window.open that's not coming as a direct result of a click, you can 
>>> then move a step forward fighting with the user's browser preferences and 
>>> instead of using window.open you send javascript that creates an A element 
>>> and clicks it, or even a form that submits to another page.  
>>>   
>>> Don't do this, it won't work reliably. Depending on what you're trying 
>>> to do a good alternative can be to use a modal, or putting a 
>>> _target="_blank" in your form so it submits to a new window.
>>>
>>

-- 
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: Open a new page in the browser from redirect or URL

2019-03-08 Thread João Matos
The grid's checkboxes (and their multiple selection) are not the problem.
The problem is that my origin page has a grid with extra buttons, using the 
selectable option. And I wanted one of the buttons (from the selectable 
option) to open a view in another browser page.
Can I control the buttons from the grid's selectable option from Javascript?


sexta-feira, 8 de Março de 2019 às 23:08:50 UTC, icodk escreveu:
>
> I would do it in javascript in the view and simulate radio buttons, which 
> means that every time the user is selecting a checkbox the script will 
> clear the former selected checkbox. This way you don't have to deal with 
> informing the user, about multiple selections.
>
> On Friday, March 8, 2019 at 9:07:55 PM UTC+1, João Matos wrote:
>>
>> The problem is that my origin page has a grid with extra buttons, using 
>> the selectable option.
>> And that option does not allow using _target or anything similar. It can 
>> only call a function (which is the function on the 1st message).
>> That function checks if there is only 1 record selected in the grid and 
>> if so calls the button action (add, edit, ...)
>> What I would like is for this action to open a new page.
>>
>> Do you see some solution?
>>
>> sexta-feira, 8 de Março de 2019 às 19:39:06 UTC, Leonel Câmara escreveu:
>>>
>>> It's sort of possible using response.js = "window.open(url, '_blank')" 
>>> however any modern browser will consider this a popup and block it because 
>>> it's a window.open that's not coming as a direct result of a click, you can 
>>> then move a step forward fighting with the user's browser preferences and 
>>> instead of using window.open you send javascript that creates an A element 
>>> and clicks it, or even a form that submits to another page.  
>>>   
>>> Don't do this, it won't work reliably. Depending on what you're trying 
>>> to do a good alternative can be to use a modal, or putting a 
>>> _target="_blank" in your form so it submits to a new window.
>>>
>>

-- 
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: Open a new page in the browser from redirect or URL

2019-03-08 Thread icodk
I would do it in javascript in the view and simulate radio buttons, which 
means that every time the user is selecting a checkbox the script will 
clear the former selected checkbox. This way you don't have to deal with 
informing the user, about multiple selections.

On Friday, March 8, 2019 at 9:07:55 PM UTC+1, João Matos wrote:
>
> The problem is that my origin page has a grid with extra buttons, using 
> the selectable option.
> And that option does not allow using _target or anything similar. It can 
> only call a function (which is the function on the 1st message).
> That function checks if there is only 1 record selected in the grid and if 
> so calls the button action (add, edit, ...)
> What I would like is for this action to open a new page.
>
> Do you see some solution?
>
> sexta-feira, 8 de Março de 2019 às 19:39:06 UTC, Leonel Câmara escreveu:
>>
>> It's sort of possible using response.js = "window.open(url, '_blank')" 
>> however any modern browser will consider this a popup and block it because 
>> it's a window.open that's not coming as a direct result of a click, you can 
>> then move a step forward fighting with the user's browser preferences and 
>> instead of using window.open you send javascript that creates an A element 
>> and clicks it, or even a form that submits to another page.  
>>   
>> Don't do this, it won't work reliably. Depending on what you're trying to 
>> do a good alternative can be to use a modal, or putting a _target="_blank" 
>> in your form so it submits to a new window.
>>
>

-- 
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: Creating table on the fly with the app in production

2019-03-08 Thread Leonel Câmara
The simple stuff you talk about should simply work:

0. backup the database, this is just good practice...
1. if you're running the scheduler you should stop it until migration is 
finished and migrate is disabled
2. update the code making sure migrate is True.
3. visit appadmin to make sure all tables migrated even if they're lazy
4. disable migrations
5. restart scheduler

We should probably have a command line to do 2,3 and 4...

-- 
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] Creating table on the fly with the app in production

2019-03-08 Thread Gualter Portella
Hi everyone,
My app is in production and is hosted at RoseHosting.
I will soon need to create several tables and want to avoid those “auth.user 
table has already been created” messages when the app crashes as I insert new 
code on, for example, db.py.
I will insert code like this, simple stuff:
db.define_table(‘sometsble’, Field(‘somefield’, ‘string’, notnull=True))
My question is:
Are there step by step explanations available on how to do it without much try 
and error puzzles?
Did not find anything really clear on this matter either on web2py manual or on 
the web.
Any suggestions or help?
Many thanks.
Gualter 

-- 
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: Open a new page in the browser from redirect or URL

2019-03-08 Thread João Matos
The problem is that my origin page has a grid with extra buttons, using the 
selectable option.
And that option does not allow using _target or anything similar. It can 
only call a function (which is the function on the 1st message).
That function checks if there is only 1 record selected in the grid and if 
so calls the button action (add, edit, ...)
What I would like is for this action to open a new page.

Do you see some solution?

sexta-feira, 8 de Março de 2019 às 19:39:06 UTC, Leonel Câmara escreveu:
>
> It's sort of possible using response.js = "window.open(url, '_blank')" 
> however any modern browser will consider this a popup and block it because 
> it's a window.open that's not coming as a direct result of a click, you can 
> then move a step forward fighting with the user's browser preferences and 
> instead of using window.open you send javascript that creates an A element 
> and clicks it, or even a form that submits to another page.  
>   
> Don't do this, it won't work reliably. Depending on what you're trying to 
> do a good alternative can be to use a modal, or putting a _target="_blank" 
> in your form so it submits to a new window.
>

-- 
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: Open a new page in the browser from redirect or URL

2019-03-08 Thread Leonel Câmara
It's sort of possible using response.js = "window.open(url, '_blank')" 
however any modern browser will consider this a popup and block it because 
it's a window.open that's not coming as a direct result of a click, you can 
then move a step forward fighting with the user's browser preferences and 
instead of using window.open you send javascript that creates an A element 
and clicks it, or even a form that submits to another page.  
  
Don't do this, it won't work reliably. Depending on what you're trying to 
do a good alternative can be to use a modal, or putting a _target="_blank" 
in your form so it submits to a new window.

-- 
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] Open a new page in the browser from redirect or URL

2019-03-08 Thread João Matos
Hello,

I have this function

def check_only_one_selection(ids, destination):
# type: (List[int], str) -> None
"""Check only one selection in grid.

:param ids: List of Ids.
:param destination: Destination page if one selection was made.
"""
if len(ids) > 1:
session.flash = T('Select only one record.')
else:
redirect(URL(destination, args=[ids[0]])



and would like it to open the it's view on another web page (not the same 
from where it was called).
Something similar to this


but without using A.

Is it possible?

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: "NameError: name 'pydal' is not defined" when function has typing type in def

2019-03-08 Thread João Matos
I'm using Python 3.7.1. Can that explain this strange situation?
I'm calling web2py with the -e command line option to see the errors and 
there are none.

sexta-feira, 8 de Março de 2019 às 18:30:48 UTC, Leonel Câmara escreveu:
>
> web2py doesn't do that. This is weird. Both those lines should give you 
> errors.
>

-- 
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: "NameError: name 'pydal' is not defined" when function has typing type in def

2019-03-08 Thread Leonel Câmara
web2py doesn't do that. This is weird. Both those lines should give you 
errors.

-- 
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: "NameError: name 'pydal' is not defined" when function has typing type in def

2019-03-08 Thread João Matos
Just for testing, I removed pydal.objects.Table from the function header 
and changed the line inside the function from

row: pydal.objects.Row = table[rec_id]

to

row: pydal.objects.Table = table[rec_id]

without importing anything from pydal or pydal.objects, anywhere in 
controllers, models or modules.

And it worked without any problem.

My conclusion is that either web2py is importing pyday.objects automatically 
inside the function, but not when it calls (loads) the function, or web2py is 
not showing the errors inside the function.

Any thoughts?



sexta-feira, 8 de Março de 2019 às 17:40:41 UTC, Leonel Câmara escreveu:
>
> Weird because that doesn't work for me if I don't import pydal so I'm 
> guessing you have a import pydal.objects.Row somewhere in your models. That 
> said you can just use DAL.Table and DAL.Row which are imports web2py does 
> make for you.
>

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


[web2py] Re: "NameError: name 'pydal' is not defined" when function has typing type in def

2019-03-08 Thread João Matos
No, I don't import pydal.objects.Row anywhere in my modules, controllers 
even in models.


sexta-feira, 8 de Março de 2019 às 17:40:41 UTC, Leonel Câmara escreveu:
>
> Weird because that doesn't work for me if I don't import pydal so I'm 
> guessing you have a import pydal.objects.Row somewhere in your models. That 
> said you can just use DAL.Table and DAL.Row which are imports web2py does 
> make for you.
>

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


[web2py] Re: How to create a nested json dictionary by loading data from a flat, parent-referencing list?

2019-03-08 Thread Leonel Câmara
Note that parent_name should be the actual field name and not the field 
itself. In your case parent_name='object_super_object_fk'

-- 
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: "NameError: name 'pydal' is not defined" when function has typing type in def

2019-03-08 Thread Leonel Câmara
Weird because that doesn't work for me if I don't import pydal so I'm 
guessing you have a import pydal.objects.Row somewhere in your models. That 
said you can just use DAL.Table and DAL.Row which are imports web2py does 
make for you.

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


[web2py] Re: How to create a nested json dictionary by loading data from a flat, parent-referencing list?

2019-03-08 Thread Alex Glaros
The manual’s example uses a single, self-referencing table. What would be the 
syntax for joined, parent/child tables?  

 

I get an AttributeError. Not sure if the parent_name formation is the problem

 

roots = db((db.role_member.id > 0) & (db.role_member.object_super_object_fk 
== 
db.object_super_object.id)).select().as_trees(parent_name=db.role_member.object_super_object_fk)
  File 
"C:\alex\alt_web2py_11_new_boot\web2py_win\web2py\gluon\packages\dal\pydal\objects.py",
 line 2470, in as_trees
drows[row.id] = row
  File 
"C:\alex\alt_web2py_11_new_boot\web2py_win\web2py\gluon\packages\dal\pydal\objects.py",
 line 109, in __getattr__
raise AttributeError

 

It seems that the solution could be to create a set so there is only one 
record-type:

 

mySet = db((db.role_member.id > 0)  & (db.role_member.object_super_object_fk == 
db.object_super_object.id)).select()

 

Then find some way to make it work within as_trees:

 

roots = db(mySet).select().as_trees(parent_name='mySet.object_super_object_fk')

-- 
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: "NameError: name 'pydal' is not defined" when function has typing type in def

2019-03-08 Thread João Matos

Didn't know that, will correct auth.requires_login with auth.is_logged_in.

No I did not import pydal.

If I remove the type specification from the function header it works, even 
when I'm also mentioning pydal inside the function in the line

 row: pydal.objects.Row = table[rec_id]
which means pydal is imported by web2py.




sexta-feira, 8 de Março de 2019 às 17:06:38 UTC, Leonel Câmara escreveu:
>
> Note that requires_login is meant to be used as a decorator, you should be 
> using auth.is_logged_in() 
>
> Did you import pydal?
>

-- 
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: "NameError: name 'pydal' is not defined" when function has typing type in def

2019-03-08 Thread Leonel Câmara
Note that requires_login is meant to be used as a decorator, you should be 
using auth.is_logged_in() 

Did you import pydal?

-- 
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: Poweredby error

2019-03-08 Thread Kevin Keller
Hey Daniel,

we need a bit more details to be able to see what is going on.

We can not see what the ticket text says from the link that you posted.

Please share the full traceback.
Give us a glimbs what you want to achieve and what you have already done.
Which models/functions are doing the main part of your app?

Also which web2py version, os, python version etc do you use?

Thanks!

On Fri, Mar 8, 2019 at 5:52 PM Daniel Guilhermino <
danielguilherm...@gmail.com> wrote:

>  Anyone?
>
> Em quinta-feira, 28 de fevereiro de 2019 09:42:56 UTC-3, Daniel
> Guilhermino escreveu:
>>
>> Hi,
>>
>> I've just tried to submit an new application made with web2py and
>> integrated with Dialogflow, but the following error was show:
>>
>>
>> Internal errorTicket issued:
>> poweredby/191.162.178.30.2019-02-28.12-36-03.22ce450a-64b7-4832-8d08-750e16ce25c2
>> 
>>
>> Best 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.
>

-- 
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: Poweredby error

2019-03-08 Thread Daniel Guilhermino
 Anyone?

Em quinta-feira, 28 de fevereiro de 2019 09:42:56 UTC-3, Daniel Guilhermino 
escreveu:
>
> Hi,
>
> I've just tried to submit an new application made with web2py and 
> integrated with Dialogflow, but the following error was show:
>
>
> Internal errorTicket issued: 
> poweredby/191.162.178.30.2019-02-28.12-36-03.22ce450a-64b7-4832-8d08-750e16ce25c2
>  
> 
>
> Best 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: web2py reports "invalid function (client/get_approval)" when function has typing return type

2019-03-08 Thread João Matos

  
  
Hello,

I already opened an issue on Github.

Thanks, but I prefer to stick with the old type syntax
 # type: () -> Dict[str, SQLFORM]

solution instead of creating another function.


Best regards,

João Matos

On 08-03-2019 16:45, Anthony wrote:


  
  In order to determine which functions in a
controller file to expose as actions, web2py uses the following
regex (the intention is to identify only functions that take no
arguments and don't start with a double underscore):



  
  '^def\s+(?P_?[a-zA-Z0-9]\w*)\(
  *\)\s*:'

  
  As you can see, this does not support type hints. Feel free to
  open an issue on Github or submit a pull request to allow type
  hints.


In the meantime, you can create a separate function with
  the type hint and call that function from within a non-hinted
  action:



def get_approval():
    return
hinted_get_approval()
  


Anthony
  
  On Friday, March 8, 2019 at 9:31:58 AM UTC-5, João Matos
  wrote:
  

  If I write this function
  from typing import Dict

@auth.requires(lambda: (auth.requires_login() and request.env.http_referer
and ('/client' in request.env.http_referer
 or '/client/get_approval' in request.env.http_referer)))
def get_approval() -> Dict[str, SQLFORM]:
"""Get approval for deletion.

:return: Dict with form.
"""
rec_id: str = request.args[0]

rows_dic: Dict[int, str] = {**general.get_members(db, SUPERVISOR_ROLE),
**general.get_members(db, MANAGER_ROLE)}

form = SQLFORM.factory(
Field('user_id', label=T('Supervisor/Manager'),
  requires=IS_IN_SET(rows_dic, zero=T('Choose one...'))),
Field('password', 'password', label=T('Password'), requires=IS_NOT_EMPTY()),
  buttons=[BUTTON(T('Submit'), _type='submit', _class='btn btn-primary')],
  formstyle='table3cols',
)
...
return dict(form=form)
 
  web2py shows a web page with the message
invalid function (client/get_approval)
  
  
  
  If however I write it without the return type on the
header
  from typing import Dict

@auth.requires(lambda: (auth.requires_login() and request.env.http_referer
and ('/client' in request.env.http_referer
 or '/client/get_approval' in request.env.http_referer)))
def get_approval():
# type: () -> Dict[str, SQLFORM]
"""Get approval for deletion.

:return: Dict with form.
"""
rec_id: str = request.args[0]

rows_dic: Dict[int, str] = {**general.get_members(db, SUPERVISOR_ROLE),
**general.get_members(db, MANAGER_ROLE)}

form = SQLFORM.factory(
Field('user_id', label=T('Supervisor/Manager'),
  requires=IS_IN_SET(rows_dic, zero=T('Choose one...'))),
Field('password', 'password', label=T('Password'), requires=IS_NOT_EMPTY()),
  buttons=[BUTTON(T('Submit'), _type='submit', _class='btn btn-primary')],
  formstyle='table3cols',
)
...
return dict(form=form)

  
  
  it all works.
  
  
  
  I even tried with just -> Dict to see if it was a
problem with SQLFORM, but it returns the same message.
  
  
  Windows 7 Pro x64 SP1+all updates
Firefox 65.0.2 x64
Python 3.7.1 x86
web2py 2.18.3

  

  
  -- 
  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/YtJOP9Bv9ro/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"

[web2py] Re: web2py reports "invalid function (client/get_approval)" when function has typing return type

2019-03-08 Thread Anthony
In order to determine which functions in a controller file to expose as 
actions, web2py uses the following regex (the intention is to identify only 
functions that take no arguments and don't start with a double underscore):

'^def\s+(?P_?[a-zA-Z0-9]\w*)\( *\)\s*:'

As you can see, this does not support type hints. Feel free to open an 
issue on Github or submit a pull request to allow type hints.

In the meantime, you can create a separate function with the type hint and 
call that function from within a non-hinted action:

def get_approval():
return hinted_get_approval()

Anthony

On Friday, March 8, 2019 at 9:31:58 AM UTC-5, João Matos wrote:
>
> If I write this function
>
> from typing import Dict
>
> @auth.requires(lambda: (auth.requires_login() and request.env.http_referer
> and ('/client' in request.env.http_referer
>  or '/client/get_approval' in 
> request.env.http_referer)))
> def get_approval() -> Dict[str, SQLFORM]:
> """Get approval for deletion.
>
> :return: Dict with form.
> """
> rec_id: str = request.args[0]
>
> rows_dic: Dict[int, str] = {**general.get_members(db, SUPERVISOR_ROLE),
> **general.get_members(db, MANAGER_ROLE)}
>
> form = SQLFORM.factory(
> Field('user_id', label=T('Supervisor/Manager'),
>   requires=IS_IN_SET(rows_dic, zero=T('Choose one...'))),
> Field('password', 'password', label=T('Password'), 
> requires=IS_NOT_EMPTY()),
>   buttons=[BUTTON(T('Submit'), _type='submit', _class='btn 
> btn-primary')],
>   formstyle='table3cols',
> )
> ...
> return dict(form=form)
>  
>
> web2py shows a web page with the message
> invalid function (client/get_approval)
>
>
> If however I write it without the return type on the header
>
> from typing import Dict
>
> @auth.requires(lambda: (auth.requires_login() and request.env.http_referer
> and ('/client' in request.env.http_referer
>  or '/client/get_approval' in 
> request.env.http_referer)))
> def get_approval():
> # type: () -> Dict[str, SQLFORM]
> """Get approval for deletion.
>
> :return: Dict with form.
> """
> rec_id: str = request.args[0]
>
> rows_dic: Dict[int, str] = {**general.get_members(db, SUPERVISOR_ROLE),
> **general.get_members(db, MANAGER_ROLE)}
>
> form = SQLFORM.factory(
> Field('user_id', label=T('Supervisor/Manager'),
>   requires=IS_IN_SET(rows_dic, zero=T('Choose one...'))),
> Field('password', 'password', label=T('Password'), 
> requires=IS_NOT_EMPTY()),
>   buttons=[BUTTON(T('Submit'), _type='submit', _class='btn 
> btn-primary')],
>   formstyle='table3cols',
> )
> ...
> return dict(form=form)
>
>
> it all works.
>
>
> I even tried with just -> Dict to see if it was a problem with SQLFORM, 
> but it returns the same message.
>
>
> Windows 7 Pro x64 SP1+all updates
> Firefox 65.0.2 x64
> Python 3.7.1 x86
> web2py 2.18.3
>

-- 
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] web2py reports "invalid function (client/get_approval)" when function has typing return type

2019-03-08 Thread João Matos


If I write this function

from typing import Dict

@auth.requires(lambda: (auth.requires_login() and request.env.http_referer
and ('/client' in request.env.http_referer
 or '/client/get_approval' in 
request.env.http_referer)))
def get_approval() -> Dict[str, SQLFORM]:
"""Get approval for deletion.

:return: Dict with form.
"""
rec_id: str = request.args[0]

rows_dic: Dict[int, str] = {**general.get_members(db, SUPERVISOR_ROLE),
**general.get_members(db, MANAGER_ROLE)}

form = SQLFORM.factory(
Field('user_id', label=T('Supervisor/Manager'),
  requires=IS_IN_SET(rows_dic, zero=T('Choose one...'))),
Field('password', 'password', label=T('Password'), 
requires=IS_NOT_EMPTY()),
  buttons=[BUTTON(T('Submit'), _type='submit', _class='btn 
btn-primary')],
  formstyle='table3cols',
)
...
return dict(form=form)
 

web2py shows a web page with the message
invalid function (client/get_approval)


If however I write it without the return type on the header

from typing import Dict

@auth.requires(lambda: (auth.requires_login() and request.env.http_referer
and ('/client' in request.env.http_referer
 or '/client/get_approval' in 
request.env.http_referer)))
def get_approval():
# type: () -> Dict[str, SQLFORM]
"""Get approval for deletion.

:return: Dict with form.
"""
rec_id: str = request.args[0]

rows_dic: Dict[int, str] = {**general.get_members(db, SUPERVISOR_ROLE),
**general.get_members(db, MANAGER_ROLE)}

form = SQLFORM.factory(
Field('user_id', label=T('Supervisor/Manager'),
  requires=IS_IN_SET(rows_dic, zero=T('Choose one...'))),
Field('password', 'password', label=T('Password'), 
requires=IS_NOT_EMPTY()),
  buttons=[BUTTON(T('Submit'), _type='submit', _class='btn 
btn-primary')],
  formstyle='table3cols',
)
...
return dict(form=form)


it all works.


I even tried with just -> Dict to see if it was a problem with SQLFORM, but 
it returns the same message.


Windows 7 Pro x64 SP1+all updates
Firefox 65.0.2 x64
Python 3.7.1 x86
web2py 2.18.3

-- 
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] "NameError: name 'pydal' is not defined" when function has typing type in def

2019-03-08 Thread João Matos


If I write this function

@auth.requires(lambda: (auth.requires_login() and request.env.http_referer
and '/client' in request.env.http_referer))
def on_delete(table: pydal.objects.Table, rec_id: str):
"""Grid delete button action.

:param table: Table.
:param rec_id. Record id.
"""
if auth.has_membership(SUPERVISOR_ROLE) or 
auth.has_membership(MANAGER_ROLE):
row: pydal.objects.Row = table[rec_id]
row.update_record(cancel_approved_by=auth.user_id, 
canceled_by=auth.user_id,
  canceled_on=request.now, is_active=False)
session.flash = T('Press F5 to refresh.')
redirect(URL(user_signature=True))
else:
redirect(URL('get_approval', args=[rec_id], user_signature=True))


web2py/Python show this error

def on_delete(table: pydal.objects.Table, rec_id: str):
NameError: name 'pydal' is not defined


What is even stranger is that inside the same function there is this command
row: pydal.objects.Row = table[rec_id]
and web2py/Python don't show any error, which means they recognize pydal.


Windows 7 Pro x64 SP1+all updates
Firefox 65.0.2 x64
Python 3.7.1 x86
web2py 2.18.3

-- 
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: compiled files location

2019-03-08 Thread icodk
Thanks

On Friday, March 8, 2019 at 2:49:58 PM UTC+1, Anthony wrote:
>
> On Friday, March 8, 2019 at 4:55:02 AM UTC-5, icodk wrote:
>>
>> So if I understand it right, web2py caches  compiled application files 
>> and do it on the first demand or a source change and never write back to 
>> storage/disk. If so, Is there any advantage for compiled web2py 
>> application (except the one time load and compile after web server reset)?
>>
>
> For model files, as you suggest, aside from the initial load, I don't 
> think the compiled files offer an advantage. There is a small advantage for 
> controller files, as in the non-compiled case, web2py still parses the 
> (cached) non-compiled code to identify all the function names. The biggest 
> advantage of compiling is with the views, as web2py does not internally 
> cache compiled view code in memory.
>
> 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: compiled files location

2019-03-08 Thread Anthony
On Friday, March 8, 2019 at 4:55:02 AM UTC-5, icodk wrote:
>
> So if I understand it right, web2py caches  compiled application files and 
> do it on the first demand or a source change and never write back to 
> storage/disk. If so, Is there any advantage for compiled web2py 
> application (except the one time load and compile after web server reset)?
>

For model files, as you suggest, aside from the initial load, I don't think 
the compiled files offer an advantage. There is a small advantage for 
controller files, as in the non-compiled case, web2py still parses the 
(cached) non-compiled code to identify all the function names. The biggest 
advantage of compiling is with the views, as web2py does not internally 
cache compiled view code in memory.

Anthony

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


[web2py] Re: How to create a nested json dictionary by loading data from a flat, parent-referencing list?

2019-03-08 Thread Leonel Câmara
Use as_trees 

orgchart = db(db.your_table_which_records_have_parents).select().as_trees()

See as_trees documentation



 def as_trees(self, parent_name='parent_id', children_name='children',
 render=False):
"""
returns the data as list of trees.
:param parent_name: the name of the field holding the reference to 
the
parent (default parent_id).
:param children_name: the name where the children of each row will 
be
  stored as a list (default children).
:param render: whether we will render the fields using their 
represent
   (default False) can be a list of fields to render or
   True to render all.
"""

Then simply serialize the result into json

-- 
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: compiled files location

2019-03-08 Thread icodk
So if I understand it right, web2py caches  compiled application files and 
do it on the first demand or a source change and never write back to 
storage/disk. If so, Is there any advantage for compiled web2py 
application (except the one time load and compile after web server reset)?

On Friday, March 8, 2019 at 6:43:32 AM UTC+1, Massimo Di Pierro wrote:
>
>  the web2py files gluon/*.py are compiled as you would expect and are in 
> gluon/*.pyc but, unlike flask or django where the user code imports the 
> framework, in web2py it is the framework that executes the user code (this 
> allows running multiple apps under one web2py). When web2py executes the 
> models&controllers, it compiles them and caches the compiled versions in 
> memory. Because of this design, if a file changes, it recompiles them on 
> the fly even when running under nginx. 
> If your app imports any modules in site-packages or app/modules/ they 
> produce *.pyc files as you would expect.
>

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