Skip to content

Commit

Permalink
Merge pull request openedx#520 from MITx/feature/rocky/discussion
Browse files Browse the repository at this point in the history
add user profile and fixed edit
  • Loading branch information
David Ormsbee committed Aug 23, 2012
2 parents e30e284 + 66935e0 commit 35a89b8
Show file tree
Hide file tree
Showing 21 changed files with 701 additions and 678 deletions.
21 changes: 12 additions & 9 deletions lms/djangoapps/django_comment_client/base/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from mitxmako.shortcuts import render_to_response, render_to_string
from courseware.courses import get_course_with_access


from django_comment_client.utils import JsonResponse, JsonError, extract

from django_comment_client.permissions import check_permissions_by_view
Expand Down Expand Up @@ -282,7 +281,7 @@ def update_moderator_status(request, course_id, user_id):
'course_id': course_id,
'user': request.user,
'django_user': user,
'discussion_user': discussion_user.to_dict(),
'profiled_user': discussion_user.to_dict(),
}
return JsonResponse({
'html': render_to_string('discussion/ajax_user_profile.html', context)
Expand All @@ -298,10 +297,13 @@ def search_similar_threads(request, course_id, commentable_id):
'text': text,
'commentable_id': commentable_id,
}
result = cc.search_similar_threads(course_id, recursive=False, query_params=query_params)
return JsonResponse(result)
threads = cc.search_similar_threads(course_id, recursive=False, query_params=query_params)
else:
return JsonResponse([])
theads = []
context = { 'threads': map(utils.extend_content, threads) }
return JsonResponse({
'html': render_to_string('discussion/_similar_posts.html', context)
})

@require_GET
def tags_autocomplete(request, course_id):
Expand Down Expand Up @@ -334,8 +336,8 @@ def upload(request, course_id):#ajax upload file to a question or answer
# check file type
f = request.FILES['file-upload']
file_extension = os.path.splitext(f.name)[1].lower()
if not file_extension in settings.DISCUSSION_ALLOWED_UPLOAD_FILE_TYPES:
file_types = "', '".join(settings.DISCUSSION_ALLOWED_UPLOAD_FILE_TYPES)
if not file_extension in cc_settings.ALLOWED_UPLOAD_FILE_TYPES:
file_types = "', '".join(cc_settings.ALLOWED_UPLOAD_FILE_TYPES)
msg = _("allowed file types are '%(file_types)s'") % \
{'file_types': file_types}
raise exceptions.PermissionDenied(msg)
Expand All @@ -354,15 +356,16 @@ def upload(request, course_id):#ajax upload file to a question or answer
# check file size
# byte
size = file_storage.size(new_file_name)
if size > settings.ASKBOT_MAX_UPLOAD_FILE_SIZE:
if size > cc_settings.MAX_UPLOAD_FILE_SIZE:
file_storage.delete(new_file_name)
msg = _("maximum upload file size is %(file_size)sK") % \
{'file_size': settings.ASKBOT_MAX_UPLOAD_FILE_SIZE}
{'file_size': cc_settings.MAX_UPLOAD_FILE_SIZE}
raise exceptions.PermissionDenied(msg)

except exceptions.PermissionDenied, e:
error = unicode(e)
except Exception, e:
print e
logging.critical(unicode(e))
error = _('Error uploading file. Please contact the site administrator. Thank you.')

Expand Down
7 changes: 5 additions & 2 deletions lms/djangoapps/django_comment_client/forum/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def infogetter(thread):
'base_url': base_url,
'query_params': strip_blank(strip_none(extract(query_params, ['page', 'sort_key', 'sort_order', 'tags', 'text']))),
'annotated_content_info': json.dumps(annotated_content_info),
'discussion_data': json.dumps({ discussion_id: threads }),
'discussion_data': json.dumps({ (discussion_id or user_id): threads })
}
context = dict(context.items() + query_params.items())
return render_to_string(template, context)
Expand Down Expand Up @@ -250,7 +250,10 @@ def user_profile(request, course_id, user_id):
content = render_user_discussion(request, course_id, threads, user_id=user_id, query_params=query_params)

