Commit d0f26418 by David Ormsbee

Account for the fact that sometimes we don't get HTTP_HOST (like for tests)

parent 7386d66c
......@@ -94,7 +94,7 @@ def main_index(request, extra_context={}, user=None):
# The course selection work is done in courseware.courses.
universities = get_courses_by_university(None,
domain=request.META['HTTP_HOST'])
domain=request.META.get('HTTP_HOST'))
context = {'universities': universities, 'entries': entries}
context.update(extra_context)
return render_to_response('index.html', context)
......
......@@ -205,19 +205,18 @@ def get_courses_by_university(user, domain=None):
Returns dict of lists of courses available, keyed by course.org (ie university).
Courses are sorted by course.number.
'''
subdomain = domain.split(".")[0]
# TODO: Clean up how 'error' is done.
# filter out any courses that errored.
if settings.MITX_FEATURES.get('SUBDOMAIN_COURSE_LISTINGS'):
if subdomain in settings.COURSE_LISTINGS:
visible_courses = settings.COURSE_LISTINGS[subdomain]
else:
visible_courses = frozenset(settings.COURSE_LISTINGS['default'])
courses = [c for c in modulestore().get_courses()
if isinstance(c, CourseDescriptor)]
courses = sorted(courses, key=lambda course: course.number)
if domain and settings.MITX_FEATURES.get('SUBDOMAIN_COURSE_LISTINGS'):
subdomain = settings.COURSE_LISTINGS.get(domain.split(".")[0], 'default')
visible_courses = frozenset(settings.COURSE_LISTINGS[subdomain])
else:
visible_courses = frozenset(c.id for c in courses)
universities = defaultdict(list)
for course in courses:
<<<<<<< HEAD
......@@ -227,9 +226,8 @@ def get_courses_by_university(user, domain=None):
if settings.MITX_FEATURES.get('ACCESS_REQUIRE_STAFF_FOR_COURSE'):
if not has_access_to_course(user,course):
continue
if settings.MITX_FEATURES.get('SUBDOMAIN_COURSE_LISTINGS'):
if course.id not in visible_courses:
continue
if course.id not in visible_courses:
continue
universities[course.org].append(course)
>>>>>>> implement subdomain-based course displays
return universities
......
......@@ -64,7 +64,7 @@ def courses(request):
Render "find courses" page. The course selection work is done in courseware.courses.
'''
universities = get_courses_by_university(request.user,
domain=request.META['HTTP_HOST'])
domain=request.META.get('HTTP_HOST'))
return render_to_response("courses.html", {'universities': universities})
......@@ -243,7 +243,7 @@ def university_profile(request, org_id):
# Only grab courses for this org...
courses = get_courses_by_university(request.user,
domain=request.META['HTTP_HOST'])[org_id]
domain=request.META.get('HTTP_HOST'))[org_id]
context = dict(courses=courses, org_id=org_id)
template_file = "university_profile/{0}.html".format(org_id).lower()
......
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