mustache_helpers.py 939 Bytes
Newer Older
1 2
from .utils import url_for_tags as _url_for_tags

3
import django.core.urlresolvers as urlresolvers
4
import urllib
5 6
import sys
import inspect
7 8 9

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

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

19
def url_for_tags(content, tags): # assume that attribute 'tags' is in the format u'a, b, c'
20
    return _url_for_tags(content['course_id'], tags)
21 22 23 24 25 26 27

def close_thread_text(content):
    if content.get('closed'):
        return 'Re-open thread'
    else:
        return 'Close thread'

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