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?
On Thursday, 13 February 2020 14:50:17 UTC-8, Luca wrote:
>
> 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
>
> On Friday, January 31, 2020 at 8:55:11 PM UTC-8, Massimo Di Pierro wrote:
>>
>> 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?
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/web2py/4951fa88-e18e-46e9-a1e0-95adcb52f179%40googlegroups.com.