fix pep8 violations, fix pylint violations

This commit is contained in:
Miles Steele
2013-07-01 16:29:14 -04:00
parent a727959d18
commit f25b414d40
12 changed files with 227 additions and 147 deletions

View File

@@ -9,7 +9,8 @@ import xmodule.graders as xmgraders
STUDENT_FEATURES = ('username', 'first_name', 'last_name', 'is_staff', 'email')
PROFILE_FEATURES = ('name', 'language', 'location', 'year_of_birth', 'gender', 'level_of_education', 'mailing_address', 'goals')
PROFILE_FEATURES = ('name', 'language', 'location', 'year_of_birth', 'gender',
'level_of_education', 'mailing_address', 'goals')
AVAILABLE_FEATURES = STUDENT_FEATURES + PROFILE_FEATURES
@@ -19,17 +20,19 @@ def enrolled_students_profiles(course_id, features):
"""
# enrollments = CourseEnrollment.objects.filter(course_id=course_id)
# students = [enrollment.user for enrollment in enrollments]
students = User.objects.filter(courseenrollment__course_id=course_id).order_by('username').select_related('profile')
print len(students)
print students
students = User.objects.filter(courseenrollment__course_id=course_id)\
.order_by('username').select_related('profile')
def extract_student(student):
student_features = [feature for feature in features if feature in STUDENT_FEATURES]
profile_features = [feature for feature in features if feature in PROFILE_FEATURES]
""" convert student to dictionary """
student_features = [x for x in STUDENT_FEATURES if x in features]
profile_features = [x for x in PROFILE_FEATURES if x in features]
student_dict = dict((feature, getattr(student, feature)) for feature in student_features)
student_dict = dict((feature, getattr(student, feature))
for feature in student_features)
profile = student.profile
profile_dict = dict((feature, getattr(profile, feature)) for feature in profile_features)
profile_dict = dict((feature, getattr(profile, feature))
for feature in profile_features)
student_dict.update(profile_dict)
return student_dict
@@ -38,12 +41,14 @@ def enrolled_students_profiles(course_id, features):
def dump_grading_context(course):
"""
Render information about course grading context (eg which problems are graded in what assignments)
Render information about course grading context
(e.g. which problems are graded in what assignments)
Useful for debugging grading_policy.json and policy.json
Returns HTML string
"""
msg = "-----------------------------------------------------------------------------\n"
hbar = "{}\n".format("-" * 77)
msg = hbar
msg += "Course grader:\n"
msg += '%s\n' % course.grader.__class__
@@ -52,34 +57,36 @@ def dump_grading_context(course):
msg += '\n'
msg += "Graded sections:\n"
for subgrader, category, weight in course.grader.sections:
msg += " subgrader=%s, type=%s, category=%s, weight=%s\n" % (subgrader.__class__, subgrader.type, category, weight)
msg += " subgrader=%s, type=%s, category=%s, weight=%s\n"\
% (subgrader.__class__, subgrader.type, category, weight)
subgrader.index = 1
graders[subgrader.type] = subgrader
msg += "-----------------------------------------------------------------------------\n"
msg += hbar
msg += "Listing grading context for course %s\n" % course.id
gc = course.grading_context
gcontext = course.grading_context
msg += "graded sections:\n"
msg += '%s\n' % gc['graded_sections'].keys()
for (gs, gsvals) in gc['graded_sections'].items():
msg += "--> Section %s:\n" % (gs)
msg += '%s\n' % gcontext['graded_sections'].keys()
for (gsomething, gsvals) in gcontext['graded_sections'].items():
msg += "--> Section %s:\n" % (gsomething)
for sec in gsvals:
s = sec['section_descriptor']
format = getattr(s.lms, 'format', None)
sdesc = sec['section_descriptor']
frmat = getattr(sdesc.lms, 'format', None)
aname = ''
if format in graders:
g = graders[format]
aname = '%s %02d' % (g.short_label, g.index)
g.index += 1
elif s.display_name in graders:
g = graders[s.display_name]
aname = '%s' % g.short_label
if frmat in graders:
gform = graders[frmat]
aname = '%s %02d' % (gform.short_label, gform.index)
gform.index += 1
elif sdesc.display_name in graders:
gform = graders[sdesc.display_name]
aname = '%s' % gform.short_label
notes = ''
if getattr(s, 'score_by_attempt', False):
if getattr(sdesc, 'score_by_attempt', False):
notes = ', score by attempt!'
msg += " %s (format=%s, Assignment=%s%s)\n" % (s.display_name, format, aname, notes)
msg += " %s (format=%s, Assignment=%s%s)\n"\
% (sdesc.display_name, frmat, aname, notes)
msg += "all descriptors:\n"
msg += "length=%d\n" % len(gc['all_descriptors'])
msg = '<pre>%s</pre>' % msg.replace('<','&lt;')
msg += "length=%d\n" % len(gcontext['all_descriptors'])
msg = '<pre>%s</pre>' % msg.replace('<', '&lt;')
return msg