Commit 9b1ae9f9 by Carlos Andrés Rocha

Merge pull request #1583 from MITx/fix/ned/clean-ups

Fix/ned/clean ups
parents 3a748b1e 7c8a9022
...@@ -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)
...@@ -13,7 +13,7 @@ def query_yes_no(question, default="yes"): ...@@ -13,7 +13,7 @@ def query_yes_no(question, default="yes"):
""" """
valid = {"yes":True, "y":True, "ye":True, valid = {"yes":True, "y":True, "ye":True,
"no":False, "n":False} "no":False, "n":False}
if default == None: if default is None:
prompt = " [y/n] " prompt = " [y/n] "
elif default == "yes": elif default == "yes":
prompt = " [Y/n] " prompt = " [Y/n] "
......
...@@ -115,7 +115,7 @@ def get_date_for_press(publish_date): ...@@ -115,7 +115,7 @@ def get_date_for_press(publish_date):
def press(request): def press(request):
json_articles = cache.get("student_press_json_articles") json_articles = cache.get("student_press_json_articles")
if json_articles == None: if json_articles is None:
if hasattr(settings, 'RSS_URL'): if hasattr(settings, 'RSS_URL'):
content = urllib.urlopen(settings.PRESS_URL).read() content = urllib.urlopen(settings.PRESS_URL).read()
json_articles = json.loads(content) json_articles = json.loads(content)
...@@ -301,7 +301,7 @@ def change_enrollment(request): ...@@ -301,7 +301,7 @@ def change_enrollment(request):
action = request.POST.get("enrollment_action", "") action = request.POST.get("enrollment_action", "")
course_id = request.POST.get("course_id", None) course_id = request.POST.get("course_id", None)
if course_id == None: if course_id is None:
return HttpResponse(json.dumps({'success': False, return HttpResponse(json.dumps({'success': False,
'error': 'There was an error receiving the course id.'})) 'error': 'There was an error receiving the course id.'}))
...@@ -1203,7 +1203,7 @@ def _get_news(top=None): ...@@ -1203,7 +1203,7 @@ def _get_news(top=None):
"Return the n top news items on settings.RSS_URL" "Return the n top news items on settings.RSS_URL"
feed_data = cache.get("students_index_rss_feed_data") feed_data = cache.get("students_index_rss_feed_data")
if feed_data == None: if feed_data is None:
if hasattr(settings, 'RSS_URL'): if hasattr(settings, 'RSS_URL'):
feed_data = urllib.urlopen(settings.RSS_URL).read() feed_data = urllib.urlopen(settings.RSS_URL).read()
else: else:
......
...@@ -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'))
...@@ -524,7 +524,7 @@ class PeerGradingModule(XModule): ...@@ -524,7 +524,7 @@ class PeerGradingModule(XModule):
''' '''
Show individual problem interface Show individual problem interface
''' '''
if get == None or get.get('location') == None: if get is None or get.get('location') is None:
if not self.use_for_single_location: if not self.use_for_single_location:
#This is an error case, because it must be set to use a single location to be called without get parameters #This is an error case, because it must be set to use a single location to be called without get parameters
#This is a dev_facing_error #This is a dev_facing_error
......
...@@ -49,7 +49,7 @@ def course_wiki_redirect(request, course_id): ...@@ -49,7 +49,7 @@ def course_wiki_redirect(request, course_id):
if not course_slug: if not course_slug:
log.exception("This course is improperly configured. The slug cannot be empty.") log.exception("This course is improperly configured. The slug cannot be empty.")
valid_slug = False valid_slug = False
if re.match('^[-\w\.]+$', course_slug) == None: if re.match('^[-\w\.]+$', course_slug) is None:
log.exception("This course is improperly configured. The slug can only contain letters, numbers, periods or hyphens.") log.exception("This course is improperly configured. The slug can only contain letters, numbers, periods or hyphens.")
valid_slug = False valid_slug = False
......
...@@ -140,7 +140,7 @@ def grade(student, request, course, student_module_cache=None, keep_raw_scores=F ...@@ -140,7 +140,7 @@ def grade(student, request, course, student_module_cache=None, keep_raw_scores=F
grading_context = course.grading_context grading_context = course.grading_context
raw_scores = [] raw_scores = []
if student_module_cache == None: if student_module_cache is None:
student_module_cache = StudentModuleCache(course.id, student, grading_context['all_descriptors']) student_module_cache = StudentModuleCache(course.id, student, grading_context['all_descriptors'])
totaled_scores = {} totaled_scores = {}
......
...@@ -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)
......
...@@ -68,7 +68,7 @@ def get_course_settings(coursename): ...@@ -68,7 +68,7 @@ def get_course_settings(coursename):
def is_valid_course(coursename): def is_valid_course(coursename):
return get_course_settings(coursename) != None return get_course_settings(coursename) is not None
def get_course_property(coursename, property): def get_course_property(coursename, property):
......
...@@ -236,7 +236,7 @@ def history(request, article_path, page=1, course_id=None): ...@@ -236,7 +236,7 @@ def history(request, article_path, page=1, course_id=None):
page_size = 10 page_size = 10
if page == None: if page is None:
page = 1 page = 1
try: try:
p = int(page) p = int(page)
...@@ -310,7 +310,7 @@ def revision_feed(request, page=1, namespace=None, course_id=None): ...@@ -310,7 +310,7 @@ def revision_feed(request, page=1, namespace=None, course_id=None):
page_size = 10 page_size = 10
if page == None: if page is None:
page = 1 page = 1
try: try:
p = int(page) p = int(page)
......
...@@ -23,7 +23,7 @@ class Model(object): ...@@ -23,7 +23,7 @@ class Model(object):
try: try:
return self.attributes[name] return self.attributes[name]
except KeyError: except KeyError:
if self.retrieved or self.id == None: if self.retrieved or self.id is None:
raise AttributeError("Field {0} does not exist".format(name)) raise AttributeError("Field {0} does not exist".format(name))
self.retrieve() self.retrieve()
return self.__getattr__(name) return self.__getattr__(name)
......
...@@ -70,7 +70,7 @@ StrPrinter._print_hat = _print_hat ...@@ -70,7 +70,7 @@ StrPrinter._print_hat = _print_hat
def to_latex(x): def to_latex(x):
if x == None: return '' if x is None: return ''
# LatexPrinter._print_dot = _print_dot # LatexPrinter._print_dot = _print_dot
xs = latex(x) xs = latex(x)
xs = xs.replace(r'\XI', 'XI') # workaround for strange greek xs = xs.replace(r'\XI', 'XI') # workaround for strange greek
...@@ -278,7 +278,7 @@ class formula(object): ...@@ -278,7 +278,7 @@ class formula(object):
if self.the_sympy: return self.the_sympy if self.the_sympy: return self.the_sympy
if xml == None: # root if xml is None: # root
if not self.is_mathml(): if not self.is_mathml():
return my_sympify(self.expr) return my_sympify(self.expr)
if self.is_presentation_mathml(): if self.is_presentation_mathml():
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<%page args="active_page=None" /> <%page args="active_page=None" />
<% <%
if active_page == None and active_page_context is not UNDEFINED: if active_page is None and active_page_context is not UNDEFINED:
# If active_page is not passed in as an argument, it may be in the context as active_page_context # If active_page is not passed in as an argument, it may be in the context as active_page_context
active_page = active_page_context active_page = active_page_context
......
<%namespace name='static' file='static_content.html'/> <%namespace name='static' file='static_content.html'/>
<h2 class="problem-header"> <h2 class="problem-header">
${ problem['name'] } ${ problem['name'] }
% if problem['weight'] != 1 and problem['weight'] != None: % if problem['weight'] != 1 and problem['weight'] is not None:
: ${ problem['weight'] } points : ${ problem['weight'] } points
% endif % endif
</h2> </h2>
...@@ -30,4 +30,4 @@ ...@@ -30,4 +30,4 @@
</section> </section>
% endif % endif
</section> </section>
</section> </section>
\ No newline at end of file
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