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
17d11a63
Commit
17d11a63
authored
Aug 01, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pagination
parent
f204e988
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
130 additions
and
19 deletions
+130
-19
lms/djangoapps/django_comment_client/forum/views.py
+63
-14
lms/lib/comment_client.py
+5
-2
lms/static/sass/_discussion.scss
+6
-1
lms/templates/discussion/_forum.html
+2
-1
lms/templates/discussion/_inline.html
+2
-1
lms/templates/discussion/_paginator.html
+52
-0
No files found.
lms/djangoapps/django_comment_client/forum/views.py
View file @
17d11a63
...
...
@@ -3,18 +3,28 @@ from django.views.decorators.http import require_POST
from
django.http
import
HttpResponse
from
django.utils
import
simplejson
from
django.core.context_processors
import
csrf
from
django.core.urlresolvers
import
reverse
from
mitxmako.shortcuts
import
render_to_response
,
render_to_string
from
courseware.courses
import
check_course
import
comment_client
import
dateutil
from
dateutil.tz
import
tzlocal
from
datehelper
import
time_ago_in_words
from
django_comment_client.utils
import
get_categorized_discussion_info
from
urllib
import
urlencode
import
json
import
comment_client
import
dateutil
THREADS_PER_PAGE
=
20
PAGES_NEARBY_DELTA
=
2
class
HtmlResponse
(
HttpResponse
):
def
__init__
(
self
,
html
=
''
):
super
(
HtmlResponse
,
self
)
.
__init__
(
html
,
content_type
=
'text/plain'
)
def
render_accordion
(
request
,
course
,
discussion_id
):
...
...
@@ -29,29 +39,58 @@ def render_accordion(request, course, discussion_id):
return
render_to_string
(
'discussion/_accordion.html'
,
context
)
def
render_discussion
(
request
,
course_id
,
threads
,
discussion_id
=
None
,
with_search_bar
=
True
,
search_text
=
''
,
template
=
'discussion/_inline.html'
):
def
render_discussion
(
request
,
course_id
,
threads
,
discussion_id
=
None
,
with_search_bar
=
True
,
search_text
=
''
,
discussion_type
=
'inline'
,
page
=
1
,
num_pages
=
None
,
per_page
=
THREADS_PER_PAGE
,
url_for_page
=
None
):
template
=
{
'inline'
:
'discussion/_inline.html'
,
'forum'
:
'discussion/_forum.html'
,
}[
discussion_type
]
def
_url_for_inline_page
(
page
,
per_page
):
raw_url
=
reverse
(
'django_comment_client.forum.views.inline_discussion'
,
args
=
[
course_id
,
discussion_id
])
return
raw_url
+
'?'
+
urlencode
({
'page'
:
page
,
'per_page'
:
per_page
})
def
_url_for_forum_page
(
page
,
per_page
):
raw_url
=
reverse
(
'django_comment_client.forum.views.forum_form_discussion'
,
args
=
[
course_id
,
discussion_id
])
return
raw_url
+
'?'
+
urlencode
({
'page'
:
page
,
'per_page'
:
per_page
})
url_for_page
=
{
'inline'
:
_url_for_inline_page
,
'forum'
:
_url_for_forum_page
,
}[
discussion_type
]
context
=
{
'threads'
:
threads
,
'discussion_id'
:
discussion_id
,
'search_bar'
:
''
if
not
with_search_bar
\
else
render_search_bar
(
request
,
course_id
,
discussion_id
,
text
=
search_text
),
'user_info'
:
comment_client
.
get_user_info
(
request
.
user
.
id
,
raw
=
True
),
'tags'
:
comment_client
.
get_threads_tags
(
raw
=
True
),
'course_id'
:
course_id
,
'request'
:
request
,
'page'
:
page
,
'per_page'
:
per_page
,
'num_pages'
:
num_pages
,
'pages_nearby_delta'
:
PAGES_NEARBY_DELTA
,
'discussion_type'
:
discussion_type
,
'url_for_page'
:
url_for_page
,
}
return
render_to_string
(
template
,
context
)
def
render_inline_discussion
(
*
args
,
**
kwargs
):
return
render_discussion
(
template
=
'discussion/_inline.html'
,
*
args
,
**
kwargs
)
return
render_discussion
(
discussion_type
=
'inline'
,
*
args
,
**
kwargs
)
def
render_forum_discussion
(
*
args
,
**
kwargs
):
return
render_discussion
(
template
=
'discussion/_forum.html
'
,
*
args
,
**
kwargs
)
return
render_discussion
(
discussion_type
=
'forum
'
,
*
args
,
**
kwargs
)
# discussion per page is fixed for now
def
inline_discussion
(
request
,
course_id
,
discussion_id
):
threads
=
comment_client
.
get_threads
(
discussion_id
,
recursive
=
False
)
html
=
render_inline_discussion
(
request
,
course_id
,
threads
,
discussion_id
=
discussion_id
)
return
HttpResponse
(
html
,
content_type
=
"text/plain"
)
formpage
=
request
.
GET
.
get
(
'page'
,
1
)
threads
,
page
,
num_pages
=
comment_client
.
get_threads
(
discussion_id
,
recursive
=
False
,
page
=
page
,
per_page
=
THREADS_PER_PAGE
)
html
=
render_inline_discussion
(
request
,
course_id
,
threads
,
discussion_id
=
discussion_id
,
num_pages
=
num_pages
,
page
=
page
)
return
HtmlResponse
(
html
)
def
render_search_bar
(
request
,
course_id
,
discussion_id
=
None
,
text
=
''
):
if
not
discussion_id
:
...
...
@@ -66,18 +105,29 @@ def render_search_bar(request, course_id, discussion_id=None, text=''):
def
forum_form_discussion
(
request
,
course_id
,
discussion_id
):
course
=
check_course
(
course_id
)
search_text
=
request
.
GET
.
get
(
'text'
,
''
)
page
=
request
.
GET
.
get
(
'page'
,
1
)
if
len
(
search_text
)
>
0
:
threads
=
comment_client
.
search_threads
({
'text'
:
search_text
,
'commentable_id'
:
discussion_id
})
threads
,
page
,
per_page
,
num_pages
=
comment_client
.
search_threads
({
'text'
:
search_text
,
'commentable_id'
:
discussion_id
,
'course_id'
:
course_id
,
'page'
:
page
,
'per_page'
:
THREADS_PER_PAGE
,
})
else
:
threads
=
comment_client
.
get_threads
(
discussion_id
,
recursive
=
False
)
threads
,
page
,
per_page
,
num_pages
=
comment_client
.
get_threads
(
discussion_id
,
recursive
=
False
,
page
=
page
,
per_page
=
THREADS_PER_PAGE
)
context
=
{
'csrf'
:
csrf
(
request
)[
'csrf_token'
],
'course'
:
course
,
'content'
:
render_forum_discussion
(
request
,
course_id
,
threads
,
discussion_id
=
discussion_id
,
search_text
=
search_text
),
'content'
:
render_forum_discussion
(
request
,
course_id
,
threads
,
discussion_id
=
discussion_id
,
search_text
=
search_text
,
num_pages
=
num_pages
,
per_page
=
per_page
,
page
=
page
),
'accordion'
:
render_accordion
(
request
,
course
,
discussion_id
),
}
...
...
@@ -102,7 +152,6 @@ def render_single_thread(request, course_id, thread_id):
'thread'
:
thread
,
'user_info'
:
comment_client
.
get_user_info
(
request
.
user
.
id
,
raw
=
True
),
'annotated_content_info'
:
json
.
dumps
(
get_annotated_content_info
(
thread
=
thread
,
user_id
=
request
.
user
.
id
)),
'tags'
:
comment_client
.
get_threads_tags
(
raw
=
True
),
'course_id'
:
course_id
,
'request'
:
request
,
}
...
...
lms/lib/comment_client.py
View file @
17d11a63
...
...
@@ -15,8 +15,9 @@ class CommentClientUnknownError(CommentClientError):
def
delete_threads
(
commentable_id
,
*
args
,
**
kwargs
):
return
_perform_request
(
'delete'
,
_url_for_commentable_threads
(
commentable_id
),
*
args
,
**
kwargs
)
def
get_threads
(
commentable_id
,
recursive
=
False
,
*
args
,
**
kwargs
):
return
_perform_request
(
'get'
,
_url_for_threads
(
commentable_id
),
{
'recursive'
:
recursive
},
*
args
,
**
kwargs
)
def
get_threads
(
commentable_id
,
recursive
=
False
,
page
=
1
,
per_page
=
20
,
*
args
,
**
kwargs
):
response
=
_perform_request
(
'get'
,
_url_for_threads
(
commentable_id
),
{
'recursive'
:
recursive
,
'page'
:
page
,
'per_page'
:
per_page
},
*
args
,
**
kwargs
)
return
response
[
'collection'
],
response
[
'page'
],
response
[
'per_page'
],
response
[
'num_pages'
]
def
get_threads_tags
(
*
args
,
**
kwargs
):
return
_perform_request
(
'get'
,
_url_for_threads_tags
(),
{},
*
args
,
**
kwargs
)
...
...
@@ -98,6 +99,8 @@ def unsubscribe_commentable(user_id, commentable_id, *args, **kwargs):
return
unsubscribe
(
user_id
,
{
'source_type'
:
'other'
,
'source_id'
:
commentable_id
})
def
search_threads
(
attributes
,
*
args
,
**
kwargs
):
default_attributes
=
{
'page'
:
1
,
'per_page'
:
20
}
attributes
=
dict
(
default_attributes
.
items
()
+
attributes
.
items
())
return
_perform_request
(
'get'
,
_url_for_search_threads
(),
attributes
,
*
args
,
**
kwargs
)
def
_perform_request
(
method
,
url
,
data_or_params
=
None
,
*
args
,
**
kwargs
):
...
...
lms/static/sass/_discussion.scss
View file @
17d11a63
...
...
@@ -280,7 +280,12 @@ $discussion_input_width: 90%;
}
}
}
.discussion-paginator
{
margin-top
:
40px
;
div
{
display
:
inline-block
;
}
}
}
...
...
lms/templates/discussion/_forum.html
View file @
17d11a63
...
...
@@ -8,9 +8,11 @@
${search_bar}
<div
class=
"discussion-new-post control-button"
href=
"javascript:void(0)"
>
New Post
</div>
</div>
<
%
include
file=
"_paginator.html"
/>
% for thread in threads:
${renderer.render_thread(course_id, thread, edit_thread=False, show_comments=False)}
% endfor
<
%
include
file=
"_paginator.html"
/>
</section>
<
%!
...
...
@@ -21,5 +23,4 @@
<script
type=
"text/javascript"
>
var
$$user_info
=
JSON
.
parse
(
'${user_info | escape_quotes}'
);
var
$$course_id
=
"${course_id}"
;
var
$$tags
=
JSON
.
parse
(
"${tags | escape_quotes}"
);
</script>
lms/templates/discussion/_inline.html
View file @
17d11a63
...
...
@@ -8,9 +8,11 @@
${search_bar}
<div
class=
"discussion-new-post control-button"
href=
"javascript:void(0)"
>
New Post
</div>
</div>
<
%
include
file=
"_paginator.html"
/>
% for thread in threads:
${renderer.render_thread(course_id, thread, edit_thread=False, show_comments=False)}
% endfor
<
%
include
file=
"_paginator.html"
/>
</section>
<
%!
...
...
@@ -21,5 +23,4 @@
<script
type=
"text/javascript"
>
var
$$user_info
=
JSON
.
parse
(
'${user_info | escape_quotes}'
);
var
$$course_id
=
"${course_id}"
;
var
$$tags
=
JSON
.
parse
(
"${tags | escape_quotes}"
);
</script>
lms/templates/discussion/_paginator.html
0 → 100644
View file @
17d11a63
<
%
def
name=
"link_to_page(_page)"
>
% if _page != page:
<div
class=
"page-link"
>
<a
href=
"${url_for_page(_page, per_page)}"
>
${_page}
</a>
</div>
% else:
<div
class=
"page-link"
>
${_page}
</div>
% endif
</
%
def>
<
%
def
name=
"list_pages(*args)"
>
% for arg in args:
% if arg == 'dots':
<div
class=
"page-dots"
>
...
</div>
% elif isinstance(arg, list):
% for _page in arg:
${link_to_page(_page)}
% endfor
% else:
${link_to_page(arg)}
% endif
% endfor
</
%
def>
<div
class=
"discussion-${discussion_type}-paginator discussion-paginator"
>
<div
class=
"prev-page"
>
% if page > 1:
<a
href=
"${url_for_page(page - 1, per_page)}"
>
<
Previous page
</a>
% else:
<
Previous page
% endif
</div>
% if num_pages
<
=
2
*
pages_nearby_delta
+
2:
${
list_pages
(
range
(
1
,
num_pages
+
1
))}
%
else:
%
if
page
<=
2
*
pages_nearby_delta:
${
list_pages
(
range
(
1
,
2
*
pages_nearby_delta
+
2
),
'
dots
',
num_pages
)}
%
elif
num_pages
-
page
+
1
<=
2
*
pages_nearby_delta:
${
list_pages
(
1
,
'
dots
',
range
(
num_pages
-
2
*
pages_nearby_delta
,
num_pages
+
1
))}
%
else:
${
list_pages
(
1
,
'
dots
',
range
(
page
-
pages_nearby_delta
,
page
+
pages_nearby_delta
+
1
),
'
dots
',
num_pages
)}
%
endif
%
endif
<
div
class=
"next-page"
>
% if page
<
num
_pages:
<
a
href=
"${url_for_page(page + 1, per_page)}"
>
Next page
>
</a>
% else:
Next page
>
% endif
</div>
</div>
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