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
baa2c068
Commit
baa2c068
authored
Jun 29, 2012
by
Bridger Maxwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Got history and view revision working on wiki.
parent
0c4b6f30
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
66 additions
and
42 deletions
+66
-42
lms/djangoapps/simplewiki/models.py
+17
-2
lms/djangoapps/simplewiki/views.py
+41
-32
lms/templates/simplewiki/simplewiki_base.html
+2
-2
lms/templates/simplewiki/simplewiki_history.html
+2
-2
lms/urls.py
+4
-4
No files found.
lms/djangoapps/simplewiki/models.py
View file @
baa2c068
...
...
@@ -47,14 +47,29 @@ class Article(models.Model):
def
attachments
(
self
):
return
ArticleAttachment
.
objects
.
filter
(
article__exact
=
self
)
def
get_path
(
self
):
return
self
.
namespace
.
name
+
"/"
+
self
.
slug
@classmethod
def
get_article
(
cls
,
article_path
):
"""
Given an article_path like namespace/slug, this returns the article. It may raise
a Article.DoesNotExist if no matching article is found or ValueError if the
article_path is not constructed properly.
"""
#TODO: Verify the path, throw a meaningful error?
namespace
,
slug
=
article_path
.
split
(
"/"
)
return
Article
.
objects
.
get
(
slug__exact
=
slug
,
namespace__name__exact
=
namespace
)
@classmethod
def
get_root
(
cls
):
def
get_root
(
cls
,
namespace
):
"""Return the root article, which should ALWAYS exist..
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
(
slug__exact
=
""
)[
0
]
return
Article
.
objects
.
filter
(
slug__exact
=
""
,
namespace__name__exact
=
namespace
)[
0
]
except
:
raise
ShouldHaveExactlyOneRootSlug
()
...
...
lms/djangoapps/simplewiki/views.py
View file @
baa2c068
...
...
@@ -14,16 +14,16 @@ from multicourse import multicourse_settings
from
models
import
Revision
,
Article
,
CreateArticleForm
,
RevisionFormWithTitle
,
RevisionForm
import
wiki_settings
def
view
(
request
,
course_id
,
slug
,
namespace
=
None
):
def
get_course
(
course_id
):
try
:
course
=
settings
.
COURSES_BY_ID
[
course_id
]
if
not
namespace
:
namespace
=
course
.
wiki_namespace
except
KeyError
:
raise
Http404
(
"Course not found"
)
(
article
,
err
)
=
get_article
(
request
,
slug
,
namespace
if
namespace
else
course_id
)
return
course
def
view
(
request
,
course_id
,
article_path
):
course
=
get_course
(
course_id
)
(
article
,
err
)
=
get_article
(
request
,
article_path
,
course
)
if
err
:
return
err
...
...
@@ -39,11 +39,11 @@ def view(request, course_id, slug, namespace=None):
'course'
:
course
,
}
d
.
update
(
csrf
(
request
))
print
d
return
render_to_response
(
'simplewiki/simplewiki_view.html'
,
d
)
def
view_revision
(
request
,
course_id
,
slug
,
revision_number
,
namespace
=
None
):
(
article
,
err
)
=
get_article
(
request
,
slug
,
namespace
if
namespace
else
course_id
)
def
view_revision
(
request
,
course_id
,
revision_number
,
article_path
):
course
=
get_course
(
course_id
)
(
article
,
err
)
=
get_article
(
request
,
article_path
,
course
)
if
err
:
return
err
...
...
@@ -65,23 +65,24 @@ def view_revision(request, course_id, slug, revision_number, namespace=None):
'wiki_write'
:
article
.
can_write_l
(
request
.
user
),
'wiki_attachments_write'
:
article
.
can_attach
(
request
.
user
),
'wiki_current_revision_deleted'
:
not
(
revision
.
deleted
==
0
),
'course'
:
course
,
}
d
.
update
(
csrf
(
request
))
return
render_to_response
(
'simplewiki/simplewiki_view.html'
,
d
)
def
root_redirect
(
request
):
# TODO: What is going on here? Why don't we just return the redirect?
def
root_redirect
(
request
,
course_id
):
course
=
get_course
(
course_id
)
try
:
root
=
Article
.
get_root
()
root
=
Article
.
get_root
(
course
.
wiki_namespace
)
except
:
#TODO: If we don't find a root article, we should create it
err
=
not_found
(
request
,
'/'
)
return
err
return
HttpResponseRedirect
(
reverse
(
'wiki_view'
,
args
=
(
root
.
get_url
())
))
return
HttpResponseRedirect
(
reverse
(
'wiki_view'
,
kwargs
=
{
'course_id'
:
course_id
,
'article_path'
:
root
.
get_path
()}
))
def
create
(
request
,
wiki_url
):
url_path
=
get_url_path
(
wiki_url
)
if
url_path
!=
[]
and
url_path
[
0
]
.
startswith
(
'_'
):
...
...
@@ -204,8 +205,9 @@ def edit(request, course_id, slug, namespace = None):
return
render_to_response
(
'simplewiki/simplewiki_edit.html'
,
d
)
def
history
(
request
,
course_id
,
slug
,
namespace
=
None
,
page
=
1
):
(
article
,
err
)
=
get_article
(
request
,
slug
,
namespace
if
namespace
else
course_id
)
def
history
(
request
,
course_id
,
article_path
,
page
=
1
):
course
=
get_course
(
course_id
)
(
article
,
err
)
=
get_article
(
request
,
article_path
,
course
)
if
err
:
return
err
...
...
@@ -216,6 +218,8 @@ def history(request, course_id, slug, namespace = None, page=1):
page_size
=
10
if
page
==
None
:
page
=
1
try
:
p
=
int
(
page
)
except
ValueError
:
...
...
@@ -229,7 +233,7 @@ def history(request, course_id, slug, namespace = None, page=1):
if
perm_err
:
return
perm_err
redirectURL
=
reverse
(
'wiki_view'
,
args
=
(
article
.
get_url
(),)
)
redirectURL
=
reverse
(
'wiki_view'
,
kwargs
=
{
'course_id'
:
course
.
id
,
'article_path'
:
article
.
get_path
()}
)
try
:
r
=
int
(
request
.
POST
[
'revision'
])
revision
=
Revision
.
objects
.
get
(
id
=
r
)
...
...
@@ -237,8 +241,9 @@ def history(request, course_id, slug, namespace = None, page=1):
article
.
current_revision
=
revision
article
.
save
()
elif
request
.
POST
.
__contains__
(
'view'
):
redirectURL
=
reverse
(
'wiki_view_revision'
,
args
=
(
revision
.
counter
,
article
.
get_url
(),))
redirectURL
=
reverse
(
'wiki_view_revision'
,
kwargs
=
{
'course_id'
:
course
.
id
,
'revision_number'
:
revision
.
counter
,
'article_path'
:
article
.
get_path
()})
#The rese of these are admin functions
elif
request
.
POST
.
__contains__
(
'delete'
)
and
request
.
user
.
is_superuser
:
if
(
revision
.
deleted
==
0
):
...
...
@@ -253,7 +258,8 @@ def history(request, course_id, slug, namespace = None, page=1):
article
.
locked
=
not
article
.
locked
print
"changed locked article "
,
article
.
locked
article
.
save
()
except
:
except
Exception
as
e
:
print
str
(
e
)
pass
finally
:
return
HttpResponseRedirect
(
redirectURL
)
...
...
@@ -282,7 +288,8 @@ def history(request, course_id, slug, namespace = None, page=1):
'wiki_article'
:
article
,
'wiki_title'
:
article
.
title
,
'wiki_history'
:
history
[
beginItem
:
beginItem
+
page_size
],
'show_delete_revision'
:
request
.
user
.
is_superuser
,}
'show_delete_revision'
:
request
.
user
.
is_superuser
,
'course'
:
course
}
d
.
update
(
csrf
(
request
))
return
render_to_response
(
'simplewiki/simplewiki_history.html'
,
d
)
...
...
@@ -361,7 +368,7 @@ def search_articles(request, course_id):
return
render_to_response
(
'simplewiki/simplewiki_searchresults.html'
,
d
)
def
search_add_related
(
request
,
course_id
,
slug
,
namespace
=
None
):
def
search_add_related
(
request
,
course_id
,
slug
,
namespace
):
(
article
,
err
)
=
get_article
(
request
,
slug
,
namespace
if
namespace
else
course_id
)
if
err
:
return
err
...
...
@@ -391,7 +398,7 @@ def search_add_related(request, course_id, slug, namespace=None):
json
=
simplejson
.
dumps
({
'results'
:
results
})
return
HttpResponse
(
json
,
mimetype
=
'application/json'
)
def
add_related
(
request
,
course_id
,
slug
,
namespace
=
None
):
def
add_related
(
request
,
course_id
,
slug
,
namespace
):
(
article
,
err
)
=
get_article
(
request
,
slug
,
namespace
if
namespace
else
course_id
)
if
err
:
return
err
...
...
@@ -412,7 +419,7 @@ def add_related(request, course_id, slug, namespace=None):
finally
:
return
HttpResponseRedirect
(
reverse
(
'wiki_view'
,
args
=
(
article
.
get_url
(),)))
def
remove_related
(
request
,
course_id
,
slug
,
related_id
,
namespace
=
None
,
):
def
remove_related
(
request
,
course_id
,
namespace
,
slug
,
related_id
):
(
article
,
err
)
=
get_article
(
request
,
slug
,
namespace
if
namespace
else
course_id
)
if
err
:
...
...
@@ -438,27 +445,29 @@ def random_article(request, course_id):
article
=
Article
.
objects
.
all
()[
randint
(
0
,
num_arts
-
1
)]
return
HttpResponseRedirect
(
reverse
(
'wiki_view'
,
args
=
(
article
.
get_url
(),)))
def
encode_err
(
request
,
url
):
d
=
{
'wiki_err_encode'
:
True
}
def
encode_err
(
request
,
url
,
course
):
d
=
{
'wiki_err_encode'
:
True
,
'course'
:
course
}
d
.
update
(
csrf
(
request
))
return
render_to_response
(
'simplewiki/simplewiki_error.html'
,
d
)
def
not_found
(
request
,
wiki_url
):
def
not_found
(
request
,
wiki_url
,
course
):
"""Generate a NOT FOUND message for some URL"""
d
=
{
'wiki_err_notfound'
:
True
,
'wiki_url'
:
wiki_url
}
'wiki_url'
:
wiki_url
,
'course'
:
course
}
d
.
update
(
csrf
(
request
))
return
render_to_response
(
'simplewiki/simplewiki_error.html'
,
d
)
def
get_article
(
request
,
slug
,
namespac
e
):
def
get_article
(
request
,
article_path
,
cours
e
):
err
=
None
article
=
None
try
:
article
=
Article
.
objects
.
get
(
slug__exact
=
slug
)
#, namespace__name__exact = namespace
)
except
Article
.
DoesNotExist
:
article
=
Article
.
get_article
(
article_path
)
except
Article
.
DoesNotExist
,
ValueError
:
#TODO: We need to pass a url for creating the article here
err
=
not_found
(
request
,
slug
)
err
=
not_found
(
request
,
article_path
,
course
)
return
(
article
,
err
)
...
...
lms/templates/simplewiki/simplewiki_base.html
View file @
baa2c068
...
...
@@ -7,8 +7,8 @@
from
django
.
core
.
urlresolvers
import
reverse
%
>
## A convenience function that calls reverse with the kwargs course_id, namespace, and slug
<
%
def
name=
"wiki_reverse(wiki_page)"
>
${reverse(wiki_page, kwargs=
{'course_id': course.id, 'namespace' : wiki_article.namespace.name, 'slug' : wiki_article.slug})
}
<
%
def
name=
"wiki_reverse(wiki_page
, args=[], kwargs={}
)"
>
${reverse(wiki_page, kwargs=
dict({'course_id': course.id, 'article_path' : wiki_article.get_path()}, **kwargs), args=args)
}
</
%
def>
<
%
block
name=
"headextra"
>
...
...
lms/templates/simplewiki/simplewiki_history.html
View file @
baa2c068
...
...
@@ -64,10 +64,10 @@ ${ wiki_article.title }
<tr>
<td
colspan=
"4"
>
%if wiki_prev_page:
<a
href=
"${
reverse("
wiki_history
",
args=
[wiki_article.get_url(),
wiki_prev_page
]
)}"
>
Previous page
</a>
<a
href=
"${
self.wiki_reverse('wiki_history', kwargs={'page' : wiki_prev_page}
)}"
>
Previous page
</a>
%endif
%if wiki_next_page:
<a
href=
"${
reverse("
wiki_history
",
args=
[wiki_article.get_url(),
wiki_next_page
]
)}"
>
Next page
</a>
<a
href=
"${
self.wiki_reverse('wiki_history', kwargs={'page' : wiki_next_page}
)}"
>
Next page
</a>
%endif
</td>
</tr>
...
...
lms/urls.py
View file @
baa2c068
...
...
@@ -85,17 +85,17 @@ if settings.COURSEWARE_ENABLED:
)
# Multicourse wiki
article_slug
=
r"
(?:/(?P<namespace>[a-zA-Z\d_-]*))?/(?P<slug>
[a-zA-Z\d_-]*)"
article_slug
=
r"
/(?P<article_path>[a-zA-Z\d_-]+/
[a-zA-Z\d_-]*)"
urlpatterns
+=
(
url
(
r'^courses/(?P<course_id>[^/]*)/wiki/$'
,
'simplewiki.views.root_redirect'
,
name
=
'wiki_root'
),
url
(
r'^courses/(?P<course_id>[^/]*)/wiki/view'
+
article_slug
+
r'/?$'
,
'simplewiki.views.view'
,
name
=
'wiki_view'
),
url
(
r'^courses/(?P<course_id>[^/]*)/wiki/view_revision/(
[0-9]*)(/[a-zA-Z\d/_-]*)
/?$'
,
'simplewiki.views.view_revision'
,
name
=
'wiki_view_revision'
),
url
(
r'^courses/(?P<course_id>[^/]*)/wiki/view_revision/(
?P<revision_number>[0-9]+)'
+
article_slug
+
r'
/?$'
,
'simplewiki.views.view_revision'
,
name
=
'wiki_view_revision'
),
url
(
r'^courses/(?P<course_id>[^/]*)/wiki/edit'
+
article_slug
+
r'/?$'
,
'simplewiki.views.edit'
,
name
=
'wiki_edit'
),
url
(
r'^courses/(?P<course_id>[^/]*)/wiki/create/?$'
,
'simplewiki.views.create'
,
name
=
'wiki_create'
),
url
(
r'^courses/(?P<course_id>[^/]*)/wiki/history'
+
article_slug
+
r'(?:/(
[0-9]*
))?/?$'
,
'simplewiki.views.history'
,
name
=
'wiki_history'
),
url
(
r'^courses/(?P<course_id>[^/]*)/wiki/history'
+
article_slug
+
r'(?:/(
?P<page>[0-9]+
))?/?$'
,
'simplewiki.views.history'
,
name
=
'wiki_history'
),
url
(
r'^courses/(?P<course_id>[^/]*)/wiki/search_related'
+
article_slug
+
r'/?$'
,
'simplewiki.views.search_add_related'
,
name
=
'search_related'
),
url
(
r'^courses/(?P<course_id>[^/]*)/wiki/random/?$'
,
'simplewiki.views.random_article'
,
name
=
'wiki_random'
),
url
(
r'^courses/(?P<course_id>[^/]*)/wiki/revision_feed/([0-9]
*
)/?$'
,
'simplewiki.views.revision_feed'
,
name
=
'wiki_revision_feed'
),
url
(
r'^courses/(?P<course_id>[^/]*)/wiki/revision_feed/([0-9]
+
)/?$'
,
'simplewiki.views.revision_feed'
,
name
=
'wiki_revision_feed'
),
url
(
r'^courses/(?P<course_id>[^/]*)/wiki/search/?$'
,
'simplewiki.views.search_articles'
,
name
=
'wiki_search_articles'
),
url
(
r'^courses/(?P<course_id>[^/]*)/wiki/list/?$'
,
'simplewiki.views.search_articles'
,
name
=
'wiki_list_articles'
),
#Just an alias for the search, but you usually don't submit a search term
...
...
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