Commit dd82ea57 by Brian Talbot

Merge branch 'master' into feature/btalbot/studio-alerts

parents ec90d349 9b1ae9f9
......@@ -17,8 +17,7 @@ from auth.authz import _delete_course_group
class Command(BaseCommand):
help = \
'''Delete a MongoDB backed course'''
help = '''Delete a MongoDB backed course'''
def handle(self, *args, **options):
if len(args) != 1 and len(args) != 2:
......@@ -28,19 +27,19 @@ class Command(BaseCommand):
commit = False
if len(args) == 2:
commit = args[1] == 'commit'
commit = args[1] == 'commit'
if commit:
print 'Actually going to delete the course from DB....'
print 'Actually going to delete the course from DB....'
ms = modulestore('direct')
cs = contentstore()
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"):
loc = CourseDescriptor.id_to_location(loc_str)
if delete_course(ms, cs, loc, commit) == True:
print 'removing User permissions from course....'
# in the django layer, we need to remove all the user permissions groups associated with this course
if commit:
_delete_course_group(loc)
if query_yes_no("Are you sure. This action cannot be undone!", default="no"):
loc = CourseDescriptor.id_to_location(loc_str)
if delete_course(ms, cs, loc, commit) == True:
print 'removing User permissions from course....'
# in the django layer, we need to remove all the user permissions groups associated with this course
if commit:
_delete_course_group(loc)
......@@ -13,7 +13,7 @@ def query_yes_no(question, default="yes"):
"""
valid = {"yes":True, "y":True, "ye":True,
"no":False, "n":False}
if default == None:
if default is None:
prompt = " [y/n] "
elif default == "yes":
prompt = " [Y/n] "
......
......@@ -115,7 +115,7 @@ def get_date_for_press(publish_date):
def press(request):
json_articles = cache.get("student_press_json_articles")
if json_articles == None:
if json_articles is None:
if hasattr(settings, 'RSS_URL'):
content = urllib.urlopen(settings.PRESS_URL).read()
json_articles = json.loads(content)
......@@ -301,7 +301,7 @@ def change_enrollment(request):
action = request.POST.get("enrollment_action", "")
course_id = request.POST.get("course_id", None)
if course_id == None:
if course_id is None:
return HttpResponse(json.dumps({'success': False,
'error': 'There was an error receiving the course id.'}))
......@@ -1203,7 +1203,7 @@ def _get_news(top=None):
"Return the n top news items on settings.RSS_URL"
feed_data = cache.get("students_index_rss_feed_data")
if feed_data == None:
if feed_data is None:
if hasattr(settings, 'RSS_URL'):
feed_data = urllib.urlopen(settings.RSS_URL).read()
else:
......
......@@ -7,47 +7,47 @@ from json import dumps
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)
export_fs = fs.makeopendir(course_dir)
fs = OSFS(root_dir)
export_fs = fs.makeopendir(course_dir)
xml = course.export_to_xml(export_fs)
with export_fs.open('course.xml', 'w') as course_xml:
course_xml.write(xml)
xml = course.export_to_xml(export_fs)
with export_fs.open('course.xml', 'w') as course_xml:
course_xml.write(xml)
# export the static assets
contentstore.export_all_for_course(course_location, root_dir + '/' + course_dir + '/static/')
# export the static assets
contentstore.export_all_for_course(course_location, root_dir + '/' + course_dir + '/static/')
# export the static tabs
export_extra_content(export_fs, modulestore, course_location, 'static_tab', 'tabs', '.html')
# export the static tabs
export_extra_content(export_fs, modulestore, course_location, 'static_tab', 'tabs', '.html')
# export the custom tags
export_extra_content(export_fs, modulestore, course_location, 'custom_tag_template', 'custom_tags')
# export the custom tags
export_extra_content(export_fs, modulestore, course_location, 'custom_tag_template', 'custom_tags')
# export the course updates
export_extra_content(export_fs, modulestore, course_location, 'course_info', 'info', '.html')
# export the course updates
export_extra_content(export_fs, modulestore, course_location, 'course_info', 'info', '.html')
# export the grading policy
policies_dir = export_fs.makeopendir('policies')
course_run_policy_dir = policies_dir.makeopendir(course.location.name)
if 'grading_policy' in course.definition['data']:
with course_run_policy_dir.open('grading_policy.json', 'w') as grading_policy:
grading_policy.write(dumps(course.definition['data']['grading_policy']))
# export the grading policy
policies_dir = export_fs.makeopendir('policies')
course_run_policy_dir = policies_dir.makeopendir(course.location.name)
if 'grading_policy' in course.definition['data']:
with course_run_policy_dir.open('grading_policy.json', 'w') as grading_policy:
grading_policy.write(dumps(course.definition['data']['grading_policy']))
# export all of the course metadata in policy.json
with course_run_policy_dir.open('policy.json', 'w') as course_policy:
policy = {}
policy = {'course/' + course.location.name: course.metadata}
course_policy.write(dumps(policy))
# export all of the course metadata in policy.json
with course_run_policy_dir.open('policy.json', 'w') as course_policy:
policy = {}
policy = {'course/' + course.location.name: course.metadata}
course_policy.write(dumps(policy))
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)
items = modulestore.get_items(query_loc)
if len(items) > 0:
item_dir = export_fs.makeopendir(dirname)
for item in items:
with item_dir.open(item.location.name + file_suffix, 'w') as item_file:
item_file.write(item.definition['data'].encode('utf8'))
query_loc = Location('i4x', course_location.org, course_location.course, category_type, None)
items = modulestore.get_items(query_loc)
if len(items) > 0:
item_dir = export_fs.makeopendir(dirname)
for item in items:
with item_dir.open(item.location.name + file_suffix, 'w') as item_file:
item_file.write(item.definition['data'].encode('utf8'))
......@@ -524,7 +524,7 @@ class PeerGradingModule(XModule):
'''
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:
#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
......
......@@ -49,7 +49,7 @@ def course_wiki_redirect(request, course_id):
if not course_slug:
log.exception("This course is improperly configured. The slug cannot be empty.")
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.")
valid_slug = False
......
......@@ -140,7 +140,7 @@ def grade(student, request, course, student_module_cache=None, keep_raw_scores=F
grading_context = course.grading_context
raw_scores = []
if student_module_cache == None:
if student_module_cache is None:
student_module_cache = StudentModuleCache(course.id, student, grading_context['all_descriptors'])
totaled_scores = {}
......
......@@ -91,7 +91,6 @@ def create_thread(request, course_id, commentable_id):
'user_id': request.user.id,
})
user = cc.User.from_django_user(request.user)
#kevinchugh because the new requirement is that all groups will be determined
......@@ -112,8 +111,8 @@ def create_thread(request, course_id, commentable_id):
# regular users always post with their own id.
group_id = user_group_id
if group_id:
thread.update_attributes(group_id=group_id)
if group_id:
thread.update_attributes(group_id=group_id)
thread.save()
......
......@@ -11,7 +11,7 @@ from django.contrib.auth.models import User
from mitxmako.shortcuts import render_to_response, render_to_string
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 urllib import urlencode
......@@ -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
#is user a moderator
#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
group_id = request.GET.get('group_id')
if group_id == "all":
group_id = None
if not group_id:
if not cached_has_permission(request.user, "see_all_cohorts", course_id):
group_id = get_cohort_id(request.user, course_id)
if group_id:
default_query_params["group_id"] = group_id
#so by default, a moderator sees all items, and a student sees his cohort
query_params = merge_dict(default_query_params,
strip_none(extract(request.GET,
['page', 'sort_key',
......@@ -89,7 +88,7 @@ def get_threads(request, course_id, discussion_id=None, per_page=THREADS_PER_PAG
'tags', 'commentable_ids'])))
threads, page, num_pages = cc.Thread.search(query_params)
#now add the group name if the thread has a group id
for thread in threads:
if thread.get('group_id'):
......@@ -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):
"""
Renders JSON for DiscussionModules
"""
......@@ -128,7 +126,7 @@ def inline_discussion(request, course_id, discussion_id):
allow_anonymous = course.metadata.get("allow_anonymous", True)
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
#if the commentable is cohorted, otherwise everything is not cohorted
#and no one has the option of choosing a cohort
......@@ -138,18 +136,18 @@ def inline_discussion(request, course_id, discussion_id):
cohorts_list = list()
if is_cohorted:
cohorts_list.append({'name':'All Groups','id':None})
#if you're a mod, send all cohorts and let you pick
if is_moderator:
cohorts = get_course_cohorts(course_id)
for c in cohorts:
cohorts_list.append({'name':c.name, 'id':c.id})
else:
#students don't get to choose
cohorts_list = None
cohorts_list.append({'name':'All Groups','id':None})
#if you're a mod, send all cohorts and let you pick
if is_moderator:
cohorts = get_course_cohorts(course_id)
for c in cohorts:
cohorts_list.append({'name':c.name, 'id':c.id})
else:
#students don't get to choose
cohorts_list = None
return utils.JsonResponse({
'discussion_data': map(utils.safe_content, threads),
......@@ -168,7 +166,6 @@ def inline_discussion(request, course_id, discussion_id):
@login_required
def forum_form_discussion(request, course_id):
"""
Renders the main Discussion page, potentially filtered by a search query
"""
......@@ -210,7 +207,7 @@ def forum_form_discussion(request, course_id):
#)
cohorts = get_course_cohorts(course_id)
cohorted_commentables = get_cohorted_commentables(course_id)
user_cohort_id = get_cohort_id(request.user, course_id)
context = {
......@@ -233,7 +230,7 @@ def forum_form_discussion(request, course_id):
'is_course_cohorted': is_course_cohorted(course_id)
}
# print "start rendering.."
return render_to_response('discussion/index.html', context)
@login_required
......@@ -251,7 +248,7 @@ def single_thread(request, course_id, discussion_id, thread_id):
if request.is_ajax():
courseware_context = get_courseware_context(thread, course)
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}
# TODO: Remove completely or switch back to server side rendering
......@@ -282,7 +279,7 @@ def single_thread(request, course_id, discussion_id, thread_id):
if courseware_context:
thread.update(courseware_context)
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]
......@@ -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)
cohorts = get_course_cohorts(course_id)
cohorted_commentables = get_cohorted_commentables(course_id)
user_cohort = get_cohort_id(request.user, course_id)
......
......@@ -68,7 +68,7 @@ def get_course_settings(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):
......
......@@ -236,7 +236,7 @@ def history(request, article_path, page=1, course_id=None):
page_size = 10
if page == None:
if page is None:
page = 1
try:
p = int(page)
......@@ -310,7 +310,7 @@ def revision_feed(request, page=1, namespace=None, course_id=None):
page_size = 10
if page == None:
if page is None:
page = 1
try:
p = int(page)
......
......@@ -23,7 +23,7 @@ class Model(object):
try:
return self.attributes[name]
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))
self.retrieve()
return self.__getattr__(name)
......
......@@ -70,7 +70,7 @@ StrPrinter._print_hat = _print_hat
def to_latex(x):
if x == None: return ''
if x is None: return ''
# LatexPrinter._print_dot = _print_dot
xs = latex(x)
xs = xs.replace(r'\XI', 'XI') # workaround for strange greek
......@@ -278,7 +278,7 @@ class formula(object):
if self.the_sympy: return self.the_sympy
if xml == None: # root
if xml is None: # root
if not self.is_mathml():
return my_sympify(self.expr)
if self.is_presentation_mathml():
......
......@@ -2,7 +2,7 @@
<%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
active_page = active_page_context
......
<%namespace name='static' file='static_content.html'/>
<h2 class="problem-header">
${ problem['name'] }
% if problem['weight'] != 1 and problem['weight'] != None:
% if problem['weight'] != 1 and problem['weight'] is not None:
: ${ problem['weight'] } points
% endif
</h2>
......@@ -30,4 +30,4 @@
</section>
% endif
</section>
</section>
\ No newline at end of file
</section>
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