Commit 97f1e042 by Ned Batchelder

Fix some 2-space indents

parent 999ed17e
...@@ -17,8 +17,7 @@ from auth.authz import _delete_course_group ...@@ -17,8 +17,7 @@ from auth.authz import _delete_course_group
class Command(BaseCommand): class Command(BaseCommand):
help = \ help = '''Delete a MongoDB backed course'''
'''Delete a MongoDB backed course'''
def handle(self, *args, **options): def handle(self, *args, **options):
if len(args) != 1 and len(args) != 2: if len(args) != 1 and len(args) != 2:
...@@ -28,19 +27,19 @@ class Command(BaseCommand): ...@@ -28,19 +27,19 @@ class Command(BaseCommand):
commit = False commit = False
if len(args) == 2: if len(args) == 2:
commit = args[1] == 'commit' commit = args[1] == 'commit'
if commit: if commit:
print 'Actually going to delete the course from DB....' print 'Actually going to delete the course from DB....'
ms = modulestore('direct') ms = modulestore('direct')
cs = contentstore() cs = contentstore()
if query_yes_no("Deleting course {0}. Confirm?".format(loc_str), default="no"): if query_yes_no("Deleting course {0}. Confirm?".format(loc_str), default="no"):
if query_yes_no("Are you sure. This action cannot be undone!", default="no"): if query_yes_no("Are you sure. This action cannot be undone!", default="no"):
loc = CourseDescriptor.id_to_location(loc_str) loc = CourseDescriptor.id_to_location(loc_str)
if delete_course(ms, cs, loc, commit) == True: if delete_course(ms, cs, loc, commit) == True:
print 'removing User permissions from course....' print 'removing User permissions from course....'
# in the django layer, we need to remove all the user permissions groups associated with this course # in the django layer, we need to remove all the user permissions groups associated with this course
if commit: if commit:
_delete_course_group(loc) _delete_course_group(loc)
...@@ -7,47 +7,47 @@ from json import dumps ...@@ -7,47 +7,47 @@ from json import dumps
def export_to_xml(modulestore, contentstore, course_location, root_dir, course_dir): def export_to_xml(modulestore, contentstore, course_location, root_dir, course_dir):
course = modulestore.get_item(course_location) course = modulestore.get_item(course_location)
fs = OSFS(root_dir) fs = OSFS(root_dir)
export_fs = fs.makeopendir(course_dir) export_fs = fs.makeopendir(course_dir)
xml = course.export_to_xml(export_fs) xml = course.export_to_xml(export_fs)
with export_fs.open('course.xml', 'w') as course_xml: with export_fs.open('course.xml', 'w') as course_xml:
course_xml.write(xml) course_xml.write(xml)
# export the static assets # export the static assets
contentstore.export_all_for_course(course_location, root_dir + '/' + course_dir + '/static/') contentstore.export_all_for_course(course_location, root_dir + '/' + course_dir + '/static/')
# export the static tabs # export the static tabs
export_extra_content(export_fs, modulestore, course_location, 'static_tab', 'tabs', '.html') export_extra_content(export_fs, modulestore, course_location, 'static_tab', 'tabs', '.html')
# export the custom tags # export the custom tags
export_extra_content(export_fs, modulestore, course_location, 'custom_tag_template', 'custom_tags') export_extra_content(export_fs, modulestore, course_location, 'custom_tag_template', 'custom_tags')
# export the course updates # export the course updates
export_extra_content(export_fs, modulestore, course_location, 'course_info', 'info', '.html') export_extra_content(export_fs, modulestore, course_location, 'course_info', 'info', '.html')
# export the grading policy # export the grading policy
policies_dir = export_fs.makeopendir('policies') policies_dir = export_fs.makeopendir('policies')
course_run_policy_dir = policies_dir.makeopendir(course.location.name) course_run_policy_dir = policies_dir.makeopendir(course.location.name)
if 'grading_policy' in course.definition['data']: if 'grading_policy' in course.definition['data']:
with course_run_policy_dir.open('grading_policy.json', 'w') as grading_policy: with course_run_policy_dir.open('grading_policy.json', 'w') as grading_policy:
grading_policy.write(dumps(course.definition['data']['grading_policy'])) grading_policy.write(dumps(course.definition['data']['grading_policy']))
# export all of the course metadata in policy.json # export all of the course metadata in policy.json
with course_run_policy_dir.open('policy.json', 'w') as course_policy: with course_run_policy_dir.open('policy.json', 'w') as course_policy:
policy = {} policy = {}
policy = {'course/' + course.location.name: course.metadata} policy = {'course/' + course.location.name: course.metadata}
course_policy.write(dumps(policy)) course_policy.write(dumps(policy))
def export_extra_content(export_fs, modulestore, course_location, category_type, dirname, file_suffix=''): def export_extra_content(export_fs, modulestore, course_location, category_type, dirname, file_suffix=''):
query_loc = Location('i4x', course_location.org, course_location.course, category_type, None) query_loc = Location('i4x', course_location.org, course_location.course, category_type, None)
items = modulestore.get_items(query_loc) items = modulestore.get_items(query_loc)
if len(items) > 0: if len(items) > 0:
item_dir = export_fs.makeopendir(dirname) item_dir = export_fs.makeopendir(dirname)
for item in items: for item in items:
with item_dir.open(item.location.name + file_suffix, 'w') as item_file: with item_dir.open(item.location.name + file_suffix, 'w') as item_file:
item_file.write(item.definition['data'].encode('utf8')) item_file.write(item.definition['data'].encode('utf8'))
...@@ -11,7 +11,7 @@ from django.contrib.auth.models import User ...@@ -11,7 +11,7 @@ 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
from courseware.courses import get_course_with_access from courseware.courses import get_course_with_access
from course_groups.cohorts import is_course_cohorted, get_cohort_id, is_commentable_cohorted, get_cohorted_commentables, get_cohort, get_course_cohorts, get_cohort_by_id from course_groups.cohorts import is_course_cohorted, get_cohort_id, is_commentable_cohorted, get_cohorted_commentables, get_cohort, get_course_cohorts, get_cohort_by_id
from courseware.access import has_access from courseware.access import has_access
from urllib import urlencode from urllib import urlencode
...@@ -64,24 +64,23 @@ def get_threads(request, course_id, discussion_id=None, per_page=THREADS_PER_PAG ...@@ -64,24 +64,23 @@ def get_threads(request, course_id, discussion_id=None, per_page=THREADS_PER_PAG
#there are 2 dimensions to consider when executing a search with respect to group id #there are 2 dimensions to consider when executing a search with respect to group id
#is user a moderator #is user a moderator
#did the user request a group #did the user request a group
#if the user requested a group explicitly, give them that group, othewrise, if mod, show all, else if student, use cohort #if the user requested a group explicitly, give them that group, othewrise, if mod, show all, else if student, use cohort
group_id = request.GET.get('group_id') group_id = request.GET.get('group_id')
if group_id == "all": if group_id == "all":
group_id = None group_id = None
if not group_id: if not group_id:
if not cached_has_permission(request.user, "see_all_cohorts", course_id): if not cached_has_permission(request.user, "see_all_cohorts", course_id):
group_id = get_cohort_id(request.user, course_id) group_id = get_cohort_id(request.user, course_id)
if group_id: if group_id:
default_query_params["group_id"] = group_id default_query_params["group_id"] = group_id
#so by default, a moderator sees all items, and a student sees his cohort #so by default, a moderator sees all items, and a student sees his cohort
query_params = merge_dict(default_query_params, query_params = merge_dict(default_query_params,
strip_none(extract(request.GET, strip_none(extract(request.GET,
['page', 'sort_key', ['page', 'sort_key',
...@@ -89,7 +88,7 @@ def get_threads(request, course_id, discussion_id=None, per_page=THREADS_PER_PAG ...@@ -89,7 +88,7 @@ def get_threads(request, course_id, discussion_id=None, per_page=THREADS_PER_PAG
'tags', 'commentable_ids']))) 'tags', 'commentable_ids'])))
threads, page, num_pages = cc.Thread.search(query_params) threads, page, num_pages = cc.Thread.search(query_params)
#now add the group name if the thread has a group id #now add the group name if the thread has a group id
for thread in threads: for thread in threads:
if thread.get('group_id'): if thread.get('group_id'):
...@@ -106,7 +105,6 @@ def get_threads(request, course_id, discussion_id=None, per_page=THREADS_PER_PAG ...@@ -106,7 +105,6 @@ def get_threads(request, course_id, discussion_id=None, per_page=THREADS_PER_PAG
def inline_discussion(request, course_id, discussion_id): def inline_discussion(request, course_id, discussion_id):
""" """
Renders JSON for DiscussionModules Renders JSON for DiscussionModules
""" """
...@@ -128,7 +126,7 @@ def inline_discussion(request, course_id, discussion_id): ...@@ -128,7 +126,7 @@ def inline_discussion(request, course_id, discussion_id):
allow_anonymous = course.metadata.get("allow_anonymous", True) allow_anonymous = course.metadata.get("allow_anonymous", True)
allow_anonymous_to_peers = course.metadata.get("allow_anonymous_to_peers", False) allow_anonymous_to_peers = course.metadata.get("allow_anonymous_to_peers", False)
#since inline is all one commentable, only show or allow the choice of cohorts #since inline is all one commentable, only show or allow the choice of cohorts
#if the commentable is cohorted, otherwise everything is not cohorted #if the commentable is cohorted, otherwise everything is not cohorted
#and no one has the option of choosing a cohort #and no one has the option of choosing a cohort
...@@ -138,18 +136,18 @@ def inline_discussion(request, course_id, discussion_id): ...@@ -138,18 +136,18 @@ def inline_discussion(request, course_id, discussion_id):
cohorts_list = list() cohorts_list = list()
if is_cohorted: if is_cohorted:
cohorts_list.append({'name':'All Groups','id':None}) cohorts_list.append({'name':'All Groups','id':None})
#if you're a mod, send all cohorts and let you pick #if you're a mod, send all cohorts and let you pick
if is_moderator: if is_moderator:
cohorts = get_course_cohorts(course_id) cohorts = get_course_cohorts(course_id)
for c in cohorts: for c in cohorts:
cohorts_list.append({'name':c.name, 'id':c.id}) cohorts_list.append({'name':c.name, 'id':c.id})
else: else:
#students don't get to choose #students don't get to choose
cohorts_list = None cohorts_list = None
return utils.JsonResponse({ return utils.JsonResponse({
'discussion_data': map(utils.safe_content, threads), 'discussion_data': map(utils.safe_content, threads),
...@@ -168,7 +166,6 @@ def inline_discussion(request, course_id, discussion_id): ...@@ -168,7 +166,6 @@ def inline_discussion(request, course_id, discussion_id):
@login_required @login_required
def forum_form_discussion(request, course_id): def forum_form_discussion(request, course_id):
""" """
Renders the main Discussion page, potentially filtered by a search query Renders the main Discussion page, potentially filtered by a search query
""" """
...@@ -210,7 +207,7 @@ def forum_form_discussion(request, course_id): ...@@ -210,7 +207,7 @@ def forum_form_discussion(request, course_id):
#) #)
cohorts = get_course_cohorts(course_id) cohorts = get_course_cohorts(course_id)
cohorted_commentables = get_cohorted_commentables(course_id) cohorted_commentables = get_cohorted_commentables(course_id)
user_cohort_id = get_cohort_id(request.user, course_id) user_cohort_id = get_cohort_id(request.user, course_id)
context = { context = {
...@@ -233,7 +230,7 @@ def forum_form_discussion(request, course_id): ...@@ -233,7 +230,7 @@ def forum_form_discussion(request, course_id):
'is_course_cohorted': is_course_cohorted(course_id) 'is_course_cohorted': is_course_cohorted(course_id)
} }
# print "start rendering.." # print "start rendering.."
return render_to_response('discussion/index.html', context) return render_to_response('discussion/index.html', context)
@login_required @login_required
...@@ -251,7 +248,7 @@ def single_thread(request, course_id, discussion_id, thread_id): ...@@ -251,7 +248,7 @@ def single_thread(request, course_id, discussion_id, thread_id):
if request.is_ajax(): if request.is_ajax():
courseware_context = get_courseware_context(thread, course) courseware_context = get_courseware_context(thread, course)
annotated_content_info = utils.get_annotated_content_infos(course_id, thread, request.user, user_info=user_info) annotated_content_info = utils.get_annotated_content_infos(course_id, thread, request.user, user_info=user_info)
context = {'thread': thread.to_dict(), 'course_id': course_id} context = {'thread': thread.to_dict(), 'course_id': course_id}
# TODO: Remove completely or switch back to server side rendering # TODO: Remove completely or switch back to server side rendering
...@@ -282,7 +279,7 @@ def single_thread(request, course_id, discussion_id, thread_id): ...@@ -282,7 +279,7 @@ def single_thread(request, course_id, discussion_id, thread_id):
if courseware_context: if courseware_context:
thread.update(courseware_context) thread.update(courseware_context)
if thread.get('group_id') and not thread.get('group_name'): if thread.get('group_id') and not thread.get('group_name'):
thread['group_name'] = get_cohort_by_id(course_id, thread.get('group_id')).name thread['group_name'] = get_cohort_by_id(course_id, thread.get('group_id')).name
threads = [utils.safe_content(thread) for thread in threads] threads = [utils.safe_content(thread) for thread in threads]
...@@ -297,7 +294,7 @@ def single_thread(request, course_id, discussion_id, thread_id): ...@@ -297,7 +294,7 @@ def single_thread(request, course_id, discussion_id, thread_id):
#) #)
annotated_content_info = utils.get_metadata_for_threads(course_id, threads, request.user, user_info) annotated_content_info = utils.get_metadata_for_threads(course_id, threads, request.user, user_info)
cohorts = get_course_cohorts(course_id) cohorts = get_course_cohorts(course_id)
cohorted_commentables = get_cohorted_commentables(course_id) cohorted_commentables = get_cohorted_commentables(course_id)
user_cohort = get_cohort_id(request.user, course_id) user_cohort = get_cohort_id(request.user, course_id)
......
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