diff --git a/lms/djangoapps/django_comment_client/mustache_helpers.py b/lms/djangoapps/django_comment_client/mustache_helpers.py index 48a38be29b..b3b5daaa01 100644 --- a/lms/djangoapps/django_comment_client/mustache_helpers.py +++ b/lms/djangoapps/django_comment_client/mustache_helpers.py @@ -1,5 +1,7 @@ -from django.core.urlresolvers import reverse +import django.core.urlresolvers as urlresolvers import urllib +import sys +import inspect def pluralize(content, text): num, word = text.split(' ') @@ -9,10 +11,10 @@ def pluralize(content, text): return num + ' ' + word def url_for_user(content, user_id): - return reverse('django_comment_client.forum.views.user_profile', args=[content['course_id'], user_id]) + return urlresolvers.reverse('django_comment_client.forum.views.user_profile', args=[content['course_id'], user_id]) -def url_for_tags(content, tags): # assume that tags is in the format u'a, b, c' - return reverse('django_comment_client.forum.views.forum_form_discussion', args=[content['course_id']]) + '?' + urllib.urlencode({'tags': tags}) +def url_for_tags(content, tags): # assume that attribute 'tags' is in the format u'a, b, c' + return urlresolvers.reverse('django_comment_client.forum.views.forum_form_discussion', args=[content['course_id']]) + '?' + urllib.urlencode({'tags': tags}) def close_thread_text(content): if content.get('closed'): @@ -20,9 +22,7 @@ def close_thread_text(content): else: return 'Close thread' -mustache_helpers = { - 'pluralize': pluralize, - 'url_for_tags': url_for_tags, - 'url_for_user': url_for_user, - 'close_thread_text': close_thread_text, -} +current_module = sys.modules[__name__] +all_functions = inspect.getmembers(current_module, inspect.isfunction) + +mustache_helpers = {k: v for k, v in all_functions if not k.startswith('_')} diff --git a/lms/lib/comment_client/settings.py b/lms/lib/comment_client/settings.py index f64726335f..75a107d0c9 100644 --- a/lms/lib/comment_client/settings.py +++ b/lms/lib/comment_client/settings.py @@ -6,3 +6,5 @@ else: SERVICE_HOST = 'http://localhost:4567' PREFIX = SERVICE_HOST + '/api/v1' + +API_KEY = "PUT_YOUR_API_KEY_HERE" diff --git a/lms/lib/comment_client/utils.py b/lms/lib/comment_client/utils.py index 16b1952303..4e8beec079 100644 --- a/lms/lib/comment_client/utils.py +++ b/lms/lib/comment_client/utils.py @@ -1,5 +1,6 @@ import requests import json +import settings def strip_none(dic): return dict([(k, v) for k, v in dic.iteritems() if v is not None]) @@ -19,6 +20,7 @@ def merge_dict(dic1, dic2): return dict(dic1.items() + dic2.items()) def perform_request(method, url, data_or_params=None, *args, **kwargs): + data_or_params['api_key'] = settings.API_KEY if method in ['post', 'put', 'patch']: response = requests.request(method, url, data=data_or_params) else: