Created
April 22, 2013 15:02
-
-
Save e0d/5435747 to your computer and use it in GitHub Desktop.
Pattern for handling dynamic inclusion of static resources
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from xmodule.modulestore.django import modulestore | |
from xmodule.course_module import CourseDescriptor | |
from django.conf import settings | |
def pick_subdomain(domain, options, default='default'): | |
for option in options: | |
if domain.startswith(option): | |
return option | |
return default | |
def get_visible_courses(domain=None): | |
""" | |
Return the set of CourseDescriptors that should be visible in this branded instance | |
""" | |
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 = pick_subdomain(domain, settings.COURSE_LISTINGS.keys()) | |
visible_ids = frozenset(settings.COURSE_LISTINGS[subdomain]) | |
return [course for course in courses if course.id in visible_ids] | |
else: | |
return courses | |
def get_university(domain=None): | |
""" | |
Return the university name specified for the domain, or None | |
if no university was specified | |
""" | |
if not settings.MITX_FEATURES['SUBDOMAIN_BRANDING'] or domain is None: | |
return None | |
subdomain = pick_subdomain(domain, settings.SUBDOMAIN_BRANDING.keys()) | |
return settings.SUBDOMAIN_BRANDING.get(subdomain) | |
def get_logo_url(domain=None): | |
""" | |
Return the url for the branded logo image to be used | |
""" | |
university = get_university(domain) | |
if university is None: | |
return '/static/images/header-logo.png' | |
return '/static/images/{uni}-on-edx-logo.png'.format( | |
uni=university | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The code around line 49 and anywhere we're doing something similar in the middle-ware will need to be changes to respect overriding the static URL. This works by accident today.
Although this is a naive version, I think something like this would do the trick:
return settings.STATIC_URL + 'images/header-logo.png'