1import os
2from django.conf.urls import defaults
3
4
5def generate_patterns(django_name, gwt_name):
6    """
7    Generates the common URL patterns for the given names
8
9    @param django_name the full name of the Django application
10                       (e.g., frontend.afe)
11    @param gwt_name the name of the GWT project (e.g., AfeClient)
12    @return the common standard and the debug pattern lists, as a tuple
13    """
14
15    pattern_list = defaults.patterns(
16            django_name,
17            (r'^(?:|noauth/)rpc/', 'views.handle_rpc'),
18            (r'^rpc_doc', 'views.rpc_documentation'),
19        )
20
21    debug_pattern_list = defaults.patterns('',
22            # for GWT hosted mode
23            (r'^(?P<forward_addr>autotest.*)',
24             'autotest_lib.frontend.afe.views.gwt_forward'),
25
26            # for GWT compiled files
27            (r'^client/(?P<path>.*)$', 'django.views.static.serve',
28             {'document_root': os.path.join(os.path.dirname(__file__), '..',
29                                            'frontend', 'client', 'www')}),
30            # redirect / to compiled client
31            (r'^$', 'django.views.generic.simple.redirect_to',
32             {'url':
33              'client/autotest.%(name)s/%(name)s.html' % dict(name=gwt_name)}),
34        )
35
36    return (pattern_list, debug_pattern_list)
37