Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
01fbbb9f
Commit
01fbbb9f
authored
Jan 23, 2012
by
Piotr Mitros
Browse files
Options
Browse Files
Download
Plain Diff
Merge
parents
747f5ac2
5227734f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
37 deletions
+24
-37
simplewiki/models.py
+9
-9
simplewiki/settings.py
+0
-1
simplewiki/urls.py
+9
-9
simplewiki/views.py
+6
-18
No files found.
simplewiki/models.py
View file @
01fbbb9f
...
...
@@ -21,9 +21,7 @@ class Article(models.Model):
title
=
models
.
CharField
(
max_length
=
512
,
verbose_name
=
_
(
'Article title'
),
blank
=
False
)
slug
=
models
.
SlugField
(
max_length
=
100
,
verbose_name
=
_
(
'slug'
),
help_text
=
_
(
'Letters, numbers, underscore and hyphen.'
' Do not use reserved words
\'
create
\'
,'
'
\'
history
\'
and
\'
edit
\'
.'
),
help_text
=
_
(
'Letters, numbers, underscore and hyphen.'
),
blank
=
True
)
created_by
=
models
.
ForeignKey
(
User
,
verbose_name
=
_
(
'Created by'
),
blank
=
True
,
null
=
True
)
created_on
=
models
.
DateTimeField
(
auto_now_add
=
1
)
...
...
@@ -50,16 +48,17 @@ class Article(models.Model):
except the very first time the wiki is loaded, in which
case the user is prompted to create this article."""
try
:
return
Article
.
objects
.
filter
(
parent__exact
=
None
)[
0
]
return
Article
.
objects
.
filter
(
slug__exact
=
""
)[
0
]
except
:
raise
ShouldHaveExactlyOneRootSlug
()
def
get_url
(
self
):
"""Return the Wiki URL for an article"""
if
self
.
parent
:
return
self
.
parent
.
get_url
()
+
'/'
+
self
.
slug
else
:
return
self
.
slug
url
=
self
.
slug
+
"/"
if
(
self
.
parent
):
url
=
self
.
parent
.
get_url
()
+
url
return
url
def
get_abs_url
(
self
):
"""Return the absolute path for an article. This is necessary in cases
...
...
@@ -247,7 +246,8 @@ class Revision(models.Model):
# Create pre-parsed contents - no need to parse on-the-fly
ext
=
WIKI_MARKDOWN_EXTENSIONS
ext
+=
[
"wikilinks(base_url=
%
s/)"
%
reverse
(
'wiki_view'
,
args
=
(
''
,))]
# TODO: Replace with a real wikilinks module
# ext += ["wikilinks(base_url=%s/)" % reverse('wiki_view', args=('',))]
self
.
contents_parsed
=
markdown
(
self
.
contents
,
extensions
=
ext
,
safe_mode
=
'escape'
,)
...
...
simplewiki/settings.py
View file @
01fbbb9f
...
...
@@ -89,7 +89,6 @@ WIKI_MARKDOWN_EXTENSIONS = getattr(settings, 'SIMPLE_WIKI_MARKDOWN_EXTENSIONS',
'abbr'
,
'toc'
,
'mathjax'
,
'camelcase'
,
# CamelCase-style wikilinks
'video'
,
# In-line embedding for YouTube, etc.
'circuit'
])
...
...
simplewiki/urls.py
View file @
01fbbb9f
from
django.conf.urls.defaults
import
*
urlpatterns
=
patterns
(
''
,
url
(
r'^
(?:view/)?
$'
,
'simplewiki.views.root_redirect'
,
name
=
'wiki_root'
),
url
(
r'^view
/([a-zA-Z\d/_-]*)/
$'
,
'simplewiki.views.view'
,
name
=
'wiki_view'
),
url
(
r'^edit
/([a-zA-Z\d/_-]*)/
$'
,
'simplewiki.views.edit'
,
name
=
'wiki_edit'
),
url
(
r'^create
/([a-zA-Z\d/_-]*)/
$'
,
'simplewiki.views.create'
,
name
=
'wiki_create'
),
url
(
r'^history
/([a-zA-Z\d/_-]*)/([0-9]*)/
$'
,
'simplewiki.views.history'
,
name
=
'wiki_history'
),
url
(
r'^
random/$'
,
'simplewiki.views.random_article'
,
name
=
'wiki_random
'
),
url
(
r'^
search/$'
,
'simplewiki.views.search_articles'
,
name
=
'wiki_search_articles'
),
url
(
r'^
list/$'
,
'simplewiki.views.search_articles'
,
name
=
'wiki_list_articles'
),
#Just an alias for the search, but you usually don't submit a search term
url
(
r'^
search_related/([a-zA-Z\d/_-]*)/$'
,
'simplewiki.views.search_add_related'
,
name
=
'search_related'
),
url
(
r'^$'
,
'simplewiki.views.root_redirect'
,
name
=
'wiki_root'
),
url
(
r'^view
(/[a-zA-Z\d/_-]*)/?
$'
,
'simplewiki.views.view'
,
name
=
'wiki_view'
),
url
(
r'^edit
(/[a-zA-Z\d/_-]*)/?
$'
,
'simplewiki.views.edit'
,
name
=
'wiki_edit'
),
url
(
r'^create
(/[a-zA-Z\d/_-]*)/?
$'
,
'simplewiki.views.create'
,
name
=
'wiki_create'
),
url
(
r'^history
(/[a-zA-Z\d/_-]*)/([0-9]*)/?
$'
,
'simplewiki.views.history'
,
name
=
'wiki_history'
),
url
(
r'^
search_related(/[a-zA-Z\d/_-]*)/?$'
,
'simplewiki.views.search_add_related'
,
name
=
'search_related
'
),
url
(
r'^
random/?$'
,
'simplewiki.views.random_article'
,
name
=
'wiki_random'
),
url
(
r'^
search/?$'
,
'simplewiki.views.search_articles'
,
name
=
'wiki_search_articles'
),
url
(
r'^
list/?$'
,
'simplewiki.views.search_articles'
,
name
=
'wiki_list_articles'
),
#Just an alias for the search, but you usually don't submit a search term
# url(r'^/?([a-zA-Z\d/_-]*)/_related/add/$', 'simplewiki.views.add_related', name='add_related'),
# url(r'^/?([a-zA-Z\d/_-]*)/_related/remove/(\d+)$', 'simplewiki.views.remove_related', name='wiki_remove_relation'),
# url(r'^/?([a-zA-Z\d/_-]*)/_add_attachment/$', 'simplewiki.views_attachments.add_attachment', name='add_attachment'),
...
...
simplewiki/views.py
View file @
01fbbb9f
...
...
@@ -43,27 +43,15 @@ def view(request, wiki_url):
return
render_to_response
(
'simplewiki_view.html'
,
d
)
def
root_redirect
(
request
):
"""
Reason for redirecting:
The root article needs to to have a specific slug
in the URL, otherwise pattern matching in urls.py will get confused.
I've tried various methods to avoid this, but depending on Django/Python
versions, regexps have been greedy in two different ways.. so I just
skipped having problematic URLs like '/wiki/_edit' for editing the main page.
#benjaoming
"""
if
not
request
.
user
.
is_authenticated
():
return
redirect
(
'/'
)
try
:
root
=
Article
.
get_root
()
if
root
.
slug
==
""
:
root
.
slug
=
"Home"
root
.
save
()
except
:
err
=
not_found
(
request
,
'
mainpage
'
)
err
=
not_found
(
request
,
'
/
'
)
return
err
return
HttpResponseRedirect
(
reverse
(
'wiki_view'
,
args
=
(
root
.
slug
,
)))
return
HttpResponseRedirect
(
reverse
(
'wiki_view'
,
args
=
(
root
.
get_url
()
)))
def
create
(
request
,
wiki_url
):
if
not
request
.
user
.
is_authenticated
():
...
...
@@ -104,7 +92,7 @@ def create(request, wiki_url):
#except ShouldHaveExactlyOneRootSlug, (e):
except
:
if
Article
.
objects
.
filter
(
parent
=
None
)
.
count
()
>
0
:
return
HttpResponseRedirect
(
reverse
(
'wiki_view'
,
args
=
(
''
,)))
return
HttpResponseRedirect
(
reverse
(
'wiki_view'
,
args
=
(
'
/
'
,)))
# Root not found...
path
=
[]
url_path
=
[
""
]
...
...
@@ -266,7 +254,7 @@ def search_articles(request):
# Need to throttle results by splitting them into pages...
results
=
Article
.
objects
.
all
()
if
results
.
count
()
==
1
:
if
results
.
count
()
==
1
and
querystring
:
return
HttpResponseRedirect
(
reverse
(
'wiki_view'
,
args
=
(
results
[
0
]
.
get_url
(),)))
else
:
d
=
{
'wiki_search_results'
:
results
,
...
...
@@ -392,7 +380,7 @@ def fetch_from_url(request, url):
try
:
root
=
Article
.
get_root
()
except
:
err
=
not_found
(
request
,
''
)
err
=
not_found
(
request
,
'
/
'
)
return
(
article
,
path
,
err
)
if
url_path
and
root
.
slug
==
url_path
[
0
]:
...
...
@@ -400,7 +388,7 @@ def fetch_from_url(request, url):
path
=
Article
.
get_url_reverse
(
url_path
,
root
)
if
not
path
:
err
=
not_found
(
request
,
'/'
.
join
([
root
.
slug
]
+
url_path
))
err
=
not_found
(
request
,
'/'
+
'/'
.
join
(
url_path
))
else
:
article
=
path
[
-
1
]
return
(
article
,
path
,
err
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment