El Wed, Jun 22, 2011 at 10:22:01AM +0200, Sergio Talens-Oliag va escriure:
> El Tue, Jun 21, 2011 at 05:44:47PM -0700, Anthony va escriure:
> > Another option might be to leave the name 'admin' and use routes.py to
> > rewrite incoming and outgoing URLs to 'admin' using a different name.
>
> But for that to work all links to /admin should be generated using the URL
> function, don't they?
>
> If that is the case I guess the only change needed would be the definition of
> 'p.error_message_ticket' on the '_params_default' function included on the
> 'gluon/rewrite.py' that will need to be redefined to get the right URL on the
> error messages (a quick review shows that all the other modified files
> generate the admin references using the URL function).
>
> I'll try it now and will send a patch if it works.
It does, here is what I've done:
1. I've reverted all the changes on the applications files
2. On my 'routes.py' I've added the following:
# Move the admin application to web2py_admin
routes_in = (
(r'/web2py_admin', r'/admin'),
(r'/web2py_admin/(?P<any>.*)', r'/admin/\g<any>'),
)
routes_out = (
(r'/admin', r'/web2py_admin'),
(r'/admin/(?P<any>.*)', r'/web2py_admin/\g<any>'),
)
3. I've modified the 'web2py/gluon/rewrite.py' with the attached patch to
apply the 'routes.py' to the 'thread.routes.error_message_ticket' setting.
I do it on the 'load' function because I wanted to call 'url_out' function
and doing it on the '_params_default' needed a lot of changes to the code
and it is unnecesary in many cases (in fact with the attached patch if
there is no global 'routes.py' file the 'url_out' function is never called
from the 'load' function).
I don't know if the patch is appropiate for inclusion on web2py, but at least
it does not break old installations and makes things work as expected for a
new user.
Greetings,
Sergio.
--
Sergio Talens-Oliag <[email protected]> <http://www.iti.upv.es/>
Key fingerprint = FF77 A16B 9D09 FC7B 6656 CFAD 261D E19A 578A 36F2
--- web2py.orig/gluon/rewrite.py 2011-06-07 22:07:48.000000000 +0200
+++ web2py/gluon/rewrite.py 2011-06-22 12:04:46.677987688 +0200
@@ -66,6 +66,10 @@
p.routes_apps_raw = []
p.error_handler = None
p.error_message = '<html><body><h1>%s</h1></body></html>'
+ # Note:
+ # p.error_message_ticket gets rewriten on the load function if there is
+ # a routes.py file on the server. Any change here it has to be applied
+ # on the other function too
p.error_message_ticket = \
'<html><body><h1>Internal error</h1>Ticket issued: <a href="/admin/default/ticket/%(ticket)s" target="_blank">%(ticket)s</a></body><!-- this is junk text else IE does not display the page: '+('x'*512)+' //--></html>'
p.routers = None
@@ -255,6 +259,26 @@
if os.path.exists(abspath('applications', appname, routes)):
load(routes, appname)
+ # Process the thread.routes.error_message_ticket with the loaded
+ # routes.py, just in case it gets rewritten on them
+ thread.routes.error_message_ticket = \
+ '<html><body><h1>Internal error</h1>Ticket issued: <a href="' \
+ + url_out(
+ request = None,
+ env = None,
+ application = 'admin',
+ controller = 'default',
+ function = 'ticket',
+ args = None,
+ other = '/%(ticket)s',
+ scheme = None,
+ host = None,
+ port = None
+ ) + '" target="_blank">%(ticket)s</a></body>' \
+ + '<!-- this is junk text else IE does not display the page: ' \
+ + ('x'*512) \
+ + ' //--></html>'
+
if routers:
load_routers(all_apps)