PageRenderTime 104ms CodeModel.GetById 40ms app.highlight 23ms RepoModel.GetById 38ms app.codeStats 0ms

/kai/config/routing.py

https://bitbucket.org/bbangert/kai/
Python | 128 lines | 84 code | 22 blank | 22 comment | 3 complexity | b73924d0476d9d3b93ab9ddaf2e1d27a MD5 | raw file
  1"""Routes configuration
  2
  3The more specific and detailed routes should be defined first so they
  4may take precedent over the more generic routes. For more information
  5refer to the routes manual at http://routes.groovie.org/docs/
  6"""
  7from routes import Mapper
  8
  9wiki = 'http://wiki.pylonshq.com'
 10
 11def article_expand(kwargs):
 12    if 'article' not in kwargs:
 13        return kwargs
 14    article = kwargs.pop('article')
 15    kwargs['year'] = article.published.year
 16    kwargs['month'] = article.published.month
 17    kwargs['slug'] = article.slug
 18    return kwargs
 19
 20
 21def make_map(config):
 22    """Create, configure and return the routes Mapper"""
 23    version = config['pylons.app_globals'].current_version
 24    globs = config['pylons.app_globals']
 25    static_host = config['cdn.uri']
 26
 27    map = Mapper(directory=config['pylons.paths']['controllers'],
 28                 always_scan=config['debug'])
 29    map.minimization = False
 30    
 31    # The ErrorController route (handles 404/500 error pages); it should
 32    # likely stay at the top, ensuring it can always be resolved
 33    map.connect('/error/{action}', controller='error')
 34    map.connect('/error/{action}/{id}', controller='error')
 35    
 36    # Toppcloud sync
 37    map.connect('/sync_app', controller='home', action='sync')
 38    
 39    # Home url's
 40    map.connect('home', '/', controller='home', action='index')
 41    map.connect('/robots.txt', controller='home', action='robots')
 42    map.connect('features', '/features', controller='home', action='features')
 43    map.connect('history', '/history', controller='home', action='history')
 44    map.connect('search', '/search', controller='home', action='search')
 45    map.connect('community', '/community', controller='home', action='community')
 46    
 47    # Blog url's
 48    map.connect('article_archives', '/articles/archives/{year:\d+}/{month:\d+}/{slug}',
 49                controller='articles', action='archives', _filter=article_expand)
 50    map.resource('article', 'articles')
 51    
 52    # Code url's
 53    # map.connect('buildbot', '/buildbot/{action}', controller='buildbot')
 54    
 55    # Doc url's
 56    map.connect('doc_upload', '/docs/upload', controller='docs', action='upload')
 57    map.connect('doc_upload_image', '/docs/upload_image', controller='docs', action='upload_image')
 58    map.connect('doc_delete', '/docs/delete_revision/{project}/{version}', controller='docs', action='delete_revision')
 59    map.redirect('/docs/{version}', '/docs/en/{version}/')
 60    map.connect('doc_home', '/docs/{language}/{version}/', controller='docs', action='view', url='index', language='en',
 61                version=globs.doc_version)
 62    map.connect('doc_view', '/docs/{language}/{version}/{url:.*}', controller='docs', action='view', language='en', 
 63                version=globs.doc_version)
 64    
 65    map.connect('wiki', 'http://wiki.pylonshq.com/', _static=True)
 66    map.connect('download', '/download/{version}', controller='download',
 67                action='index', version=globs.doc_version)
 68    map.connect('download', '/download/{version}/*file', controller='download',
 69                action='index', version=globs.doc_version)
 70
 71    map.connect('/download', controller='download', action='index', version=globs.current_version)
 72    map.connect('/download/', controller='download', action='index', version=globs.current_version)
 73    map.connect('cdocs', '%s/display/pylonsdocs/{page}' % wiki, _static=True)
 74    
 75    # Accounts
 76    map.connect('account_login', '/accounts/login', controller='accounts', action='login')
 77    map.connect('account_login', '/accounts/login', controller='accounts', action='login')
 78    map.connect('account_register', '/accounts/register', controller='accounts', action='register')
 79    map.connect('account_logout', '/accounts/logout', controller='accounts', action='logout')
 80    map.connect('verify_email', '/accounts/verify_email/{token}', controller='accounts', action='verify_email')
 81    map.connect('forgot_password', '/accounts/forgot_password', controller='accounts', action='forgot_password')
 82    map.connect('reset_password', '/accounts/reset_password/{token}', controller='accounts', action='change_password')
 83    
 84    # OpenID URL's
 85    map.connect('openid_associate', '/accounts/openid/associate', controller='accounts', action='openid_associate')
 86    map.connect('openid_register', '/accounts/openid/register', controller='accounts', action='openid_register')
 87    map.connect('openid_login', '/accounts/openid/login', controller='consumer', action='login')
 88    map.connect('openid_process', '/accounts/openid/process', controller='consumer', action='process')
 89    map.connect('openid_create', '/accounts/openid/create', controller='consumer', action='create')
 90    
 91    # Snippets
 92    map.connect('preview_snippet', '/snippets/preview', controller='snippets', action='preview', conditions=dict(method='POST'))
 93    map.connect('snippet_author', '/snippets/by_author/{id}', controller='snippets', action='by_author')
 94    map.connect('snippet_tag', '/snippets/by_tag/{tag}', controller='snippets', action='by_tag')
 95    map.connect('snippet_tagcloud', '/snippets/tagcloud', controller='snippets', action='tagcloud')
 96    map.resource('snippet', 'snippets', collection={'preview':'POST'})
 97    
 98    # Pastebin
 99    map.connect('pasties_tagcloud', '/pasties/tagcloud', controller='pasties', action='tagcloud')
100    map.connect('formatted_pasties_tag', '/pasties/by_tag/{tag}.{format:(atom|rss)}', controller='pasties', action='index')
101    map.redirect('/pastetags/{tag}', '/pasties/by_tag/{tag}')
102    map.connect('pasties_tag', '/pasties/by_tag/{tag}', controller='pasties', action='index')
103    map.connect('pasties_author', '/pasties/by_author/{author}', controller='pasties', action='by_author')
104    map.resource('paste', 'pasties', member={'download':'GET'})
105
106    # Resources
107    map.resource('traceback', 'tracebacks', member={'reown':'GET'})
108    
109    # Comments
110    map.connect('preview_comment', '/comment/preview', controller='comments', action='preview', conditions=dict(method='POST'))
111    map.connect('post_comment', '/comment/{doc_id}', controller='comments', action='create', conditions=dict(method='POST'))
112    map.connect('delete_comment', '/comment/{id}', controller='comments', action='delete', conditions=dict(method='DELETE'))
113    map.resource('comment', 'comments')
114    
115    # External Links
116    map.connect('sqlalchemy', 'http://sqlalchemy.org/', _static=True)
117    map.connect('sqlobject', 'http://www.sqlobject.org/', _static=True)
118    map.connect('python-couchdb', 'http://code.google.com/p/couchdb-python/', _static=True)
119    map.connect('formalchemy', 'http://code.google.com/p/formalchemy/', _static=True)
120    map.connect('mako', 'http://www.makotemplates.org/', _static=True)
121    map.connect('genshi', 'http://genshi.edgewall.org/', _static=True)
122    map.connect('jinja2', 'http://jinja.pocoo.org/', _static=True)
123    map.connect('pylons_book', 'http://pylonsbook.com/', _static=True)
124
125    map.connect('/{controller}/{action}')
126    map.connect('/{controller}/{action}/{id}')
127
128    return map