[web2py] Re: how to rewrite an URL to drop a function name showing in the address bar

2017-08-27 Thread 98ujko9
I chose pattern-based  rewrite because I don't know better. Please know 
that I am only temporary part time web coder relying on web2py book 100% 
with understanding at about 60%. Being a mature person I am fond of 
eloquence in life as well as in URL's however complexity has its price. I 
sense from what you are  saying I should stick with parametric router or 
leave it alone and keep the "asset" function where it naturally is .  A 
quick sketch of what I am having fun with:



Thanks in advance.

On Sunday, August 27, 2017 at 7:55:27 PM UTC-4, Anthony wrote:
>
> Got it. Next, provide more detail regarding your current code/setup. Is 
> there any particular reason you need to be using the pattern-based rewrite 
> system? If so, you'll just need to create a regex that matches the route in 
> question, or create a regex that matches all the other possible functions 
> in the controller and create a fallback route *after* that to direct to 
> the "asset" function.
>
> Anthony
>
> On Sunday, August 27, 2017 at 1:33:09 PM UTC-4, 98u...@gmail.com 
>  wrote:
>>
>> I could make "asset" function the default for the "showcase" controller 
>> however I am not sure how as I am already using renamed 
>> routes.patterns.example.py (the book recommends not to mix pattern and 
>> parameter routing methods) in the root of the website (multiple apps in my 
>> case) to rewrite one URL (works nicely):
>>
>> routes_out = (
>> ('/stock/default/index',BASE + '/stock'),# <== my addition
>> # do not reroute admin unless you want to disable it
>> ('/admin/$anything', BASE + '/admin/$anything'),
>> # do not reroute appadmin unless you want to disable it
>> ('/$app/appadmin/$anything', BASE + '/$app/appadmin/$anything'),
>> # do not reroute static files
>> ('/$app/static/$anything', BASE + '/$app/static/$anything'),
>> # do other stuff
>> (r'.*http://otherdomain\.com.* /app/ctr(?P.*)', r'\g'),
>> (r'/app(?P.*)', r'\g'),
>> # restore the BASE prefix
>> ('/$anything', BASE + '/$anything'),
>> )
>>
>> Thanks in advance for any assistance
>>
>>
>> On Sunday, August 27, 2017 at 12:17:16 PM UTC-4, Anthony wrote:
>>>
>>> On Saturday, August 26, 2017 at 4:05:59 PM UTC-4, 98u...@gmail.com 
>>> wrote:

 How can I rewrite the URL (to drop asset):

 https://192.168.1.25:8000/stock/showcase/asset/2017-Some-fridge?id=79&_signature=c2e7899530c858f1b478cb7ea5f03bb30d4f68e1
 to look like:

 https://192.168.1.25:8000/stock/showcase/2017-Some-fridge?id=79&_signature=c2e7899530c858f1b478cb7ea5f03bb30d4f68e1
 the app 'stock' ins't default
 the controllert 'showcase' isn't default
 the function 'asset' isn't default

>>>
>>> Do you use another function as the default within the "showcase" 
>>> controller? If not, you can define "asset" as the default function just for 
>>> the "showcase" controller using the parameter-based router. Alternatively, 
>>> you can use the default function to handle the above routes by checking for 
>>> a URL arg and returning the appropriate response. For example, if the 
>>> default function is "index":
>>>
>>> def index():
>>> if not request.args:
>>> [code currently in the "index" function]
>>> else:
>>> [code currently in the "asset" function]
>>>
>>> Finally, you could use the pattern-based rewrite system, though that can 
>>> start to get complex.
>>>
>>> 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: web2py 2.15.3 is OUT

2017-08-27 Thread Anthony
It's not clear how that would be related to response.js, as it appears the 
code returned via response.js is in fact being executed in the browser. 
It's hard to say what's going wrong in the browser without knowing more 
about the JS and what the DOM looks like at that point.

Anthony

