| 1 | # -*- coding: utf-8 -*- |
|---|
| 2 | """ |
|---|
| 3 | zine.urls |
|---|
| 4 | ~~~~~~~~~ |
|---|
| 5 | |
|---|
| 6 | This module implements a function that creates a list of urls for all |
|---|
| 7 | the core components. |
|---|
| 8 | |
|---|
| 9 | :copyright: (c) 2010 by the Zine Team, see AUTHORS for more details. |
|---|
| 10 | :license: BSD, see LICENSE for more details. |
|---|
| 11 | """ |
|---|
| 12 | from werkzeug.routing import Rule, Submount |
|---|
| 13 | |
|---|
| 14 | def make_urls(app): |
|---|
| 15 | """Make the URLs for a new zine application.""" |
|---|
| 16 | blog_urls = [ |
|---|
| 17 | Rule('/', defaults={'page': 1}, endpoint='blog/index'), |
|---|
| 18 | Rule('/feed.atom', endpoint='blog/atom_feed'), |
|---|
| 19 | Submount('/feed', [ |
|---|
| 20 | Rule('/', endpoint='blog/rss_feed'), |
|---|
| 21 | Rule('/rss', endpoint='blog/rss_feed'), |
|---|
| 22 | Rule('/rss2', endpoint='blog/rss_feed'), |
|---|
| 23 | Rule('/atom', endpoint='blog/atom_feed'), |
|---|
| 24 | ]), |
|---|
| 25 | Rule('/page/<int:page>', endpoint='blog/index'), |
|---|
| 26 | Rule('/archive', endpoint='blog/archive'), |
|---|
| 27 | Submount(app.cfg['profiles_url_prefix'], [ |
|---|
| 28 | Rule('/', endpoint='blog/authors'), |
|---|
| 29 | Rule('/<string:username>', defaults={'page': 1}, endpoint='blog/show_author'), |
|---|
| 30 | Rule('/<string:username>/page/<int:page>', endpoint='blog/show_author'), |
|---|
| 31 | Rule('/<string:author>/feed.atom', endpoint='blog/atom_feed'), |
|---|
| 32 | Submount('/<string:author>/feed', [ |
|---|
| 33 | Rule('/', endpoint='blog/rss_feed'), |
|---|
| 34 | Rule('/rss', endpoint='blog/rss_feed'), |
|---|
| 35 | Rule('/rss2', endpoint='blog/rss_feed'), |
|---|
| 36 | Rule('/atom', endpoint='blog/atom_feed'), |
|---|
| 37 | ]), |
|---|
| 38 | ]), |
|---|
| 39 | Submount(app.cfg['category_url_prefix'], [ |
|---|
| 40 | Rule('/<string:slug>', defaults={'page': 1}, endpoint='blog/show_category'), |
|---|
| 41 | Rule('/<string:slug>/page/<int:page>', endpoint='blog/show_category'), |
|---|
| 42 | Rule('/<string:category>/feed.atom', endpoint='blog/atom_feed'), |
|---|
| 43 | Submount('/<string:category>/feed', [ |
|---|
| 44 | Rule('/', endpoint='blog/rss_feed'), |
|---|
| 45 | Rule('/rss', endpoint='blog/rss_feed'), |
|---|
| 46 | Rule('/rss2', endpoint='blog/rss_feed'), |
|---|
| 47 | Rule('/atom', endpoint='blog/atom_feed'), |
|---|
| 48 | ]), |
|---|
| 49 | ]), |
|---|
| 50 | Submount(app.cfg['tags_url_prefix'], [ |
|---|
| 51 | Rule('/', endpoint='blog/tags'), |
|---|
| 52 | Rule('/<string:slug>', defaults={'page': 1}, endpoint='blog/show_tag'), |
|---|
| 53 | Rule('/<string:slug>/page/<int:page>', endpoint='blog/show_tag'), |
|---|
| 54 | Rule('/<string:tag>/feed.atom', endpoint='blog/atom_feed'), |
|---|
| 55 | Submount('/<string:tag>/feed', [ |
|---|
| 56 | Rule('/', endpoint='blog/rss_feed'), |
|---|
| 57 | Rule('/rss', endpoint='blog/rss_feed'), |
|---|
| 58 | Rule('/rss2', endpoint='blog/rss_feed'), |
|---|
| 59 | Rule('/atom', endpoint='blog/atom_feed'), |
|---|
| 60 | ]), |
|---|
| 61 | ]), |
|---|
| 62 | Submount(app.cfg['account_url_prefix'], [ |
|---|
| 63 | Rule('/', endpoint='account/index'), |
|---|
| 64 | Rule('/login', endpoint='account/login'), |
|---|
| 65 | Rule('/logout', endpoint='account/logout'), |
|---|
| 66 | Rule('/delete', endpoint='account/delete'), |
|---|
| 67 | Rule('/profile', endpoint='account/profile'), |
|---|
| 68 | Rule('/notifications', endpoint='account/notification_settings'), |
|---|
| 69 | Rule('/system/about', endpoint='account/about_zine'), |
|---|
| 70 | Rule('/system/help/', endpoint='account/help'), |
|---|
| 71 | Rule('/system/help/<path:page>', endpoint='account/help') |
|---|
| 72 | ]) |
|---|
| 73 | ] |
|---|
| 74 | admin_urls = [ |
|---|
| 75 | Rule('/', endpoint='admin/index'), |
|---|
| 76 | Rule('/login', endpoint='admin/login', redirect_to='account/login'), # XXX: Remove on Zine 0.3 |
|---|
| 77 | Rule('/logout', endpoint='admin/logout', redirect_to='account/logout'), # XXX: Remove on Zine 0.3 |
|---|
| 78 | Rule('/_bookmarklet', endpoint='admin/bookmarklet'), |
|---|
| 79 | Rule('/entries/', endpoint='admin/manage_entries', defaults={'page': 1}), |
|---|
| 80 | Rule('/entries/page/<int:page>', endpoint='admin/manage_entries'), |
|---|
| 81 | Rule('/entries/new', endpoint='admin/new_entry'), |
|---|
| 82 | Rule('/pages/', endpoint='admin/manage_pages', defaults={'page': 1}), |
|---|
| 83 | Rule('/pages/page/<int:page>', endpoint='admin/manage_pages'), |
|---|
| 84 | Rule('/pages/new', endpoint='admin/new_page'), |
|---|
| 85 | Rule('/p/<int:post_id>', endpoint='admin/edit_post'), |
|---|
| 86 | Rule('/p/<int:post_id>/delete', endpoint='admin/delete_post'), |
|---|
| 87 | Rule('/p/<int:post_id>/comments', defaults={'page': 1, 'per_page': 20}, |
|---|
| 88 | endpoint='admin/show_post_comments'), |
|---|
| 89 | Rule('/p/<int:post_id>/comments/page/<int:page>/per-page/<int:per_page>', |
|---|
| 90 | endpoint='admin/show_post_comments'), |
|---|
| 91 | Rule('/comments/', endpoint='admin/manage_comments', |
|---|
| 92 | defaults={'page': 1, 'per_page': 20}), |
|---|
| 93 | Rule('/comments/page/<int:page>/per-page/<int:per_page>', |
|---|
| 94 | endpoint='admin/manage_comments'), |
|---|
| 95 | Rule('/comments/unmoderated', defaults={'page': 1, 'per_page': 20}, |
|---|
| 96 | endpoint='admin/show_unmoderated_comments'), |
|---|
| 97 | Rule('/comments/unmoderated/page/<int:page>/per-page/<int:per_page>', |
|---|
| 98 | endpoint='admin/show_unmoderated_comments'), |
|---|
| 99 | Rule('/comments/approved', defaults={'page': 1, 'per_page': 20}, |
|---|
| 100 | endpoint='admin/show_approved_comments'), |
|---|
| 101 | Rule('/comments/approved/page/<int:page>/per-page/<int:per_page>', |
|---|
| 102 | endpoint='admin/show_approved_comments'), |
|---|
| 103 | Rule('/comments/blocked', defaults={'page': 1, 'per_page': 20}, |
|---|
| 104 | endpoint='admin/show_blocked_comments'), |
|---|
| 105 | Rule('/comments/blocked/page/<int:page>/per-page/<int:per_page>', |
|---|
| 106 | endpoint='admin/show_blocked_comments'), |
|---|
| 107 | Rule('/comments/spam', defaults={'page': 1, 'per_page': 20}, |
|---|
| 108 | endpoint='admin/show_spam_comments'), |
|---|
| 109 | Rule('/comments/spam/page/<int:page>/per-page/<int:per_page>', |
|---|
| 110 | endpoint='admin/show_spam_comments'), |
|---|
| 111 | Rule('/comments/<int:comment_id>', endpoint='admin/edit_comment'), |
|---|
| 112 | Rule('/comments/<int:comment_id>/delete', endpoint='admin/delete_comment'), |
|---|
| 113 | Rule('/comments/<int:comment_id>/approve', endpoint='admin/approve_comment'), |
|---|
| 114 | Rule('/comments/<int:comment_id>/block', endpoint='admin/block_comment'), |
|---|
| 115 | Rule('/comments/<int:comment_id>/spam', endpoint='admin/report_comment_spam'), |
|---|
| 116 | Rule('/comments/<int:comment_id>/ham', endpoint='admin/report_comment_ham'), |
|---|
| 117 | Rule('/categories/', endpoint='admin/manage_categories', defaults={'page': 1}), |
|---|
| 118 | Rule('/categories/page/<int:page>', endpoint='admin/manage_categories'), |
|---|
| 119 | Rule('/categories/new', endpoint='admin/new_category'), |
|---|
| 120 | Rule('/categories/<int:category_id>', endpoint='admin/edit_category'), |
|---|
| 121 | Rule('/categories/<int:category_id>/delete', endpoint='admin/delete_category'), |
|---|
| 122 | Rule('/users/', endpoint='admin/manage_users', defaults={'page': 1}), |
|---|
| 123 | Rule('/users/page/<int:page>', endpoint='admin/manage_users'), |
|---|
| 124 | Rule('/users/new', endpoint='admin/new_user'), |
|---|
| 125 | Rule('/users/<int:user_id>', endpoint='admin/edit_user'), |
|---|
| 126 | Rule('/users/<int:user_id>/delete', endpoint='admin/delete_user'), |
|---|
| 127 | Rule('/groups/', endpoint='admin/manage_groups'), |
|---|
| 128 | Rule('/groups/new', endpoint='admin/new_group'), |
|---|
| 129 | Rule('/groups/<int:group_id>', endpoint='admin/edit_group'), |
|---|
| 130 | Rule('/groups/<int:group_id>/delete', endpoint='admin/delete_group'), |
|---|
| 131 | Rule('/options/', endpoint='admin/options'), |
|---|
| 132 | Rule('/options/basic', endpoint='admin/basic_options'), |
|---|
| 133 | Rule('/options/urls', endpoint='admin/urls'), |
|---|
| 134 | Rule('/options/theme/', endpoint='admin/theme'), |
|---|
| 135 | Rule('/options/theme/configure', endpoint='admin/configure_theme'), |
|---|
| 136 | Rule('/options/cache', endpoint='admin/cache'), |
|---|
| 137 | Rule('/options/configuration', endpoint='admin/configuration'), |
|---|
| 138 | Rule('/system/', endpoint='admin/information'), |
|---|
| 139 | Rule('/system/maintenance', endpoint='admin/maintenance'), |
|---|
| 140 | Rule('/system/log', defaults={'page': 1}, endpoint='admin/log'), |
|---|
| 141 | Rule('/system/log/page/<int:page>', endpoint='admin/log'), |
|---|
| 142 | Rule('/system/import/', endpoint='admin/import'), |
|---|
| 143 | Rule('/system/import/<int:id>', endpoint='admin/inspect_import'), |
|---|
| 144 | Rule('/system/import/<int:id>/delete', endpoint='admin/delete_import'), |
|---|
| 145 | Rule('/system/export', endpoint='admin/export'), |
|---|
| 146 | Rule('/system/plugins/', endpoint='admin/plugins'), |
|---|
| 147 | Rule('/system/plugins/<plugin>/remove', endpoint='admin/remove_plugin'), |
|---|
| 148 | Rule('/system/help/', endpoint='admin/help'), |
|---|
| 149 | Rule('/system/help/<path:page>', endpoint='admin/help'), |
|---|
| 150 | Rule('/change_password', endpoint='admin/change_password', |
|---|
| 151 | redirect_to='account/index'), # XXX: Remove on Zine 0.3 |
|---|
| 152 | ] |
|---|
| 153 | other_urls = [ |
|---|
| 154 | Rule('/<slug>', endpoint='blog/post', build_only=True), |
|---|
| 155 | Rule('/_services/', endpoint='blog/service_rsd'), |
|---|
| 156 | Rule('/_services/json/<path:identifier>', endpoint='blog/json_service'), |
|---|
| 157 | Rule('/_services/xml/<path:identifier>', endpoint='blog/xml_service'), |
|---|
| 158 | Rule('/_translations.js', endpoint='blog/serve_translations') |
|---|
| 159 | ] |
|---|
| 160 | |
|---|
| 161 | # add the more complex url rule for archive and show post |
|---|
| 162 | tmp = '/' |
|---|
| 163 | for digits, part in zip(app.cfg['fixed_url_date_digits'] and (4, 2, 2) |
|---|
| 164 | or (0, 0, 0), ('year', 'month', 'day')): |
|---|
| 165 | tmp += '<int(fixed_digits=%d):%s>/' % (digits, part) |
|---|
| 166 | blog_urls.extend([ |
|---|
| 167 | Rule(tmp, defaults={'page': 1}, endpoint='blog/archive'), |
|---|
| 168 | Rule(tmp + 'page/<int:page>', endpoint='blog/archive'), |
|---|
| 169 | Rule(tmp + 'feed.atom', endpoint='blog/atom_feed') |
|---|
| 170 | ]) |
|---|
| 171 | |
|---|
| 172 | return [ |
|---|
| 173 | Submount(app.cfg['blog_url_prefix'], blog_urls), |
|---|
| 174 | Submount(app.cfg['admin_url_prefix'], admin_urls) |
|---|
| 175 | ] + other_urls |
|---|