OLD | NEW |
(Empty) | |
| 1 # Copyright 2014 Google Inc. |
| 2 |
| 3 """Set up the rietveld2 webapp and register all HTTP request handlers. |
| 4 |
| 5 Rietveld2 uses the webapp2 framework. Each web page or group of related |
| 6 JSON request handlers is organized into a servlet class. |
| 7 """ |
| 8 |
| 9 import webapp2 |
| 10 from webapp2_extras import routes |
| 11 |
| 12 from v2 import api |
| 13 from v2 import servlet |
| 14 |
| 15 |
| 16 HTML_UI_ROUTES = [ |
| 17 # Top level pages |
| 18 webapp2.Route(r'/', servlet.EchoHTML, 'home-page'), |
| 19 webapp2.Route(r'/rawimage', servlet.RawExample), |
| 20 webapp2.Route(r'/mine', servlet.EchoHTML, 'my-issues-page'), |
| 21 webapp2.Route(r'/stared', servlet.EchoHTML, 'starred-issue-page'), |
| 22 webapp2.Route(r'/all', servlet.EchoHTML, 'all-issues-page'), |
| 23 webapp2.Route(r'/search', servlet.EchoHTML, 'issue-search-page'), |
| 24 |
| 25 # Issue detail pages |
| 26 routes.PathPrefixRoute(r'/<issue_id:\d+>', [ |
| 27 webapp2.Route(r'/', servlet.EchoHTML, 'issue-detail-page'), |
| 28 webapp2.Route(r'/patch/<patchset_id:\d+>/<patch_id:\d+>', |
| 29 servlet.EchoHTML, 'unified-diff-page'), |
| 30 webapp2.Route(r'/diff/<patchset_id:\d+>/<path:.+>', |
| 31 servlet.EchoHTML, 'side-by-side-diff'), |
| 32 # TODO(jrobbins): more handlers for edit, publish, delete, etc. |
| 33 ]), |
| 34 ] |
| 35 |
| 36 |
| 37 def route_nested_entities(spec, *path_handler_pairs): |
| 38 """Accumulate handlers along a longer and longer route spec.""" |
| 39 routes = [] |
| 40 for spec_part, handler in path_handler_pairs: |
| 41 spec += '/' + spec_part |
| 42 routes.append(webapp2.Route(spec, handler)) |
| 43 return routes |
| 44 |
| 45 |
| 46 API_ROUTES = ( |
| 47 # Issue -> Patchset -> Patch -> Comment |
| 48 route_nested_entities( |
| 49 '', |
| 50 ('Issue', api.IssueCollectionJSON), |
| 51 ('<issue_id:\d+>', api.IssueJSON), |
| 52 ('Patchset', api.PatchCollectionJSON), |
| 53 ('<ps_id:\d+>', api.PatchsetJSON), |
| 54 ('Patch', api.PatchCollectionJSON), |
| 55 ('<patch_id:\d+>', api.PatchJSON), |
| 56 ('Comment', api.CommentCollectionJSON), |
| 57 ('<comment_id:\d+>', api.CommentJSON)) + |
| 58 # Issue -> Message |
| 59 route_nested_entities( |
| 60 '/Issue/<issue_id:\d+>', |
| 61 ('Message', api.MessageCollectionJSON), |
| 62 ('<message_id:\d+>', api.MessageJSON)) |
| 63 ) |
| 64 |
| 65 |
| 66 ROUTES = [ |
| 67 routes.PathPrefixRoute(r'/v2', HTML_UI_ROUTES), |
| 68 routes.PathPrefixRoute(r'/v2/api', API_ROUTES), |
| 69 ] |
OLD | NEW |