On Sunday, August 27, 2017 at 8:16:19 PM UTC-4, 黄祥 wrote:
>
> it seems response.js have a different behaviour in new version
> e.g. (the same code work well in 2.14.6)
> ...
> if form.process().accepted:
> ...
> target_response = "jQuery('#test .close').click(); 
> jQuery('#test').get(0).reload()"
> response.js =  target_response
> #redirect(request.env.http_web2py_component_location, client_side = 
> True)
>
> in 2.14.6, after the form submited it automatically reload the web2py 
> component and the page still responding, while in the latest version the 
> modal is closed, the component data is reload with new value but the page 
> is not responding, just have the dark silouette of the page, the solution 
> is must refresh the page or append :
> redirect(request.env.http_web2py_component_location, client_side = True)
> is it normal or did i missed something in the latest version ?
>
> thanks and 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] Re: web2py 2.15.3 is OUT

2017-08-27 Thread 黄祥
it seems response.js have a different behaviour in new version
e.g. (the same code work well in 2.14.6)
...
if form.process().accepted:
...
target_response = "jQuery('#test .close').click(); 
jQuery('#test').get(0).reload()"
response.js =  target_response
#redirect(request.env.http_web2py_component_location, client_side = 
True)

in 2.14.6, after the form submited it automatically reload the web2py 
component and the page still responding, while in the latest version the 
modal is closed, the component data is reload with new value but the page 
is not responding, just have the dark silouette of the page, the solution 
is must refresh the page or append :
redirect(request.env.http_web2py_component_location, client_side = True)
is it normal or did i missed something in the latest version ?

thanks and 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] Re: how to rewrite an URL to drop a function name showing in the address bar

2017-08-27 Thread Anthony
Got it. Next, provide more detail regarding your current code/setup. Is 
there any particular reason you need to be using the pattern-based rewrite 
system? If so, you'll just need to create a regex that matches the route in 
question, or create a regex that matches all the other possible functions 
in the controller and create a fallback route *after* that to direct to the 
"asset" function.

Anthony

On Sunday, August 27, 2017 at 1:33:09 PM UTC-4, 98uj...@gmail.com wrote:
>
> I could make "asset" function the default for the "showcase" controller 
> however I am not sure how as I am already using renamed 
> routes.patterns.example.py (the book recommends not to mix pattern and 
> parameter routing methods) in the root of the website (multiple apps in my 
> case) to rewrite one URL (works nicely):
>
> routes_out = (
> ('/stock/default/index',BASE + '/stock'),# <== my addition
> # do not reroute admin unless you want to disable it
> ('/admin/$anything', BASE + '/admin/$anything'),
> # do not reroute appadmin unless you want to disable it
> ('/$app/appadmin/$anything', BASE + '/$app/appadmin/$anything'),
> # do not reroute static files
> ('/$app/static/$anything', BASE + '/$app/static/$anything'),
> # do other stuff
> (r'.*http://otherdomain\.com.* /app/ctr(?P.*)', r'\g'),
> (r'/app(?P.*)', r'\g'),
> # restore the BASE prefix
> ('/$anything', BASE + '/$anything'),
> )
>
> Thanks in advance for any assistance
>
>
> On Sunday, August 27, 2017 at 12:17:16 PM UTC-4, Anthony wrote:
>>
>> On Saturday, August 26, 2017 at 4:05:59 PM UTC-4, 98u...@gmail.com wrote:
>>>
>>> How can I rewrite the URL (to drop asset):
>>>
>>> https://192.168.1.25:8000/stock/showcase/asset/2017-Some-fridge?id=79&_signature=c2e7899530c858f1b478cb7ea5f03bb30d4f68e1
>>> to look like:
>>>
>>> https://192.168.1.25:8000/stock/showcase/2017-Some-fridge?id=79&_signature=c2e7899530c858f1b478cb7ea5f03bb30d4f68e1
>>> the app 'stock' ins't default
>>> the controllert 'showcase' isn't default
>>> the function 'asset' isn't default
>>>
>>
>> Do you use another function as the default within the "showcase" 
>> controller? If not, you can define "asset" as the default function just for 
>> the "showcase" controller using the parameter-based router. Alternatively, 
>> you can use the default function to handle the above routes by checking for 
>> a URL arg and returning the appropriate response. For example, if the 
>> default function is "index":
>>
>> def index():
>> if not request.args:
>> [code currently in the "index" function]
>> else:
>> [code currently in the "asset" function]
>>
>> Finally, you could use the pattern-based rewrite system, though that can 
>> start to get complex.
>>
>> 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: Is it posible to fallback to static files when a controller is not found?

2017-08-27 Thread Alfonso Serra
Simpler and better approach:

routes_in = (
# do not reroute admin unless you want to disable it
(BASE + '/admin', '/admin/default/index')
, (BASE + '/admin/$anything', '/admin/$anything')
# do not reroute appadmin unless you want to disable it
, (BASE + '/$app/appadmin', '/$app/appadmin/index')
, (BASE + '/$app/appadmin/$anything', '/$app/appadmin/$anything')

# default controller
, ('/', '/%s/default/index' % default_application)
, ('/$c', '/%s/$c/index' % default_application)
, ('/$c/$f', '/%s/$c/$f' % default_application)
, ('/$anything', '/%s/static/$anything' % default_application)
, (BASE + '/$anything', '/$anything')
]

routes_out = (
# do not reroute admin unless you want to disable it
('/admin/$anything', BASE + '/admin/$anything')
# do not reroute appadmin unless you want to disable it
, ('/$app/appadmin/$anything', BASE + '/$app/appadmin/$anything')
)

Works well, I have to put aside web2py default autoroutes but this is what 
i wanted.

I still dont quite get routes_out, when a route is coming from the app? 
only on redirections? 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: Is it posible to fallback to static files when a controller is not found?

2017-08-27 Thread Alfonso Serra
Think i got it:

routes.py:
routes_onerror = [
# (r'init/400', r'/init/default/login')
# ,(r'init/*', r'/init/static/fail.html')
# ,(r'*/404', r'/init/static/cantfind.html')
('*/*', '/myapp/default/handle_error')
]

In app/default.py

def handle_error():
code = request.vars.code
url = request.vars.request_url
uri = request.vars.requested_uri
ticket = request.vars.ticket
if uri:
redirect("/myapp/static" + uri)
return "Error"

This way we can set static files as they were in the root directory, no 
need to prefix with /static.
I have to polish this to implement 404's or 500's but would be a start. 

Any other suggestions are welcome.
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: how to rewrite an URL to drop a function name showing in the address bar

2017-08-27 Thread 98ujko9
I could make "asset" function the default for the "showcase" controller 
however I am not sure how as I am already using renamed 
routes.patterns.example.py in the root of the website (multiple apps) to 
rewrite one URL (works nicely):

routes_out = (
('/stock/default/index','/stock'),# <== my addition
# do not reroute admin unless you want to disable it
('/admin/$anything', BASE + '/admin/$anything'),
# do not reroute appadmin unless you want to disable it
('/$app/appadmin/$anything', BASE + '/$app/appadmin/$anything'),
# do not reroute static files
('/$app/static/$anything', BASE + '/$app/static/$anything'),
# do other stuff
(r'.*http://otherdomain\.com.* /app/ctr(?P.*)', r'\g'),
(r'/app(?P.*)', r'\g'),
# restore the BASE prefix
('/$anything', BASE + '/$anything'),
)

Thanks in advance for any assistance


On Sunday, August 27, 2017 at 12:17:16 PM UTC-4, Anthony wrote:
>
> On Saturday, August 26, 2017 at 4:05:59 PM UTC-4, 98u...@gmail.com 
>  wrote:
>>
>> How can I rewrite the URL (to drop asset):
>>
>> https://192.168.1.25:8000/stock/showcase/asset/2017-Some-fridge?id=79&_signature=c2e7899530c858f1b478cb7ea5f03bb30d4f68e1
>> to look like:
>>
>> https://192.168.1.25:8000/stock/showcase/2017-Some-fridge?id=79&_signature=c2e7899530c858f1b478cb7ea5f03bb30d4f68e1
>> the app 'stock' ins't default
>> the controllert 'showcase' isn't default
>> the function 'asset' isn't default
>>
>
> Do you use another function as the default within the "showcase" 
> controller? If not, you can define "asset" as the default function just for 
> the "showcase" controller using the parameter-based router. Alternatively, 
> you can use the default function to handle the above routes by checking for 
> a URL arg and returning the appropriate response. For example, if the 
> default function is "index":
>
> def index():
> if not request.args:
> [code currently in the "index" function]
> else:
> [code currently in the "asset" function]
>
> Finally, you could use the pattern-based rewrite system, though that can 
> start to get complex.
>
> 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 rewrite an URL to drop a function name showing in the address bar

