Commit d1a8cd3f by Arjun Singh

Limiting depth of comments

parent 27347fbc
...@@ -8,6 +8,8 @@ import functools ...@@ -8,6 +8,8 @@ import functools
import comment_client as cc import comment_client as cc
import django_comment_client.utils as utils import django_comment_client.utils as utils
import django_comment_client.settings as cc_settings
from django.core import exceptions from django.core import exceptions
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
...@@ -15,7 +17,6 @@ from django.views.decorators.http import require_POST, require_GET ...@@ -15,7 +17,6 @@ from django.views.decorators.http import require_POST, require_GET
from django.views.decorators import csrf from django.views.decorators import csrf
from django.core.files.storage import get_storage_class from django.core.files.storage import get_storage_class
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.conf import settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
from mitxmako.shortcuts import render_to_response, render_to_string from mitxmako.shortcuts import render_to_response, render_to_string
...@@ -114,6 +115,9 @@ def _create_comment(request, course_id, thread_id=None, parent_id=None): ...@@ -114,6 +115,9 @@ def _create_comment(request, course_id, thread_id=None, parent_id=None):
@login_required @login_required
@permitted @permitted
def create_comment(request, course_id, thread_id): def create_comment(request, course_id, thread_id):
if cc_settings.MAX_COMMENT_DEPTH is not None:
if cc_settings.MAX_COMMENT_DEPTH < 0:
return JsonError("Comment level too deep")
return _create_comment(request, course_id, thread_id=thread_id) return _create_comment(request, course_id, thread_id=thread_id)
@require_POST @require_POST
...@@ -158,6 +162,9 @@ def openclose_thread(request, course_id, thread_id): ...@@ -158,6 +162,9 @@ def openclose_thread(request, course_id, thread_id):
@login_required @login_required
@permitted @permitted
def create_sub_comment(request, course_id, comment_id): def create_sub_comment(request, course_id, comment_id):
if cc_settings.MAX_COMMENT_DEPTH is not None:
if cc_settings.MAX_COMMENT_DEPTH <= cc.Comment.find(comment_id).depth:
return JsonError("Comment level too deep")
return _create_comment(request, course_id, parent_id=comment_id) return _create_comment(request, course_id, parent_id=comment_id)
@require_POST @require_POST
......
...@@ -6,6 +6,7 @@ from django.core.urlresolvers import reverse ...@@ -6,6 +6,7 @@ from django.core.urlresolvers import reverse
from functools import partial from functools import partial
from utils import * from utils import *
import django_comment_client.settings as cc_settings
import pystache_custom as pystache import pystache_custom as pystache
import urllib import urllib
...@@ -39,6 +40,13 @@ def render_content(content, additional_context={}): ...@@ -39,6 +40,13 @@ def render_content(content, additional_context={}):
'content': extend_content(content), 'content': extend_content(content),
content['type']: True, content['type']: True,
} }
if cc_settings.MAX_COMMENT_DEPTH is not None:
if content['type'] == 'thread':
if cc_settings.MAX_COMMENT_DEPTH < 0:
context['max_depth'] = True
elif content['type'] == 'comment':
if cc_settings.MAX_COMMENT_DEPTH <= content['depth']:
context['max_depth'] = True
context = merge_dict(context, additional_context) context = merge_dict(context, additional_context)
partial_mustache_helpers = {k: partial(v, content) for k, v in mustache_helpers.items()} partial_mustache_helpers = {k: partial(v, content) for k, v in mustache_helpers.items()}
context = merge_dict(context, partial_mustache_helpers) context = merge_dict(context, partial_mustache_helpers)
......
...@@ -21,6 +21,8 @@ import pystache_custom as pystache ...@@ -21,6 +21,8 @@ import pystache_custom as pystache
_FULLMODULES = None _FULLMODULES = None
_DISCUSSIONINFO = None _DISCUSSIONINFO = None
def extract(dic, keys): def extract(dic, keys):
return {k: dic.get(k) for k in keys} return {k: dic.get(k) for k in keys}
......
...@@ -38,6 +38,10 @@ ASKBOT_ENABLED = False ...@@ -38,6 +38,10 @@ ASKBOT_ENABLED = False
GENERATE_RANDOM_USER_CREDENTIALS = False GENERATE_RANDOM_USER_CREDENTIALS = False
PERFSTATS = False PERFSTATS = False
DISCUSSION_SETTINGS = {
'MAX_COMMENT_DEPTH': 2,
}
# Features # Features
MITX_FEATURES = { MITX_FEATURES = {
'SAMPLE' : False, 'SAMPLE' : False,
......
...@@ -51,7 +51,9 @@ ...@@ -51,7 +51,9 @@
{{/thread}} {{/thread}}
</div> </div>
<ul class="discussion-actions"> <ul class="discussion-actions">
<li><a class="discussion-link discussion-reply discussion-reply-{{content.type}}" href="javascript:void(0)">Reply</a></li> {{^max_depth}}
<li><a class="discussion-link discussion-reply discussion-reply-{{content.type}}" href="javascript:void(0)">Reply</a></li>
{{/max_depth}}
{{#thread}} {{#thread}}
<li><div class="follow-wrapper"><a class="discussion-link discussion-follow-thread" href="javascript:void(0)">Follow</a></div></li> <li><div class="follow-wrapper"><a class="discussion-link discussion-follow-thread" href="javascript:void(0)">Follow</a></div></li>
{{/thread}} {{/thread}}
......
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