showard | 26b7ec7 | 2009-12-21 22:43:57 +0000 | [diff] [blame] | 1 | import os |
Aviv Keshet | 0a0029f | 2017-04-17 12:51:39 -0700 | [diff] [blame] | 2 | from django.conf import urls |
Justin Giorgi | 971b324 | 2016-07-20 15:44:21 -0700 | [diff] [blame] | 3 | from django.views import generic |
showard | 26b7ec7 | 2009-12-21 22:43:57 +0000 | [diff] [blame] | 4 | |
| 5 | |
showard | f713072 | 2009-12-23 00:06:16 +0000 | [diff] [blame] | 6 | def generate_patterns(django_name, gwt_name): |
showard | 26b7ec7 | 2009-12-21 22:43:57 +0000 | [diff] [blame] | 7 | """ |
| 8 | Generates the common URL patterns for the given names |
| 9 | |
| 10 | @param django_name the full name of the Django application |
| 11 | (e.g., frontend.afe) |
| 12 | @param gwt_name the name of the GWT project (e.g., AfeClient) |
| 13 | @return the common standard and the debug pattern lists, as a tuple |
| 14 | """ |
| 15 | |
Aviv Keshet | 0a0029f | 2017-04-17 12:51:39 -0700 | [diff] [blame] | 16 | pattern_list = urls.patterns( |
showard | f713072 | 2009-12-23 00:06:16 +0000 | [diff] [blame] | 17 | django_name, |
Scott Zawalski | 347aaf4 | 2012-04-03 16:33:00 -0400 | [diff] [blame] | 18 | (r'^(?:|noauth/)rpc/', 'views.handle_rpc'), |
showard | f713072 | 2009-12-23 00:06:16 +0000 | [diff] [blame] | 19 | (r'^rpc_doc', 'views.rpc_documentation'), |
| 20 | ) |
showard | 26b7ec7 | 2009-12-21 22:43:57 +0000 | [diff] [blame] | 21 | |
Aviv Keshet | 0a0029f | 2017-04-17 12:51:39 -0700 | [diff] [blame] | 22 | debug_pattern_list = urls.patterns('', |
showard | 26b7ec7 | 2009-12-21 22:43:57 +0000 | [diff] [blame] | 23 | # for GWT hosted mode |
| 24 | (r'^(?P<forward_addr>autotest.*)', |
| 25 | 'autotest_lib.frontend.afe.views.gwt_forward'), |
| 26 | |
| 27 | # for GWT compiled files |
| 28 | (r'^client/(?P<path>.*)$', 'django.views.static.serve', |
| 29 | {'document_root': os.path.join(os.path.dirname(__file__), '..', |
| 30 | 'frontend', 'client', 'www')}), |
| 31 | # redirect / to compiled client |
Justin Giorgi | 971b324 | 2016-07-20 15:44:21 -0700 | [diff] [blame] | 32 | (r'^$', generic.RedirectView.as_view( |
| 33 | url='client/autotest.%(name)s/%(name)s.html' |
| 34 | % dict(name=gwt_name))), |
showard | f713072 | 2009-12-23 00:06:16 +0000 | [diff] [blame] | 35 | ) |
showard | 26b7ec7 | 2009-12-21 22:43:57 +0000 | [diff] [blame] | 36 | |
| 37 | return (pattern_list, debug_pattern_list) |