/
urls.py
272 lines (247 loc) · 10.3 KB
/
urls.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.conf.urls import include, url
from wiki.conf import settings
from wiki.core.plugins import registry
from wiki.core.plugins.loader import load_wiki_plugins
from wiki.core.utils import get_class_from_str
from wiki.views import accounts, article, deleted_list
class WikiURLPatterns(object):
'''
configurator for wiki urls.
To customize, you can define your own subclass, either overriding
the view providers, or overriding the functions that collect
views.
'''
# basic views
article_view_class = article.ArticleView
article_create_view_class = article.Create
article_delete_view_class = article.Delete
article_deleted_view_class = article.Deleted
article_dir_view_class = article.Dir
article_edit_view_class = article.Edit
article_move_view_class = article.Move
article_preview_view_class = article.Preview
article_history_view_class = article.History
article_settings_view_class = article.Settings
article_source_view_class = article.Source
article_plugin_view_class = article.Plugin
revision_change_view_class = article.ChangeRevisionView
revision_merge_view = staticmethod(article.merge)
search_view_class = settings.SEARCH_VIEW
article_diff_view = staticmethod(article.diff)
# account views
signup_view_class = accounts.Signup
login_view_class = accounts.Login
logout_view_class = accounts.Logout
profile_update_view_class = accounts.Update
# deleted list view
deleted_list_view_class = deleted_list.DeletedListView
def get_urls(self):
urlpatterns = self.get_root_urls()
urlpatterns += self.get_accounts_urls()
urlpatterns += self.get_deleted_list_urls()
urlpatterns += self.get_revision_urls()
urlpatterns += self.get_article_urls()
urlpatterns += self.get_plugin_urls()
# This ALWAYS has to be the last of all the patterns since
# the paths in theory could wrongly match other targets.
urlpatterns += self.get_article_path_urls()
return urlpatterns
def get_root_urls(self):
urlpatterns = [
url(r'^$',
self.article_view_class.as_view(),
name='root',
kwargs={'path': ''}),
url(r'^create-root/$',
article.CreateRootView.as_view(),
name='root_create'),
url(r'^missing-root/$',
article.MissingRootView.as_view(),
name='root_missing'),
url(r'^_search/$',
get_class_from_str(self.search_view_class).as_view(),
name='search'),
url(r'^_revision/diff/(?P<revision_id>[0-9]+)/$',
self.article_diff_view,
name='diff'),
]
return urlpatterns
def get_deleted_list_urls(self):
urlpatterns = [
url('^_admin/$',
self.deleted_list_view_class.as_view(),
name="deleted_list"),
]
return urlpatterns
def get_accounts_urls(self):
if settings.ACCOUNT_HANDLING:
urlpatterns = [
url(r'^_accounts/sign-up/$',
self.signup_view_class.as_view(),
name='signup'),
url(r'^_accounts/logout/$',
self.logout_view_class.as_view(),
name='logout'),
url(r'^_accounts/login/$',
self.login_view_class.as_view(),
name='login'),
url(r'^_accounts/settings/$',
self.profile_update_view_class.as_view(),
name='profile_update'),
]
else:
urlpatterns = []
return urlpatterns
def get_revision_urls(self):
urlpatterns = [
# This one doesn't work because it don't know
# where to redirect after...
url(
r'^_revision/change/(?P<article_id>[0-9]+)/(?P<revision_id>[0-9]+)/$',
self.revision_change_view_class.as_view(),
name='change_revision'),
url(r'^_revision/preview/(?P<article_id>[0-9]+)/$',
self.article_preview_view_class.as_view(),
name='preview_revision'),
url(
r'^_revision/merge/(?P<article_id>[0-9]+)/(?P<revision_id>[0-9]+)/preview/$',
self.revision_merge_view,
name='merge_revision_preview',
kwargs={
'preview': True}),
]
return urlpatterns
def get_article_urls(self):
urlpatterns = [
# Paths decided by article_ids
url(r'^(?P<article_id>[0-9]+)/$',
self.article_view_class.as_view(),
name='get'),
url(r'^(?P<article_id>[0-9]+)/delete/$',
self.article_delete_view_class.as_view(),
name='delete'),
url(r'^(?P<article_id>[0-9]+)/deleted/$',
self.article_deleted_view_class.as_view(),
name='deleted'),
url(r'^(?P<article_id>[0-9]+)/edit/$',
self.article_edit_view_class.as_view(),
name='edit'),
url(r'^(?P<article_id>[0-9]+)/move/$',
self.article_move_view_class.as_view(),
name='move'),
url(r'^(?P<article_id>[0-9]+)/preview/$',
self.article_preview_view_class.as_view(),
name='preview'),
url(r'^(?P<article_id>[0-9]+)/history/$',
self.article_history_view_class.as_view(),
name='history'),
url(r'^(?P<article_id>[0-9]+)/settings/$',
self.article_settings_view_class.as_view(),
name='settings'),
url(r'^(?P<article_id>[0-9]+)/source/$',
self.article_source_view_class.as_view(),
name='source'),
url(
r'^(?P<article_id>[0-9]+)/revision/change/(?P<revision_id>[0-9]+)/$',
self.revision_change_view_class.as_view(),
name='change_revision'),
url(
r'^(?P<article_id>[0-9]+)/revision/merge/(?P<revision_id>[0-9]+)/$',
self.revision_merge_view,
name='merge_revision'),
url(r'^(?P<article_id>[0-9]+)/plugin/(?P<slug>\w+)/$',
self.article_plugin_view_class.as_view(),
name='plugin'),
]
return urlpatterns
def get_article_path_urls(self):
urlpatterns = [
# Paths decided by URLs
url(r'^(?P<path>.+/|)_create/$',
self.article_create_view_class.as_view(),
name='create'),
url(r'^(?P<path>.+/|)_delete/$',
self.article_delete_view_class.as_view(),
name='delete'),
url(r'^(?P<path>.+/|)_deleted/$',
self.article_deleted_view_class.as_view(),
name='deleted'),
url(r'^(?P<path>.+/|)_edit/$',
self.article_edit_view_class.as_view(),
name='edit'),
url(r'^(?P<path>.+/|)_move/$',
self.article_move_view_class.as_view(),
name='move'),
url(r'^(?P<path>.+/|)_preview/$',
self.article_preview_view_class.as_view(),
name='preview'),
url(r'^(?P<path>.+/|)_history/$',
self.article_history_view_class.as_view(),
name='history'),
url(r'^(?P<path>.+/|)_dir/$',
self.article_dir_view_class.as_view(),
name='dir'),
url(r'^(?P<path>.+/|)_search/$',
get_class_from_str(self.search_view_class).as_view(),
name='search'),
url(r'^(?P<path>.+/|)_settings/$',
self.article_settings_view_class.as_view(),
name='settings'),
url(r'^(?P<path>.+/|)_source/$',
self.article_source_view_class.as_view(),
name='source'),
url(
r'^(?P<path>.+/|)_revision/change/(?P<revision_id>[0-9]+)/$',
self.revision_change_view_class.as_view(),
name='change_revision'),
url(
r'^(?P<path>.+/|)_revision/merge/(?P<revision_id>[0-9]+)/$',
self.revision_merge_view,
name='merge_revision'),
url(r'^(?P<path>.+/|)_plugin/(?P<slug>\w+)/$',
self.article_plugin_view_class.as_view(),
name='plugin'),
# This should always go last!
url(r'^(?P<path>.+/|)$',
self.article_view_class.as_view(),
name='get'),
]
return urlpatterns
@staticmethod
def get_plugin_urls():
urlpatterns = []
for plugin in registry.get_plugins().values():
slug = getattr(plugin, 'slug', None)
if slug:
article_urlpatterns = plugin.urlpatterns.get('article', [])
urlpatterns += [
url(r'^(?P<article_id>[0-9]+)/plugin/' + slug + '/',
include(article_urlpatterns)),
url(r'^(?P<path>.+/|)_plugin/' + slug + '/',
include(article_urlpatterns)),
]
root_urlpatterns = plugin.urlpatterns.get('root', [])
urlpatterns += [
url(r'^_plugin/' + slug + '/', include(root_urlpatterns)),
]
return urlpatterns
def get_pattern(app_name="wiki", namespace="wiki", url_config_class=None):
"""Every url resolution takes place as "wiki:view_name".
You should not attempt to have multiple deployments of the wiki in a
single Django project.
https://docs.djangoproject.com/en/dev/topics/http/urls/#topics-http-reversing-url-namespaces
"""
if url_config_class is None:
url_config_classname = getattr(settings, 'URL_CONFIG_CLASS', None)
if url_config_classname is None:
url_config_class = WikiURLPatterns
else:
url_config_class = get_class_from_str(url_config_classname)
urlpatterns = url_config_class().get_urls()
return urlpatterns, app_name, namespace
######################
# PLUGINS
######################
load_wiki_plugins()