2017-08-27 Thread Anthony
On Saturday, August 26, 2017 at 4:05:59 PM UTC-4, 98uj...@gmail.com wrote:
>
> How can I rewrite the URL (to drop asset):
>
> https://192.168.1.25:8000/stock/showcase/asset/2017-Some-fridge?id=79&_signature=c2e7899530c858f1b478cb7ea5f03bb30d4f68e1
> to look like:
>
> https://192.168.1.25:8000/stock/showcase/2017-Some-fridge?id=79&_signature=c2e7899530c858f1b478cb7ea5f03bb30d4f68e1
> the app 'stock' ins't default
> the controllert 'showcase' isn't default
> the function 'asset' isn't default
>

Do you use another function as the default within the "showcase" 
controller? If not, you can define "asset" as the default function just for 
the "showcase" controller using the parameter-based router. Alternatively, 
you can use the default function to handle the above routes by checking for 
a URL arg and returning the appropriate response. For example, if the 
default function is "index":

def index():
if not request.args:
[code currently in the "index" function]
else:
[code currently in the "asset" function]

Finally, you could use the pattern-based rewrite system, though that can 
start to get complex.

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: change_password validator

2017-08-27 Thread Anthony
First, the default validator is not IS_STRONG -- it is simply CRYPT with 
min_length set to auth.settings.password_min_length (which defaults to 4).

Second, on the password change form, the validator is not ignored, but the 
min_length of CRYPT is set to 1 for the "Old Password" field only (this is 
not a problem, because the only validation that matters for the old 
password is that it matches the password stored in the database). The "New 
Password" field is validated with whatever validators have been defined for 
the password field.

Anthony

On Friday, August 18, 2017 at 9:09:56 AM UTC-4, tomasz bandura wrote:
>
> Hello,
>
> For the user registration I use just default validator (IS_STRONG) which 
> has defined only minimum lenght (4).
>
> The problem is during password changing (form=auth() --> 
> default/user/change_password) - validator is ignored and I can set password 
> with length=1
>
>  Should I set a validator separately?
>
> There is also parameter 'auth.settings.change_password_onvalidation' but 
> it hasn't any impact on changing pass action.
>
>
> Regards,
> Tomasz
>

-- 
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: change_password validator

2017-08-27 Thread Alfonso Serra
I was able to setup IS_STRONG like this:

db.auth_user.password.requires.insert(0, IS_STRONG())

Be careful, after doing this users wont be able to log in if their password 
is not strong, validated.

-- 
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] Is it posible to fallback to static files when a controller is not found?

2017-08-27 Thread Alfonso Serra
im trying to fallback to the static folder when a controller is not found, 
for example:
a route like:


img is not a defined controller so i would like to redirect this route to 
"/static/img/mypicture.png", how do i do that?

I have tried:

BASE = ''  # optonal prefix for incoming URLs
fixed_routes = [
 # do not reroute admin unless you want to disable it
(BASE + '/admin', '/admin/default/index')
, (BASE + '/admin/$anything', '/admin/$anything')
# do not reroute appadmin unless you want to disable it
, (BASE + '/%s/appadmin' % default_application, '/%s/appadmin/index' % 
default_application)
, (BASE + '/%s/appadmin/$anything' % default_application, 
'/%s/appadmin/$anything' % default_application)
]

# for some reason using the variable $app raises a server error. 
IndexError: unknown group name: 'app'
routes_in = fixed_routes + [
('/', '/%s/default/index' % default_application)
, ('/$c', '/%s/$c/index' % default_application)
, ('/$c/$anything', '/%s/$c/index/$anything' % default_application)
, ('/$anything', '%s/static/$anything' % default_application)
]

routes_out = [(x[1], x[0]) for x in routes_in]

but does not look like $c cares about the string is a controller or not so 
'/$anything' rerouting to the static folder never triggers.

Shall i try routes on error? Any tips on how to do that?
What kind of response is sent when a static file is not found?

Thanks in advance.

-- 
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 rewrite an URL to drop a function name showing in the address bar

2017-08-27 Thread Alfonso Serra
A solution would be to use routes.py
in there you can place something like
routes_in = [
 ('/stock/showcase/$anything', '/stock/showcase/index/$anything')
]
and use the index function to do whatever you like with the view.
You redirect everything through the index function so you wont be able to 
use another ones, like assets maybe. It all depends on how do you want to 
structure your app routes.


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