Commit e5541ab7 by Mike Chen

Merge branch 'master' of github.com:dementrock/mitx into ccp0101/performance

parents 22318afd e9bdb8cd
...@@ -58,6 +58,32 @@ In the discussion service, notifications are handled asynchronously using a thir ...@@ -58,6 +58,32 @@ In the discussion service, notifications are handled asynchronously using a thir
bundle exec rake jobs:work bundle exec rake jobs:work
## Initialize roles and permissions
To fully test the discussion forum, you might want to act as a moderator or an administrator. Currently, moderators can manage everything in the forum, and administrator can manage everything plus assigning and revoking moderator status of other users.
First make sure that the database is up-to-date:
rake django-admin[syncdb]
rake django-admin[migrate]
For convenience, add the following environment variables to the terminal (assuming that you're using configuration set lms.envs.dev):
export DJANGO_SETTINGS_MODULE=lms.envs.dev
export PYTHONPATH=.
Now initialzie roles and permissions:
django-admin.py seed_permissions_roles
To assign yourself as a moderator, use the following command (assuming your username is "test", and the course id is "MITx/6.002x/2012_Fall"):
django-admin.py assign_role test Moderator "MITx/6.002x/2012_Fall"
To assign yourself as an administrator, use the following command
django-admin.py assign_role test Administrator "MITx/6.002x/2012_Fall"
## Some other useful commands ## Some other useful commands
### generate seeds for a specific forum ### generate seeds for a specific forum
...@@ -104,18 +130,30 @@ We also have a command for generating comments within a forum with the specified ...@@ -104,18 +130,30 @@ We also have a command for generating comments within a forum with the specified
bundle exec rake db:generate_comments[type_the_discussion_id_here] bundle exec rake db:generate_comments[type_the_discussion_id_here]
For instance, if you want to generate comments for the general discussion, for which the discussion id is the course id with slashes and dots replaced by underscores (you **should** do this before testing forum view) and you are in 6.002x, use the following command For instance, if you want to generate comments for a new discussion tab named "lab_3", then use the following command
bundle exec rake db:generate_comments[MITx_6_002x_2012_Fall] bundle exec rake db:generate_comments[lab_3]
### Running tests for the service ### Running tests for the service
bundle exec rspec bundle exec rspec
Warning: due to an unresolved bug in the test code, testing the service will "flush" the development database. So you need to generate seed again after testing. Warning: the development and test environments share the same elasticsearch index. After running tests, search may not work in the development environment. You simply need to reindex:
bundle exec rake db:reindex_search
### debugging the service ### debugging the service
You can use the following command to launch a console within the service environment: You can use the following command to launch a console within the service environment:
bundle exec rake console bundle exec rake console
### show user roles and permissions
Use the following command to see the roles and permissions of a user in a given course (assuming, again, that the username is "test"):
django-admin.py show_permissions moderator
You need to make sure that the environment variables are exported. Otherwise you would need to do
django-admin.py show_permissions moderator --settings=lms.envs.dev --pythonpath=.
...@@ -5,5 +5,5 @@ urlpatterns = patterns('django_comment_client.forum.views', ...@@ -5,5 +5,5 @@ urlpatterns = patterns('django_comment_client.forum.views',
url(r'users/(?P<user_id>\w+)$', 'user_profile', name='user_profile'), url(r'users/(?P<user_id>\w+)$', 'user_profile', name='user_profile'),
url(r'(?P<discussion_id>\w+)/threads/(?P<thread_id>\w+)$', 'single_thread', name='single_thread'), url(r'(?P<discussion_id>\w+)/threads/(?P<thread_id>\w+)$', 'single_thread', name='single_thread'),
url(r'(?P<discussion_id>\w+)/inline$', 'inline_discussion', name='inline_discussion'), url(r'(?P<discussion_id>\w+)/inline$', 'inline_discussion', name='inline_discussion'),
url(r'(?P<discussion_id>\w+)$', 'forum_form_discussion', name='forum_form_discussion'), url(r'', 'forum_form_discussion', name='forum_form_discussion'),
) )
...@@ -24,6 +24,10 @@ import dateutil ...@@ -24,6 +24,10 @@ import dateutil
THREADS_PER_PAGE = 5 THREADS_PER_PAGE = 5
PAGES_NEARBY_DELTA = 2 PAGES_NEARBY_DELTA = 2
def _general_discussion_id(course_id):
return course_id.replace('/', '_').replace('.', '_')
def _should_perform_search(request): def _should_perform_search(request):
return bool(request.GET.get('text', False) or \ return bool(request.GET.get('text', False) or \
request.GET.get('tags', False)) request.GET.get('tags', False))
...@@ -57,7 +61,7 @@ def render_discussion(request, course_id, threads, *args, **kwargs): ...@@ -57,7 +61,7 @@ def render_discussion(request, course_id, threads, *args, **kwargs):
base_url = { base_url = {
'inline': (lambda: reverse('django_comment_client.forum.views.inline_discussion', args=[course_id, discussion_id])), 'inline': (lambda: reverse('django_comment_client.forum.views.inline_discussion', args=[course_id, discussion_id])),
'forum': (lambda: reverse('django_comment_client.forum.views.forum_form_discussion', args=[course_id, discussion_id])), 'forum': (lambda: reverse('django_comment_client.forum.views.forum_form_discussion', args=[course_id])),
'user': (lambda: reverse('django_comment_client.forum.views.user_profile', args=[course_id, user_id])), 'user': (lambda: reverse('django_comment_client.forum.views.user_profile', args=[course_id, user_id])),
}[discussion_type]() }[discussion_type]()
...@@ -93,11 +97,11 @@ def render_forum_discussion(*args, **kwargs): ...@@ -93,11 +97,11 @@ def render_forum_discussion(*args, **kwargs):
def render_user_discussion(*args, **kwargs): def render_user_discussion(*args, **kwargs):
return render_discussion(discussion_type='user', *args, **kwargs) return render_discussion(discussion_type='user', *args, **kwargs)
def get_threads(request, course_id, discussion_id): def get_threads(request, course_id, discussion_id=None):
query_params = { query_params = {
'page': request.GET.get('page', 1), 'page': request.GET.get('page', 1),
'per_page': THREADS_PER_PAGE, #TODO maybe change this later 'per_page': THREADS_PER_PAGE, #TODO maybe change this later
'sort_key': request.GET.get('sort_key', 'date'), 'sort_key': request.GET.get('sort_key', 'activity'),
'sort_order': request.GET.get('sort_order', 'desc'), 'sort_order': request.GET.get('sort_order', 'desc'),
'text': request.GET.get('text', ''), 'text': request.GET.get('text', ''),
'tags': request.GET.get('tags', ''), 'tags': request.GET.get('tags', ''),
...@@ -129,22 +133,19 @@ def render_search_bar(request, course_id, discussion_id=None, text=''): ...@@ -129,22 +133,19 @@ def render_search_bar(request, course_id, discussion_id=None, text=''):
} }
return render_to_string('discussion/_search_bar.html', context) return render_to_string('discussion/_search_bar.html', context)
def forum_form_discussion(request, course_id, discussion_id): def forum_form_discussion(request, course_id):
course = check_course(request.user, course_id) course = check_course(request.user, course_id)
threads, query_params = get_threads(request, course_id, discussion_id) threads, query_params = get_threads(request, course_id)
content = render_forum_discussion(request, course_id, threads, discussion_id=discussion_id, \ content = render_forum_discussion(request, course_id, threads, discussion_id=_general_discussion_id(course_id), query_params=query_params)
query_params=query_params)
recent_active_threads = cc.search_recent_active_threads( recent_active_threads = cc.search_recent_active_threads(
course_id, course_id,
recursive=False, recursive=False,
query_params={'follower_id': request.user.id, query_params={'follower_id': request.user.id},
'commentable_id': discussion_id},
) )
trending_tags = cc.search_trending_tags( trending_tags = cc.search_trending_tags(
course_id, course_id,
query_params={'commentable_id': discussion_id},
) )
if request.is_ajax(): if request.is_ajax():
...@@ -154,7 +155,6 @@ def forum_form_discussion(request, course_id, discussion_id): ...@@ -154,7 +155,6 @@ def forum_form_discussion(request, course_id, discussion_id):
'csrf': csrf(request)['csrf_token'], 'csrf': csrf(request)['csrf_token'],
'course': course, 'course': course,
'content': content, 'content': content,
'accordion': render_accordion(request, course, discussion_id),
'recent_active_threads': recent_active_threads, 'recent_active_threads': recent_active_threads,
'trending_tags': trending_tags, 'trending_tags': trending_tags,
} }
......
...@@ -35,13 +35,17 @@ class Thread(models.Model): ...@@ -35,13 +35,17 @@ class Thread(models.Model):
url = cls.url(action='search') url = cls.url(action='search')
else: else:
url = cls.url(action='get_all', params=extract(params, 'commentable_id')) url = cls.url(action='get_all', params=extract(params, 'commentable_id'))
del params['commentable_id'] if params.get('commentable_id'):
del params['commentable_id']
response = perform_request('get', url, params, *args, **kwargs) response = perform_request('get', url, params, *args, **kwargs)
return response.get('collection', []), response.get('page', 1), response.get('num_pages', 1) return response.get('collection', []), response.get('page', 1), response.get('num_pages', 1)
@classmethod @classmethod
def url_for_threads(cls, params={}): def url_for_threads(cls, params={}):
return "{prefix}/{commentable_id}/threads".format(prefix=settings.PREFIX, commentable_id=params['commentable_id']) if params.get('commentable_id'):
return "{prefix}/{commentable_id}/threads".format(prefix=settings.PREFIX, commentable_id=params['commentable_id'])
else:
return "{prefix}/threads".format(prefix=settings.PREFIX)
@classmethod @classmethod
def url_for_search_threads(cls, params={}): def url_for_search_threads(cls, params={}):
......
...@@ -102,10 +102,12 @@ $tag-text-color: #5b614f; ...@@ -102,10 +102,12 @@ $tag-text-color: #5b614f;
li { li {
@include clearfix; @include clearfix;
margin-bottom: 8px; margin-bottom: 8px;
border: none;
} }
a { a {
@include standard-discussion-link; @include standard-discussion-link;
background: none;
} }
} }
......
...@@ -19,7 +19,7 @@ def url_class(url): ...@@ -19,7 +19,7 @@ def url_class(url):
<li class="book"><a href="${reverse('book', args=[course.id])}" class="${url_class('book')}">Textbook</a></li> <li class="book"><a href="${reverse('book', args=[course.id])}" class="${url_class('book')}">Textbook</a></li>
% endif % endif
% if settings.MITX_FEATURES.get('ENABLE_DISCUSSION_SERVICE'): % if settings.MITX_FEATURES.get('ENABLE_DISCUSSION_SERVICE'):
<li class="discussion"><a href="${reverse('django_comment_client.forum.views.forum_form_discussion', args=[course.id, course.id.replace('/', '_').replace('.', '_')])}" class="${url_class('discussion')}">Discussion</a></li> <li class="discussion"><a href="${reverse('django_comment_client.forum.views.forum_form_discussion', args=[course.id])}" class="${url_class('discussion')}">Discussion</a></li>
<li class="news"><a href="${reverse('news', args=[course.id])}" class="${url_class('news')}">News</a></li> <li class="news"><a href="${reverse('news', args=[course.id])}" class="${url_class('news')}">News</a></li>
% endif % endif
% endif % endif
......
...@@ -44,10 +44,10 @@ ...@@ -44,10 +44,10 @@
<%def name="render_content(content, type, **kwargs)"> <%def name="render_content(content, type, **kwargs)">
<div class="discussion-content"> <div class="discussion-content">
<div class="discussion-content-wrapper clearfix"> <div class="discussion-content-wrapper">
${render_vote(content)} ${render_vote(content)}
<div class="discussion-right-wrapper clearfix"> <div class="discussion-right-wrapper">
<ul class="admin-actions"> <ul class="admin-actions">
% if type == 'comment': % if type == 'comment':
<li><a href="javascript:void(0)" class="admin-endorse">Endorse</a></li> <li><a href="javascript:void(0)" class="admin-endorse">Endorse</a></li>
...@@ -96,7 +96,7 @@ ...@@ -96,7 +96,7 @@
<%def name="render_tags(content, type, **kwargs)"> <%def name="render_tags(content, type, **kwargs)">
<% <%
def url_for_tags(tags): def url_for_tags(tags):
return reverse('django_comment_client.forum.views.forum_form_discussion', args=[course_id, content['commentable_id']]) + '?' + urllib.urlencode({'tags': ",".join(tags)}) return reverse('django_comment_client.forum.views.forum_form_discussion', args=[course_id]) + '?' + urllib.urlencode({'tags': ",".join(tags)})
%> %>
% if type == "thread": % if type == "thread":
<div class="thread-tags"> <div class="thread-tags">
......
...@@ -16,10 +16,6 @@ ...@@ -16,10 +16,6 @@
<section class="container"> <section class="container">
<div class="course-wrapper"> <div class="course-wrapper">
<section aria-label="Course Navigation" class="course-index"> <section aria-label="Course Navigation" class="course-index">
<header id="open_close_accordion">
<h2>Discussion Boards</h2>
<a href="#">close</a>
</header>
<nav> <nav>
<article class="sidebar-module discussion-sidebar"> <article class="sidebar-module discussion-sidebar">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment