mustache_helpers.py 938 Bytes
Newer Older
1
from django.utils.translation import ugettext as _
2 3 4
import django.core.urlresolvers as urlresolvers
import sys
import inspect
5

6 7
# This method is used to pluralize the words "discussion" and "comment"
# which is why you need to tack on an "s" for the case of 0 or two or more.
Calen Pennington committed
8 9


10 11
def pluralize(content, text):
    num, word = text.split(' ')
Rocky Duan committed
12 13
    num = int(num or '0')
    if num >= 2 or num == 0:
14
        return word + 's'
15
    else:
16
        return word
17

Calen Pennington committed
18

19
def url_for_user(content, user_id):
20
    return urlresolvers.reverse('django_comment_client.forum.views.user_profile', args=[content['course_id'], user_id])
21

Calen Pennington committed
22

23 24
def close_thread_text(content):
    if content.get('closed'):
25
        return _('Re-open thread')
26
    else:
27
        return _('Close thread')
28

29 30 31 32
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('_')}