if request.is_ajax():
return utils.HtmlResponse(content)
return utils.JsonResponse({
'html': content,
'discussionData': threads,
})
else:
context = {
'course': course,
Expand Down
18 changes: 2 additions & 16 deletions lms/djangoapps/django_comment_client/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import os

def pluralize(singular_term, count):
if int(count) >= 2:
if int(count) >= 2 or int(count) == 0:
return singular_term + 's'
return singular_term

Expand All @@ -33,24 +33,10 @@ def include_mustache_templates():
file_contents = map(read_file, filter(valid_file_name, os.listdir(mustache_dir)))
return '\n'.join(map(wrap_in_tag, map(strip_file_name, file_contents)))

def permalink(content):
if content['type'] == 'thread':
return reverse('django_comment_client.forum.views.single_thread',
args=[content['course_id'], content['commentable_id'], content['id']])
else:
return reverse('django_comment_client.forum.views.single_thread',
args=[content['course_id'], content['commentable_id'], content['thread_id']]) + '#' + content['id']

def render_content(content, additional_context={}):
content_info = {
'displayed_title': content.get('highlighted_title') or content.get('title', ''),
'displayed_body': content.get('highlighted_body') or content.get('body', ''),
'raw_tags': ','.join(content.get('tags', [])),
'permalink': permalink(content),
}

context = {
'content': merge_dict(content, content_info),
'content': extend_content(content),
content['type']: True,
}
context = merge_dict(context, additional_context)
Expand Down
3 changes: 2 additions & 1 deletion lms/djangoapps/django_comment_client/mustache_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

def pluralize(content, text):
num, word = text.split(' ')
if int(num or '0') >= 2:
num = int(num or '0')
if num >= 2 or num == 0:
return word + 's'
else:
return word
Expand Down
10 changes: 10 additions & 0 deletions lms/djangoapps/django_comment_client/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.conf import settings

MAX_COMMENT_DEPTH = None
MAX_UPLOAD_FILE_SIZE = 1024 * 1024 #result in bytes
ALLOWED_UPLOAD_FILE_TYPES = ('.jpg', '.jpeg', '.gif', '.bmp', '.png', '.tiff')

if hasattr(settings, 'DISCUSSION_SETTINGS'):
MAX_COMMENT_DEPTH = settings.DISCUSSION_SETTINGS.get('MAX_COMMENT_DEPTH')
MAX_UPLOAD_FILE_SIZE = settings.DISCUSSION_SETTINGS.get('MAX_UPLOAD_FILE_SIZE') or MAX_UPLOAD_FILE_SIZE
ALLOWED_UPLOAD_FILE_TYPES = settings.DISCUSSION_SETTINGS.get('ALLOWED_UPLOAD_FILE_TYPES') or ALLOWED_UPLOAD_FILE_TYPES
17 changes: 17 additions & 0 deletions lms/djangoapps/django_comment_client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,20 @@ def url_for_tags(course_id, tags):
def render_mustache(template_name, dictionary, *args, **kwargs):
template = middleware.lookup['main'].get_template(template_name).source
return pystache.render(template, dictionary)

def permalink(content):
if content['type'] == 'thread':
return reverse('django_comment_client.forum.views.single_thread',
args=[content['course_id'], content['commentable_id'], content['id']])
else:
return reverse('django_comment_client.forum.views.single_thread',
args=[content['course_id'], content['commentable_id'], content['thread_id']]) + '#' + content['id']

def extend_content(content):
content_info = {
'displayed_title': content.get('highlighted_title') or content.get('title', ''),
'displayed_body': content.get('highlighted_body') or content.get('body', ''),
'raw_tags': ','.join(content.get('tags', [])),
'permalink': permalink(content),
}
return merge_dict(content, content_info)
Loading

0 comments on commit 35a89b8

Please sign in to comment.