Commit 1ac41787 by Carlos Andrés Rocha

Fix broken display of courses in university profile

parent bcb5eda2
......@@ -40,7 +40,7 @@ from xmodule.modulestore.exceptions import ItemNotFoundError
from datetime import date
from collections import namedtuple
from courseware.courses import get_courses_by_start_date
from courseware.courses import get_courses
from courseware.access import has_access
from statsd import statsd
......@@ -75,7 +75,11 @@ def index(request, extra_context={}, user=None):
if domain==False: # do explicit check, because domain=None is valid
domain = request.META.get('HTTP_HOST')
courses = get_courses_by_start_date(None, domain=domain)
courses = get_courses(None, domain=domain)
# Sort courses by how far are they from they start day
key = lambda course: course.metadata['days_to_start']
courses = sorted(courses, key=key, reverse=True)
# Get the 3 most recent news
top_news = _get_news(top=3)
......
......@@ -233,21 +233,7 @@ def get_courses(user, domain=None):
courses = branding.get_visible_courses(domain)
courses = [c for c in courses if has_access(user, c, 'see_exists')]
return courses
def get_courses_by_start_date(user, domain=None):
"""
Returns a list of courses available, sorted by start date
"""
visible_courses = get_courses(user, domain)
courses = _sort_courses_and_mark_new(visible_courses)
return courses
def _sort_courses_and_mark_new(courses):
"""Sort by course start date and mark which have not started yet"""
# Add metadata about the start day and if the course is new
for course in courses:
days_to_start = _get_course_days_to_start(course)
......@@ -255,9 +241,7 @@ def _sort_courses_and_mark_new(courses):
metadata['days_to_start'] = days_to_start
metadata['is_new'] = course.metadata.get('is_new', days_to_start > 1)
key = lambda c: c.metadata['days_to_start']
courses = sorted(courses, key=key, reverse=True)
courses = sorted(courses, key=lambda course:course.number)
return courses
......
......@@ -17,7 +17,7 @@ from django.views.decorators.cache import cache_control
from courseware import grades
from courseware.access import has_access
from courseware.courses import (get_course_with_access, get_courses_by_start_date)
from courseware.courses import (get_courses, get_course_with_access, get_courses_by_university)
import courseware.tabs as tabs
from courseware.models import StudentModuleCache
from module_render import toc_for_course, get_module, get_instance_module
......@@ -61,15 +61,18 @@ def user_groups(user):
return group_names
@ensure_csrf_cookie
@cache_if_anonymous
def courses(request):
'''
Render "find courses" page. The course selection work is done in courseware.courses.
'''
courses = get_courses_by_start_date(request.user,
domain=request.META.get('HTTP_HOST'))
courses = get_courses(request.user, domain=request.META.get('HTTP_HOST'))
# Sort courses by how far are they from they start day
key = lambda course: course.metadata['days_to_start']
courses = sorted(courses, key=key, reverse=True)
return render_to_response("courseware/courses.html", {'courses': courses})
......@@ -435,6 +438,11 @@ def university_profile(request, org_id):
# Only grab courses for this org...
courses = get_courses_by_university(request.user,
domain=request.META.get('HTTP_HOST'))[org_id]
# Sort courses by how far are they from they start day
key = lambda course: course.metadata['days_to_start']
courses = sorted(courses, key=key, reverse=True)
context = dict(courses=courses, org_id=org_id)
template_file = "university_profile/{0}.html".format(org_id).lower()
......
......@@ -5,7 +5,7 @@
%>
<%page args="course" />
<article id="${course.id}" class="course">
%if course.metadata['is_new']:
%if course.metadata.get('is_new'):
<span class="status">New</span>
%endif
<a href="${reverse('about_course', args=[course.id])}">
......
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