Commit 21d161f0 by Calen Pennington

Check for None with is rather than ==

parent 40b472fe
...@@ -91,7 +91,7 @@ class LoncapaProblem(object): ...@@ -91,7 +91,7 @@ class LoncapaProblem(object):
self.problem_id = id self.problem_id = id
self.system = system self.system = system
if seed != None: if seed is not None:
self.seed = seed self.seed = seed
if state: if state:
......
...@@ -133,7 +133,7 @@ class SimpleInput():# XModule ...@@ -133,7 +133,7 @@ class SimpleInput():# XModule
def register_render_function(fn, names=None, cls=SimpleInput): def register_render_function(fn, names=None, cls=SimpleInput):
if names == None: if names is None:
SimpleInput.xml_tags[fn.__name__] = fn SimpleInput.xml_tags[fn.__name__] = fn
else: else:
raise NotImplementedError raise NotImplementedError
......
...@@ -109,7 +109,7 @@ class MultipleChoiceResponse(GenericResponse): ...@@ -109,7 +109,7 @@ class MultipleChoiceResponse(GenericResponse):
if rtype not in ["MultipleChoice"]: if rtype not in ["MultipleChoice"]:
response.set("type", "MultipleChoice") # force choicegroup to be MultipleChoice if not valid response.set("type", "MultipleChoice") # force choicegroup to be MultipleChoice if not valid
for choice in list(response): for choice in list(response):
if choice.get("name") == None: if choice.get("name") is None:
choice.set("name", "choice_"+str(i)) choice.set("name", "choice_"+str(i))
i+=1 i+=1
else: else:
...@@ -121,7 +121,7 @@ class TrueFalseResponse(MultipleChoiceResponse): ...@@ -121,7 +121,7 @@ class TrueFalseResponse(MultipleChoiceResponse):
for response in self.xml.xpath("choicegroup"): for response in self.xml.xpath("choicegroup"):
response.set("type", "TrueFalse") response.set("type", "TrueFalse")
for choice in list(response): for choice in list(response):
if choice.get("name") == None: if choice.get("name") is None:
choice.set("name", "choice_"+str(i)) choice.set("name", "choice_"+str(i))
i+=1 i+=1
else: else:
...@@ -292,7 +292,7 @@ def sympy_check2(): ...@@ -292,7 +292,7 @@ def sympy_check2():
self.code = '' self.code = ''
else: else:
answer_src = answer.get('src') answer_src = answer.get('src')
if answer_src != None: if answer_src is not None:
self.code = open(settings.DATA_DIR+'src/'+answer_src).read() self.code = open(settings.DATA_DIR+'src/'+answer_src).read()
else: else:
self.code = answer.text self.code = answer.text
...@@ -418,7 +418,7 @@ class ExternalResponse(GenericResponse): ...@@ -418,7 +418,7 @@ class ExternalResponse(GenericResponse):
id=xml.get('id'))[0] id=xml.get('id'))[0]
answer_src = answer.get('src') answer_src = answer.get('src')
if answer_src != None: if answer_src is not None:
self.code = open(settings.DATA_DIR+'src/'+answer_src).read() self.code = open(settings.DATA_DIR+'src/'+answer_src).read()
else: else:
self.code = answer.text self.code = answer.text
...@@ -489,7 +489,7 @@ class FormulaResponse(GenericResponse): ...@@ -489,7 +489,7 @@ class FormulaResponse(GenericResponse):
self.context = context self.context = context
ts = xml.get('type') ts = xml.get('type')
if ts == None: if ts is None:
typeslist = [] typeslist = []
else: else:
typeslist = ts.split(',') typeslist = ts.split(',')
...@@ -558,7 +558,7 @@ class SchematicResponse(GenericResponse): ...@@ -558,7 +558,7 @@ class SchematicResponse(GenericResponse):
answer = xml.xpath('//*[@id=$id]//answer', answer = xml.xpath('//*[@id=$id]//answer',
id=xml.get('id'))[0] id=xml.get('id'))[0]
answer_src = answer.get('src') answer_src = answer.get('src')
if answer_src != None: if answer_src is not None:
self.code = self.system.filestore.open('src/'+answer_src).read() # Untested; never used self.code = self.system.filestore.open('src/'+answer_src).read() # Untested; never used
else: else:
self.code = answer.text self.code = answer.text
......
...@@ -126,7 +126,7 @@ def propogate_downward_tag(element, attribute_name, parent_attribute = None): ...@@ -126,7 +126,7 @@ def propogate_downward_tag(element, attribute_name, parent_attribute = None):
child (A) already has that attribute, A will keep the same attribute and child (A) already has that attribute, A will keep the same attribute and
all of A's children will inherit A's attribute. This is a recursive call.''' all of A's children will inherit A's attribute. This is a recursive call.'''
if (parent_attribute == None): #This is the entry call. Select all elements with this attribute if (parent_attribute is None): #This is the entry call. Select all elements with this attribute
all_attributed_elements = element.xpath("//*[@" + attribute_name +"]") all_attributed_elements = element.xpath("//*[@" + attribute_name +"]")
for attributed_element in all_attributed_elements: for attributed_element in all_attributed_elements:
attribute_value = attributed_element.get(attribute_name) attribute_value = attributed_element.get(attribute_name)
......
...@@ -190,7 +190,7 @@ def get_score(user, problem, cache, coursename=None): ...@@ -190,7 +190,7 @@ def get_score(user, problem, cache, coursename=None):
correct=float(response.grade) correct=float(response.grade)
# Grab max grade from cache, or if it doesn't exist, compute and save to DB # Grab max grade from cache, or if it doesn't exist, compute and save to DB
if id in cache and response.max_grade != None: if id in cache and response.max_grade is not None:
total = response.max_grade total = response.max_grade
else: else:
## HACK 1: We shouldn't specifically reference capa_module ## HACK 1: We shouldn't specifically reference capa_module
......
...@@ -75,7 +75,7 @@ def grade_histogram(module_id): ...@@ -75,7 +75,7 @@ def grade_histogram(module_id):
grades = list(cursor.fetchall()) grades = list(cursor.fetchall())
grades.sort(key=lambda x:x[0]) # Probably not necessary grades.sort(key=lambda x:x[0]) # Probably not necessary
if (len(grades) == 1 and grades[0][0] == None): if (len(grades) == 1 and grades[0][0] is None):
return [] return []
return grades return grades
......
...@@ -97,7 +97,7 @@ class Module(XModule): ...@@ -97,7 +97,7 @@ class Module(XModule):
reset_button = False reset_button = False
# We don't need a "save" button if infinite number of attempts and non-randomized # We don't need a "save" button if infinite number of attempts and non-randomized
if self.max_attempts == None and self.rerandomize != "always": if self.max_attempts is None and self.rerandomize != "always":
save_button = False save_button = False
# Check if explanation is available, and if so, give a link # Check if explanation is available, and if so, give a link
...@@ -222,7 +222,7 @@ class Module(XModule): ...@@ -222,7 +222,7 @@ class Module(XModule):
''' Is the student still allowed to submit answers? ''' ''' Is the student still allowed to submit answers? '''
if self.attempts == self.max_attempts: if self.attempts == self.max_attempts:
return True return True
if self.close_date != None and datetime.datetime.utcnow() > self.close_date: if self.close_date is not None and datetime.datetime.utcnow() > self.close_date:
return True return True
return False return False
......
...@@ -51,7 +51,7 @@ class Module(XModule): ...@@ -51,7 +51,7 @@ class Module(XModule):
## Returns a set of all types of all sub-children ## Returns a set of all types of all sub-children
child_classes = [set([i.tag for i in e.iter()]) for e in self.xmltree] child_classes = [set([i.tag for i in e.iter()]) for e in self.xmltree]
titles = ["\n".join([i.get("name").strip() for i in e.iter() if i.get("name") != None]) \ titles = ["\n".join([i.get("name").strip() for i in e.iter() if i.get("name") is not None]) \
for e in self.xmltree] for e in self.xmltree]
self.contents = [j(self.render_function(e)) for e in self.xmltree] self.contents = [j(self.render_function(e)) for e in self.xmltree]
...@@ -91,7 +91,7 @@ class Module(XModule): ...@@ -91,7 +91,7 @@ class Module(XModule):
self.position = 1 self.position = 1
if state != None: if state is not None:
state = json.loads(state) state = json.loads(state)
if 'position' in state: self.position = int(state['position']) if 'position' in state: self.position = int(state['position'])
......
...@@ -47,7 +47,7 @@ class Module(XModule): ...@@ -47,7 +47,7 @@ class Module(XModule):
self.youtube = xmltree.get('youtube') self.youtube = xmltree.get('youtube')
self.name = xmltree.get('name') self.name = xmltree.get('name')
self.position = 0 self.position = 0
if state != None: if state is not None:
state = json.loads(state) state = json.loads(state)
if 'position' in state: if 'position' in state:
self.position = int(float(state['position'])) self.position = int(float(state['position']))
......
...@@ -57,7 +57,7 @@ def profile(request, student_id = None): ...@@ -57,7 +57,7 @@ def profile(request, student_id = None):
''' User profile. Show username, location, etc, as well as grades . ''' User profile. Show username, location, etc, as well as grades .
We need to allow the user to change some of these settings .''' We need to allow the user to change some of these settings .'''
if student_id == None: if student_id is None:
student = request.user student = request.user
else: else:
if 'course_admin' not in content_parser.user_groups(request.user): if 'course_admin' not in content_parser.user_groups(request.user):
...@@ -194,7 +194,7 @@ def index(request, course=None, chapter="Using the System", section="Hints"): ...@@ -194,7 +194,7 @@ def index(request, course=None, chapter="Using the System", section="Hints"):
else: else:
module_wrapper = dom_module[0] module_wrapper = dom_module[0]
if module_wrapper == None: if module_wrapper is None:
module = None module = None
elif module_wrapper.get("src"): elif module_wrapper.get("src"):
module = content_parser.section_file(user=user, section=module_wrapper.get("src"), coursename=course) module = content_parser.section_file(user=user, section=module_wrapper.get("src"), coursename=course)
......
...@@ -482,7 +482,7 @@ def check_permissions(request, article, check_read=False, check_write=False, che ...@@ -482,7 +482,7 @@ def check_permissions(request, article, check_read=False, check_write=False, che
locked_err = check_locked and article.locked locked_err = check_locked and article.locked
if revision == None: if revision is None:
revision = article.current_revision revision = article.current_revision
deleted_err = check_deleted and not (revision.deleted == 0) deleted_err = check_deleted and not (revision.deleted == 0)
if (request.user.is_superuser): if (request.user.is_superuser):
......
% if name is not UNDEFINED and name != None: % if name is not UNDEFINED and name is not None:
<h1> ${name} </h1> <h1> ${name} </h1>
% endif % endif
......
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