Commit 1ea65455 by dcadams

Worked on reducing pep8 violations.

parent 56f81fb1
...@@ -264,7 +264,6 @@ def dashboard(request): ...@@ -264,7 +264,6 @@ def dashboard(request):
if not user.is_active: if not user.is_active:
message = render_to_string('registration/activate_account_notice.html', {'email': user.email}) message = render_to_string('registration/activate_account_notice.html', {'email': user.email})
# Global staff can see what courses errored on their dashboard # Global staff can see what courses errored on their dashboard
staff_access = False staff_access = False
errored_courses = {} errored_courses = {}
...@@ -355,7 +354,7 @@ def change_enrollment(request): ...@@ -355,7 +354,7 @@ def change_enrollment(request):
course = course_from_id(course_id) course = course_from_id(course_id)
except ItemNotFoundError: except ItemNotFoundError:
log.warning("User {0} tried to enroll in non-existent course {1}" log.warning("User {0} tried to enroll in non-existent course {1}"
.format(user.username, course_id)) .format(user.username, course_id))
return HttpResponseBadRequest("Course id is invalid") return HttpResponseBadRequest("Course id is invalid")
if not has_access(user, course, 'enroll'): if not has_access(user, course, 'enroll'):
...@@ -363,9 +362,9 @@ def change_enrollment(request): ...@@ -363,9 +362,9 @@ def change_enrollment(request):
org, course_num, run = course_id.split("/") org, course_num, run = course_id.split("/")
statsd.increment("common.student.enrollment", statsd.increment("common.student.enrollment",
tags=["org:{0}".format(org), tags=["org:{0}".format(org),
"course:{0}".format(course_num), "course:{0}".format(course_num),
"run:{0}".format(run)]) "run:{0}".format(run)])
try: try:
enrollment, created = CourseEnrollment.objects.get_or_create(user=user, course_id=course.id) enrollment, created = CourseEnrollment.objects.get_or_create(user=user, course_id=course.id)
...@@ -382,9 +381,9 @@ def change_enrollment(request): ...@@ -382,9 +381,9 @@ def change_enrollment(request):
org, course_num, run = course_id.split("/") org, course_num, run = course_id.split("/")
statsd.increment("common.student.unenrollment", statsd.increment("common.student.unenrollment",
tags=["org:{0}".format(org), tags=["org:{0}".format(org),
"course:{0}".format(course_num), "course:{0}".format(course_num),
"run:{0}".format(run)]) "run:{0}".format(run)])
return HttpResponse() return HttpResponse()
except CourseEnrollment.DoesNotExist: except CourseEnrollment.DoesNotExist:
...@@ -454,7 +453,6 @@ def login_user(request, error=""): ...@@ -454,7 +453,6 @@ def login_user(request, error=""):
expires_time = time.time() + max_age expires_time = time.time() + max_age
expires = cookie_date(expires_time) expires = cookie_date(expires_time)
response.set_cookie(settings.EDXMKTG_COOKIE_NAME, response.set_cookie(settings.EDXMKTG_COOKIE_NAME,
'true', max_age=max_age, 'true', max_age=max_age,
expires=expires, domain=settings.SESSION_COOKIE_DOMAIN, expires=expires, domain=settings.SESSION_COOKIE_DOMAIN,
...@@ -515,8 +513,8 @@ def _do_create_account(post_vars): ...@@ -515,8 +513,8 @@ def _do_create_account(post_vars):
Note: this function is also used for creating test users. Note: this function is also used for creating test users.
""" """
user = User(username=post_vars['username'], user = User(username=post_vars['username'],
email=post_vars['email'], email=post_vars['email'],
is_active=False) is_active=False)
user.set_password(post_vars['password']) user.set_password(post_vars['password'])
registration = Registration() registration = Registration()
# TODO: Rearrange so that if part of the process fails, the whole process fails. # TODO: Rearrange so that if part of the process fails, the whole process fails.
...@@ -698,7 +696,6 @@ def create_account(request, post_override=None): ...@@ -698,7 +696,6 @@ def create_account(request, post_override=None):
expires_time = time.time() + max_age expires_time = time.time() + max_age
expires = cookie_date(expires_time) expires = cookie_date(expires_time)
response.set_cookie(settings.EDXMKTG_COOKIE_NAME, response.set_cookie(settings.EDXMKTG_COOKIE_NAME,
'true', max_age=max_age, 'true', max_age=max_age,
expires=expires, domain=settings.SESSION_COOKIE_DOMAIN, expires=expires, domain=settings.SESSION_COOKIE_DOMAIN,
...@@ -708,7 +705,6 @@ def create_account(request, post_override=None): ...@@ -708,7 +705,6 @@ def create_account(request, post_override=None):
return response return response
def exam_registration_info(user, course): def exam_registration_info(user, course):
""" Returns a Registration object if the user is currently registered for a current """ Returns a Registration object if the user is currently registered for a current
exam of the course. Returns None if the user is not registered, or if there is no exam of the course. Returns None if the user is not registered, or if there is no
...@@ -849,7 +845,6 @@ def create_exam_registration(request, post_override=None): ...@@ -849,7 +845,6 @@ def create_exam_registration(request, post_override=None):
response_data['non_field_errors'] = form.non_field_errors() response_data['non_field_errors'] = form.non_field_errors()
return HttpResponse(json.dumps(response_data), mimetype="application/json") return HttpResponse(json.dumps(response_data), mimetype="application/json")
# only do the following if there is accommodation text to send, # only do the following if there is accommodation text to send,
# and a destination to which to send it. # and a destination to which to send it.
# TODO: still need to create the accommodation email templates # TODO: still need to create the accommodation email templates
...@@ -872,7 +867,6 @@ def create_exam_registration(request, post_override=None): ...@@ -872,7 +867,6 @@ def create_exam_registration(request, post_override=None):
# response_data['non_field_errors'] = [ 'Could not send accommodation e-mail.', ] # response_data['non_field_errors'] = [ 'Could not send accommodation e-mail.', ]
# return HttpResponse(json.dumps(response_data), mimetype="application/json") # return HttpResponse(json.dumps(response_data), mimetype="application/json")
js = {'success': True} js = {'success': True}
return HttpResponse(json.dumps(js), mimetype="application/json") return HttpResponse(json.dumps(js), mimetype="application/json")
...@@ -916,7 +910,7 @@ def activate_account(request, key): ...@@ -916,7 +910,7 @@ def activate_account(request, key):
if not r[0].user.is_active: if not r[0].user.is_active:
r[0].activate() r[0].activate()
already_active = False already_active = False
#Enroll student in any pending courses he/she may have if auto_enroll flag is set #Enroll student in any pending courses he/she may have if auto_enroll flag is set
student = request.user student = request.user
ceas = CourseEnrollmentAllowed.objects.filter(email=student.email) ceas = CourseEnrollmentAllowed.objects.filter(email=student.email)
...@@ -924,7 +918,7 @@ def activate_account(request, key): ...@@ -924,7 +918,7 @@ def activate_account(request, key):
if cea.auto_enroll: if cea.auto_enroll:
course_id = cea.course_id course_id = cea.course_id
enrollment, created = CourseEnrollment.objects.get_or_create(user_id=student.id, course_id=course_id) enrollment, created = CourseEnrollment.objects.get_or_create(user_id=student.id, course_id=course_id)
resp = render_to_response("registration/activation_complete.html", {'user_logged_in': user_logged_in, 'already_active': already_active}) resp = render_to_response("registration/activation_complete.html", {'user_logged_in': user_logged_in, 'already_active': already_active})
return resp return resp
if len(r) == 0: if len(r) == 0:
......
...@@ -172,7 +172,7 @@ class TestInstructorEnrollsStudent(LoginEnrollmentTestCase): ...@@ -172,7 +172,7 @@ class TestInstructorEnrollsStudent(LoginEnrollmentTestCase):
''' '''
Clean user input test Clean user input test
''' '''
string = "abc@test.com, def@test.com ghi@test.com \n \n jkl@test.com " string = "abc@test.com, def@test.com ghi@test.com \n \n jkl@test.com "
cleaned_string, cleaned_string_lc = get_and_clean_student_list(string) cleaned_string, cleaned_string_lc = get_and_clean_student_list(string)
self.assertEqual(cleaned_string, ['abc@test.com', 'def@test.com', 'ghi@test.com', 'jkl@test.com']) self.assertEqual(cleaned_string, ['abc@test.com', 'def@test.com', 'ghi@test.com', 'jkl@test.com'])
\ No newline at end of file
...@@ -9,7 +9,6 @@ import os ...@@ -9,7 +9,6 @@ import os
import re import re
import requests import requests
from requests.status_codes import codes from requests.status_codes import codes
import urllib
from collections import OrderedDict from collections import OrderedDict
from StringIO import StringIO from StringIO import StringIO
...@@ -230,13 +229,13 @@ def instructor_dashboard(request, course_id): ...@@ -230,13 +229,13 @@ def instructor_dashboard(request, course_id):
if student_to_reset is not None: if student_to_reset is not None:
# find the module in question # find the module in question
if '/' not in problem_to_reset: # allow state of modules other than problem to be reset if '/' not in problem_to_reset: # allow state of modules other than problem to be reset
problem_to_reset = "problem/" + problem_to_reset # but problem is the default problem_to_reset = "problem/" + problem_to_reset # but problem is the default
try: try:
(org, course_name, _) = course_id.split("/") (org, course_name, _) = course_id.split("/")
module_state_key = "i4x://" + org + "/" + course_name + "/" + problem_to_reset module_state_key = "i4x://" + org + "/" + course_name + "/" + problem_to_reset
module_to_reset = StudentModule.objects.get(student_id=student_to_reset.id, module_to_reset = StudentModule.objects.get(student_id=student_to_reset.id,
course_id=course_id, course_id=course_id,
module_state_key=module_state_key) module_state_key=module_state_key)
msg += "Found module to reset. " msg += "Found module to reset. "
except Exception: except Exception:
msg += "<font color='red'>Couldn't find module with that urlname. </font>" msg += "<font color='red'>Couldn't find module with that urlname. </font>"
...@@ -260,19 +259,18 @@ def instructor_dashboard(request, course_id): ...@@ -260,19 +259,18 @@ def instructor_dashboard(request, course_id):
module_to_reset.state = json.dumps(problem_state) module_to_reset.state = json.dumps(problem_state)
module_to_reset.save() module_to_reset.save()
track.views.server_track(request, track.views.server_track(request,
'{instructor} reset attempts from {old_attempts} to 0 for {student} on problem {problem} in {course}'.format( '{instructor} reset attempts from {old_attempts} to 0 for {student} on problem {problem} in {course}'.format(
old_attempts=old_number_of_attempts, old_attempts=old_number_of_attempts,
student=student_to_reset, student=student_to_reset,
problem=module_to_reset.module_state_key, problem=module_to_reset.module_state_key,
instructor=request.user, instructor=request.user,
course=course_id), course=course_id),
{}, {},
page='idashboard') page='idashboard')
msg += "<font color='green'>Module state successfully reset!</font>" msg += "<font color='green'>Module state successfully reset!</font>"
except: except:
msg += "<font color='red'>Couldn't reset module state. </font>" msg += "<font color='red'>Couldn't reset module state. </font>"
elif "Get link to student's progress page" in action: elif "Get link to student's progress page" in action:
unique_student_identifier = request.POST.get('unique_student_identifier', '') unique_student_identifier = request.POST.get('unique_student_identifier', '')
try: try:
...@@ -282,12 +280,12 @@ def instructor_dashboard(request, course_id): ...@@ -282,12 +280,12 @@ def instructor_dashboard(request, course_id):
student_to_reset = User.objects.get(username=unique_student_identifier) student_to_reset = User.objects.get(username=unique_student_identifier)
progress_url = reverse('student_progress', kwargs={'course_id': course_id, 'student_id': student_to_reset.id}) progress_url = reverse('student_progress', kwargs={'course_id': course_id, 'student_id': student_to_reset.id})
track.views.server_track(request, track.views.server_track(request,
'{instructor} requested progress page for {student} in {course}'.format( '{instructor} requested progress page for {student} in {course}'.format(
student=student_to_reset, student=student_to_reset,
instructor=request.user, instructor=request.user,
course=course_id), course=course_id),
{}, {},
page='idashboard') page='idashboard')
msg += "<a href='{0}' target='_blank'> Progress page for username: {1} with email address: {2}</a>.".format(progress_url, student_to_reset.username, student_to_reset.email) msg += "<a href='{0}' target='_blank'> Progress page for username: {1} with email address: {2}</a>.".format(progress_url, student_to_reset.username, student_to_reset.email)
except: except:
msg += "<font color='red'>Couldn't find student with that username. </font>" msg += "<font color='red'>Couldn't find student with that username. </font>"
...@@ -315,6 +313,7 @@ def instructor_dashboard(request, course_id): ...@@ -315,6 +313,7 @@ def instructor_dashboard(request, course_id):
msg2, rg_stud_data = _do_remote_gradebook(request.user, course, 'get-membership') msg2, rg_stud_data = _do_remote_gradebook(request.user, course, 'get-membership')
datatable = {'header': ['Student email', 'Match?']} datatable = {'header': ['Student email', 'Match?']}
rg_students = [x['email'] for x in rg_stud_data['retdata']] rg_students = [x['email'] for x in rg_stud_data['retdata']]
def domatch(x): def domatch(x):
return '<font color="green">yes</font>' if x.email in rg_students else '<font color="red">No</font>' return '<font color="green">yes</font>' if x.email in rg_students else '<font color="red">No</font>'
datatable['data'] = [[x.email, domatch(x)] for x in stud_data['students']] datatable['data'] = [[x.email, domatch(x)] for x in stud_data['students']]
...@@ -350,7 +349,6 @@ def instructor_dashboard(request, course_id): ...@@ -350,7 +349,6 @@ def instructor_dashboard(request, course_id):
msg2, _ = _do_remote_gradebook(request.user, course, 'post-grades', files=files) msg2, _ = _do_remote_gradebook(request.user, course, 'post-grades', files=files)
msg += msg2 msg += msg2
#---------------------------------------- #----------------------------------------
# Admin # Admin
...@@ -416,6 +414,7 @@ def instructor_dashboard(request, course_id): ...@@ -416,6 +414,7 @@ def instructor_dashboard(request, course_id):
profkeys = ['name', 'language', 'location', 'year_of_birth', 'gender', 'level_of_education', profkeys = ['name', 'language', 'location', 'year_of_birth', 'gender', 'level_of_education',
'mailing_address', 'goals'] 'mailing_address', 'goals']
datatable = {'header': ['username', 'email'] + profkeys} datatable = {'header': ['username', 'email'] + profkeys}
def getdat(u): def getdat(u):
p = u.profile p = u.profile
return [u.username, u.email] + [getattr(p, x, '') for x in profkeys] return [u.username, u.email] + [getattr(p, x, '') for x in profkeys]
...@@ -424,9 +423,8 @@ def instructor_dashboard(request, course_id): ...@@ -424,9 +423,8 @@ def instructor_dashboard(request, course_id):
datatable['title'] = 'Student profile data for course %s' % course_id datatable['title'] = 'Student profile data for course %s' % course_id
return return_csv('profiledata_%s.csv' % course_id, datatable) return return_csv('profiledata_%s.csv' % course_id, datatable)
elif 'Download CSV of all responses to problem' in action: elif 'Download CSV of all responses to problem' in action:
problem_to_dump = request.POST.get('problem_to_dump','') problem_to_dump = request.POST.get('problem_to_dump', '')
if problem_to_dump[-4:] == ".xml": if problem_to_dump[-4:] == ".xml":
problem_to_dump = problem_to_dump[:-4] problem_to_dump = problem_to_dump[:-4]
...@@ -444,7 +442,7 @@ def instructor_dashboard(request, course_id): ...@@ -444,7 +442,7 @@ def instructor_dashboard(request, course_id):
if smdat: if smdat:
datatable = {'header': ['username', 'state']} datatable = {'header': ['username', 'state']}
datatable['data'] = [ [x.student.username, x.state] for x in smdat ] datatable['data'] = [[x.student.username, x.state] for x in smdat]
datatable['title'] = 'Student state for problem %s' % problem_to_dump datatable['title'] = 'Student state for problem %s' % problem_to_dump
return return_csv('student_state_from_%s.csv' % problem_to_dump, datatable) return return_csv('student_state_from_%s.csv' % problem_to_dump, datatable)
...@@ -481,7 +479,6 @@ def instructor_dashboard(request, course_id): ...@@ -481,7 +479,6 @@ def instructor_dashboard(request, course_id):
msg += _list_course_forum_members(course_id, rolename, datatable) msg += _list_course_forum_members(course_id, rolename, datatable)
track.views.server_track(request, 'list-{0}'.format(rolename), {}, page='idashboard') track.views.server_track(request, 'list-{0}'.format(rolename), {}, page='idashboard')
elif action == 'Remove forum admin': elif action == 'Remove forum admin':
uname = request.POST['forumadmin'] uname = request.POST['forumadmin']
msg += _update_forum_role_membership(uname, course, FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_REMOVE) msg += _update_forum_role_membership(uname, course, FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_REMOVE)
...@@ -571,7 +568,6 @@ def instructor_dashboard(request, course_id): ...@@ -571,7 +568,6 @@ def instructor_dashboard(request, course_id):
ret = _do_enroll_students(course, course_id, students, overload=overload) ret = _do_enroll_students(course, course_id, students, overload=overload)
datatable = ret['datatable'] datatable = ret['datatable']
#---------------------------------------- #----------------------------------------
# psychometrics # psychometrics
...@@ -591,9 +587,9 @@ def instructor_dashboard(request, course_id): ...@@ -591,9 +587,9 @@ def instructor_dashboard(request, course_id):
logs and swallows errors. logs and swallows errors.
""" """
url = settings.ANALYTICS_SERVER_URL + \ url = settings.ANALYTICS_SERVER_URL + \
"get?aname={}&course_id={}&apikey={}".format(analytics_name, "get?aname={}&course_id={}&apikey={}".format(analytics_name,
course_id, course_id,
settings.ANALYTICS_API_KEY) settings.ANALYTICS_API_KEY)
try: try:
res = requests.get(url) res = requests.get(url)
except Exception: except Exception:
...@@ -652,7 +648,7 @@ def instructor_dashboard(request, course_id): ...@@ -652,7 +648,7 @@ def instructor_dashboard(request, course_id):
'cohorts_ajax_url': reverse('cohorts', kwargs={'course_id': course_id}), 'cohorts_ajax_url': reverse('cohorts', kwargs={'course_id': course_id}),
'analytics_results': analytics_results, 'analytics_results': analytics_results,
} }
return render_to_response('courseware/instructor_dashboard.html', context) return render_to_response('courseware/instructor_dashboard.html', context)
...@@ -815,7 +811,7 @@ def _add_or_remove_user_group(request, username_or_email, group, group_title, ev ...@@ -815,7 +811,7 @@ def _add_or_remove_user_group(request, username_or_email, group, group_title, ev
action = "Added" if do_add else "Removed" action = "Added" if do_add else "Removed"
prep = "to" if do_add else "from" prep = "to" if do_add else "from"
msg = '<font color="green">{action} {0} {prep} {1} group = {2}</font>'.format(user, group_title, group.name, msg = '<font color="green">{action} {0} {prep} {1} group = {2}</font>'.format(user, group_title, group.name,
action=action, prep=prep) action=action, prep=prep)
if do_add: if do_add:
user.groups.add(group) user.groups.add(group)
else: else:
...@@ -941,7 +937,7 @@ def gradebook(request, course_id): ...@@ -941,7 +937,7 @@ def gradebook(request, course_id):
'grade_summary': student_grades(student, request, course), 'grade_summary': student_grades(student, request, course),
'realname': student.profile.name, 'realname': student.profile.name,
} }
for student in enrolled_students] for student in enrolled_students]
return render_to_response('courseware/gradebook.html', { return render_to_response('courseware/gradebook.html', {
'students': student_info, 'students': student_info,
...@@ -1093,6 +1089,7 @@ def get_and_clean_student_list(students): ...@@ -1093,6 +1089,7 @@ def get_and_clean_student_list(students):
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
# answer distribution # answer distribution
def get_answers_distribution(request, course_id): def get_answers_distribution(request, course_id):
""" """
Get the distribution of answers for all graded problems in the course. Get the distribution of answers for all graded problems in the course.
...@@ -1184,5 +1181,5 @@ def dump_grading_context(course): ...@@ -1184,5 +1181,5 @@ def dump_grading_context(course):
msg += " %s (format=%s, Assignment=%s%s)\n" % (s.display_name, format, aname, notes) msg += " %s (format=%s, Assignment=%s%s)\n" % (s.display_name, format, aname, notes)
msg += "all descriptors:\n" msg += "all descriptors:\n"
msg += "length=%d\n" % len(gc['all_descriptors']) msg += "length=%d\n" % len(gc['all_descriptors'])
msg = '<pre>%s</pre>' % msg.replace('<','&lt;') msg = '<pre>%s</pre>' % msg.replace('<', '&lt;')
return msg return msg
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