PageRenderTime 194ms CodeModel.GetById 185ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 1ms

/tests/regressiontests/views/urls.py

https://code.google.com/p/mango-py/
Python | 166 lines | 151 code | 14 blank | 1 comment | 0 complexity | 8978e73aea4ff8132b776e142d013fdc MD5 | raw file
  1# coding: utf-8
  2from os import path
  3
  4from django.conf.urls.defaults import *
  5
  6from models import *
  7import views
  8
  9
 10base_dir = path.dirname(path.abspath(__file__))
 11media_dir = path.join(base_dir, 'media')
 12locale_dir = path.join(base_dir, 'locale')
 13
 14js_info_dict = {
 15    'domain': 'djangojs',
 16    'packages': ('regressiontests.views',),
 17}
 18
 19js_info_dict_english_translation = {
 20    'domain': 'djangojs',
 21    'packages': ('regressiontests.views.app0',),
 22}
 23
 24js_info_dict_multi_packages1 = {
 25    'domain': 'djangojs',
 26    'packages': ('regressiontests.views.app1', 'regressiontests.views.app2'),
 27}
 28
 29js_info_dict_multi_packages2 = {
 30    'domain': 'djangojs',
 31    'packages': ('regressiontests.views.app3', 'regressiontests.views.app4'),
 32}
 33
 34date_based_info_dict = {
 35    'queryset': Article.objects.all(),
 36    'date_field': 'date_created',
 37    'month_format': '%m',
 38}
 39
 40object_list_dict = {
 41    'queryset': Article.objects.all(),
 42    'paginate_by': 2,
 43}
 44
 45object_list_no_paginate_by = {
 46    'queryset': Article.objects.all(),
 47}
 48
 49numeric_days_info_dict = dict(date_based_info_dict, day_format='%d')
 50
 51date_based_datefield_info_dict = dict(date_based_info_dict, queryset=DateArticle.objects.all())
 52
 53urlpatterns = patterns('',
 54    (r'^$', views.index_page),
 55
 56    # Default views
 57    (r'^shortcut/(\d+)/(.*)/$', 'django.views.defaults.shortcut'),
 58    (r'^non_existing_url/', 'django.views.defaults.page_not_found'),
 59    (r'^server_error/', 'django.views.defaults.server_error'),
 60
 61    # i18n views
 62    (r'^i18n/', include('django.conf.urls.i18n')),
 63    (r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),
 64    (r'^jsi18n_english_translation/$', 'django.views.i18n.javascript_catalog', js_info_dict_english_translation),
 65    (r'^jsi18n_multi_packages1/$', 'django.views.i18n.javascript_catalog', js_info_dict_multi_packages1),
 66    (r'^jsi18n_multi_packages2/$', 'django.views.i18n.javascript_catalog', js_info_dict_multi_packages2),
 67
 68    # Static views
 69    (r'^site_media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': media_dir}),
 70
 71    # Special URLs for particular regression cases.
 72    url(u'^??/$', 'regressiontests.views.views.redirect'),
 73    url(u'^??/target/$', 'regressiontests.views.views.index_page'),
 74)
 75
 76# Date-based generic views.
 77urlpatterns += patterns('django.views.generic.date_based',
 78    (r'^date_based/object_detail/(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/(?P<slug>[-\w]+)/$',
 79        'object_detail',
 80        dict(slug_field='slug', **date_based_info_dict)),
 81    (r'^date_based/object_detail/(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/(?P<slug>[-\w]+)/allow_future/$',
 82        'object_detail',
 83        dict(allow_future=True, slug_field='slug', **date_based_info_dict)),
 84    (r'^date_based/archive_day/(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/$',
 85        'archive_day',
 86        numeric_days_info_dict),
 87    (r'^date_based/archive_month/(?P<year>\d{4})/(?P<month>\d{1,2})/$',
 88        'archive_month',
 89        date_based_info_dict),
 90    (r'^date_based/datefield/archive_month/(?P<year>\d{4})/(?P<month>\d{1,2})/$',
 91        'archive_month',
 92        date_based_datefield_info_dict),
 93)
 94
 95# crud generic views.
 96urlpatterns += patterns('django.views.generic.create_update',
 97    (r'^create_update/member/create/article/$', 'create_object',
 98        dict(login_required=True, model=Article)),
 99    (r'^create_update/create/article/$', 'create_object',
100        dict(post_save_redirect='/views/create_update/view/article/%(slug)s/',
101             model=Article)),
102    (r'^create_update/update/article/(?P<slug>[-\w]+)/$', 'update_object',
103        dict(post_save_redirect='/views/create_update/view/article/%(slug)s/',
104             slug_field='slug', model=Article)),
105    (r'^create_update/create_custom/article/$', views.custom_create),
106    (r'^create_update/delete/article/(?P<slug>[-\w]+)/$', 'delete_object',
107        dict(post_delete_redirect='/views/create_update/', slug_field='slug',
108             model=Article)),
109
110    # No post_save_redirect and no get_absolute_url on model.
111    (r'^create_update/no_redirect/create/article/$', 'create_object',
112        dict(model=Article)),
113    (r'^create_update/no_redirect/update/article/(?P<slug>[-\w]+)/$',
114        'update_object', dict(slug_field='slug', model=Article)),
115
116    # get_absolute_url on model, but no passed post_save_redirect.
117    (r'^create_update/no_url/create/article/$', 'create_object',
118        dict(model=UrlArticle)),
119    (r'^create_update/no_url/update/article/(?P<slug>[-\w]+)/$',
120        'update_object', dict(slug_field='slug', model=UrlArticle)),
121)
122
123urlpatterns += patterns('django.views.generic.list_detail',
124    (r'^object_list/page(?P<page>[\w]*)/$', 'object_list', object_list_dict),
125    (r'^object_list_no_paginate_by/page(?P<page>[0-9]+)/$', 'object_list',
126     object_list_no_paginate_by),
127)
128
129# a view that raises an exception for the debug view
130urlpatterns += patterns('',
131    (r'^raises/$', views.raises),
132    (r'^raises404/$', views.raises404),
133)
134
135# rediriects, both temporary and permanent, with non-ASCII targets
136urlpatterns += patterns('django.views.generic.simple',
137    ('^nonascii_redirect/$', 'redirect_to',
138        {'url': u'/views/??/target/', 'permanent': False}),
139    ('^permanent_nonascii_redirect/$', 'redirect_to',
140        {'url': u'/views/??/target/', 'permanent': True}),
141)
142
143urlpatterns += patterns('regressiontests.views.views',
144    url(r'view_exception/(?P<n>\d+)/$', 'view_exception', name='view_exception'),
145    url(r'template_exception/(?P<n>\d+)/$', 'template_exception', name='template_exception'),
146    url(r'^raises_template_does_not_exist/$', 'raises_template_does_not_exist', name='raises_template_does_not_exist'),
147
148    (r'^shortcuts/render_to_response/$', 'render_to_response_view'),
149    (r'^shortcuts/render_to_response/request_context/$', 'render_to_response_view_with_request_context'),
150    (r'^shortcuts/render_to_response/mimetype/$', 'render_to_response_view_with_mimetype'),
151    (r'^shortcuts/render/$', 'render_view'),
152    (r'^shortcuts/render/base_context/$', 'render_view_with_base_context'),
153    (r'^shortcuts/render/content_type/$', 'render_view_with_content_type'),
154    (r'^shortcuts/render/status/$', 'render_view_with_status'),
155    (r'^shortcuts/render/current_app/$', 'render_view_with_current_app'),
156    (r'^shortcuts/render/current_app_conflict/$', 'render_view_with_current_app_conflict'),
157)
158
159# simple generic views.
160urlpatterns += patterns('django.views.generic.simple',
161    (r'^simple/redirect_to/$', 'redirect_to', dict(url='/views/simple/target/')),
162    (r'^simple/redirect_to_temp/$', 'redirect_to', dict(url='/views/simple/target/', permanent=False)),
163    (r'^simple/redirect_to_none/$', 'redirect_to', dict(url=None)),
164    (r'^simple/redirect_to_arg/(?P<id>\d+)/$', 'redirect_to', dict(url='/views/simple/target_arg/%(id)s/')),
165    (r'^simple/redirect_to_query/$', 'redirect_to', dict(url='/views/simple/target/', query_string=True)),
166)