py4wb simplification

273 views
Skip to first unread message

Massimo Di Pierro

unread,
Jan 31, 2020, 11:55:11 PM1/31/20
to web2py-users
I committed some new code to py4web

Now you can do:

from . common import authenticated, unauthenticated # from latest _scaffold

# exposes index as /{app_name}/index and uses index.html or generic.html template, auth.user, db, T, session
@authenticated()
def index():
      return dict()

# GET only
@authenticated.get()
def index():
      return dict()

# exposes /{app_name}/index/<a>/<b>/<c>
@authenticated.get()
def index(a,b,c):
      return dict()

# more explicit
@authenticated.get("index/<a:int>/<b:int>/<c:re:.*>)
def index(a,b,c):
      return dict()

Some magic

# define a button that make the following serverside POST callback
@unauthenticated.button("click me")
def a_button(msg):
    print("you clicked the button and server received:", msg)

# expose a page that displays the button which - onclick - makes the ballback
@unauthenticated.get()
def show_a_button():
    return dict(mybutton = a_button(msg="hello world"))

Thoughts? Should we keep this API? Can we improve it?









Kevin Keller

unread,
Feb 2, 2020, 6:43:40 AM2/2/20
to web2py-users
Hey,

Regarding the now code .

I think its awesome. 

Immediate question is though, how I could replace py4web build in auth with an outside IDM using OIDC/Oauth2? 
I understand since Py4web is so modular now, I can figure it out myself with 3rd party components. 
But I think it would be a common use case and it would be great to just be able to define an external auth server, client secret and id and secret in a json file and just use 
the build in py4web decorators no?

Apart from that, unrelated to this, just to confirm.. mtable is gone or is it still usable.. in scope going forward? 

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+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/9261e53e-d45b-4be1-82e8-2d19a488df78%40googlegroups.com.

Massimo Di Pierro

unread,
Feb 2, 2020, 11:55:58 PM2/2/20
to web2py-users
mtable is in scope and usable. Does not supprt yet fields of list:<something> type.

Do not have a simple answer about OIDC/Oauth2 but I will try do it and post findings. :-)
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe@googlegroups.com.

Kevin Keller

unread,
Feb 3, 2020, 2:32:55 AM2/3/20
to web2py-users
Happy to support with the oidc/oauth2.

Will share some code suggestions if that's ok with you

To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.

--
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+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/319c1f7d-7422-48e5-9cda-df141e2482e8%40googlegroups.com.

Massimo Di Pierro

unread,
Feb 10, 2020, 12:58:47 AM2/10/20
to web2py-users
Please do
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe@googlegroups.com.

--
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+unsubscribe@googlegroups.com.

Luca

unread,
Feb 13, 2020, 5:50:17 PM2/13/20
to web2py-users
What do @authenticated and @unauthenticated do?
Can they be added to the documentation?

In particular I don't understand

# define a button that make the following serverside POST callback
@unauthenticated.button("click me")
def a_button(msg):
    print("you clicked the button and server received:", msg)

Thanks!

Luca



Luca

Massimo Di Pierro

unread,
Feb 15, 2020, 6:27:02 AM2/15/20
to web2py-users
They they should be added

@autneticated and @unauthenticated are defined in common.py


The @unauthenticated  decorator automatically applys fixtures: db, auth, session, T. exposes the action with user /{function_name} and defaults to template {function_name}.html (very much like web2py does)

@authenticated is the same but requires login.

@authenticated.button("click me")
def f(a,b,c): print(a,b,c)

crate a button factory f which you can embed in code with [[=f(1,2,3)]] it generates a <button onclick="....">click me</button> than when clicked calls via ajax POST the function f defined in python and passes a=1, b=2, c=3.

Notice that this API is still work in progress. Works but it is not documented because we may change it.

Comments?

António Ramos

unread,
May 7, 2020, 7:27:00 AM5/7/20
to web...@googlegroups.com
With this callback can i have "powerfields" that automatically update themselves in the database ?
No need to submit forms..  

--
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+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/4951fa88-e18e-46e9-a1e0-95adcb52f179%40googlegroups.com.

Ben Lawrence

unread,
May 11, 2020, 11:25:32 AM5/11/20
to web2py-users
FYI automatic is on pypi now... https://pypi.org/project/Authomatic/


On Sunday, February 2, 2020 at 11:32:55 PM UTC-8, Kevin Keller wrote:
Happy to support with the oidc/oauth2.

Will share some code suggestions if that's ok with you

To unsubscribe from this group and stop receiving emails from it, send an email to web...@googlegroups.com.

--
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 web...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages