Commit 4031c193 by Nate Hardison

Adjust available routes based on theme presence

Themes do not necessarily want all of the available LMS routes, such
as `/jobs` and `/university_profiles`. This change splits up the
`lms/urls.py` file and selectively enables/disables routes based on
whether or not a theme is enabled. This is a naive solution for now;
a better solution gives themes a way to selectively overrides such
routes.

Additionally, with the `MKTG_URL_LINK_MAP` setting that hits certain
routes immediately on each page render (whenever the `marketing_link`
helper function is called), themes may crash if they don't leave
all marketing link routes present in `lms/urls.py`. This change also
provides the ability to override the `MKTG_URL_LINK_MAP` in the
settings.

Finally, modify the mitxmako marketing URL middleware to not try to
reverse disabled URLs, which are those keys in the map whose values
are `None`.
parent e0590c35
...@@ -41,7 +41,9 @@ def marketing_link(name): ...@@ -41,7 +41,9 @@ def marketing_link(name):
return settings.MKTG_URLS.get('ROOT') + settings.MKTG_URLS.get(name) return settings.MKTG_URLS.get('ROOT') + settings.MKTG_URLS.get(name)
# only link to the old pages when the marketing site isn't on # only link to the old pages when the marketing site isn't on
elif not settings.MITX_FEATURES.get('ENABLE_MKTG_SITE') and name in link_map: elif not settings.MITX_FEATURES.get('ENABLE_MKTG_SITE') and name in link_map:
return reverse(link_map[name]) # don't try to reverse disabled marketing links
if link_map[name] is not None:
return reverse(link_map[name])
else: else:
log.warning("Cannot find corresponding link for name: {name}".format(name=name)) log.warning("Cannot find corresponding link for name: {name}".format(name=name))
return '#' return '#'
......
...@@ -131,6 +131,8 @@ if not THEME_NAME is None: ...@@ -131,6 +131,8 @@ if not THEME_NAME is None:
enable_theme(THEME_NAME) enable_theme(THEME_NAME)
FAVICON_PATH = 'themes/%s/images/favicon.ico' % THEME_NAME FAVICON_PATH = 'themes/%s/images/favicon.ico' % THEME_NAME
# Marketing link overrides
MKTG_URL_LINK_MAP.update(ENV_TOKENS.get('MKTG_URL_LINK_MAP', {}))
#Timezone overrides #Timezone overrides
TIME_ZONE = ENV_TOKENS.get('TIME_ZONE', TIME_ZONE) TIME_ZONE = ENV_TOKENS.get('TIME_ZONE', TIME_ZONE)
......
...@@ -58,66 +58,92 @@ urlpatterns = ('', # nopep8 ...@@ -58,66 +58,92 @@ urlpatterns = ('', # nopep8
name='auth_password_reset_done'), name='auth_password_reset_done'),
url(r'^heartbeat$', include('heartbeat.urls')), url(r'^heartbeat$', include('heartbeat.urls')),
)
## # University profiles only make sense in the default edX context
## Only universities without courses should be included here. If if not settings.MITX_FEATURES["USE_CUSTOM_THEME"]:
## courses exist, the dynamic profile rule below should win. urlpatterns += (
## ##
url(r'^(?i)university_profile/WellesleyX$', 'courseware.views.static_university_profile', ## Only universities without courses should be included here. If
name="static_university_profile", kwargs={'org_id': 'WellesleyX'}), ## courses exist, the dynamic profile rule below should win.
url(r'^(?i)university_profile/McGillX$', 'courseware.views.static_university_profile', ##
name="static_university_profile", kwargs={'org_id': 'McGillX'}), url(r'^(?i)university_profile/WellesleyX$', 'courseware.views.static_university_profile',
url(r'^(?i)university_profile/TorontoX$', 'courseware.views.static_university_profile', name="static_university_profile", kwargs={'org_id': 'WellesleyX'}),
name="static_university_profile", kwargs={'org_id': 'TorontoX'}), url(r'^(?i)university_profile/McGillX$', 'courseware.views.static_university_profile',
url(r'^(?i)university_profile/RiceX$', 'courseware.views.static_university_profile', name="static_university_profile", kwargs={'org_id': 'McGillX'}),
name="static_university_profile", kwargs={'org_id': 'RiceX'}), url(r'^(?i)university_profile/TorontoX$', 'courseware.views.static_university_profile',
url(r'^(?i)university_profile/ANUx$', 'courseware.views.static_university_profile', name="static_university_profile", kwargs={'org_id': 'TorontoX'}),
name="static_university_profile", kwargs={'org_id': 'ANUx'}), url(r'^(?i)university_profile/RiceX$', 'courseware.views.static_university_profile',
url(r'^(?i)university_profile/EPFLx$', 'courseware.views.static_university_profile', name="static_university_profile", kwargs={'org_id': 'RiceX'}),
name="static_university_profile", kwargs={'org_id': 'EPFLx'}), url(r'^(?i)university_profile/ANUx$', 'courseware.views.static_university_profile',
name="static_university_profile", kwargs={'org_id': 'ANUx'}),
url(r'^university_profile/(?P<org_id>[^/]+)$', 'courseware.views.university_profile', url(r'^(?i)university_profile/EPFLx$', 'courseware.views.static_university_profile',
name="university_profile"), name="static_university_profile", kwargs={'org_id': 'EPFLx'}),
#Semi-static views (these need to be rendered and have the login bar, but don't change) url(r'^university_profile/(?P<org_id>[^/]+)$', 'courseware.views.university_profile',
name="university_profile"),
)
#Semi-static views (these need to be rendered and have the login bar, but don't change)
urlpatterns += (
url(r'^404$', 'static_template_view.views.render', url(r'^404$', 'static_template_view.views.render',
{'template': '404.html'}, name="404"), {'template': '404.html'}, name="404"),
url(r'^about$', 'static_template_view.views.render',
{'template': 'about.html'}, name="about_edx"),
url(r'^jobs$', 'static_template_view.views.render',
{'template': 'jobs.html'}, name="jobs"),
url(r'^contact$', 'static_template_view.views.render',
{'template': 'contact.html'}, name="contact"),
url(r'^press$', 'student.views.press', name="press"),
url(r'^media-kit$', 'static_template_view.views.render',
{'template': 'media-kit.html'}, name="media-kit"),
url(r'^faq$', 'static_template_view.views.render',
{'template': 'faq.html'}, name="faq_edx"),
url(r'^help$', 'static_template_view.views.render',
{'template': 'help.html'}, name="help_edx"),
url(r'^tos$', 'static_template_view.views.render',
{'template': 'tos.html'}, name="tos"),
url(r'^privacy$', 'static_template_view.views.render',
{'template': 'privacy.html'}, name="privacy_edx"),
# TODO: (bridger) The copyright has been removed until it is updated for edX
# url(r'^copyright$', 'static_template_view.views.render',
# {'template': 'copyright.html'}, name="copyright"),
url(r'^honor$', 'static_template_view.views.render',
{'template': 'honor.html'}, name="honor"),
#Press releases
url(r'^press/([_a-zA-Z0-9-]+)$', 'static_template_view.views.render_press_release', name='press_release'),
# Favicon
(r'^favicon\.ico$', 'django.views.generic.simple.redirect_to', {'url': '/static/images/favicon.ico'}),
url(r'^submit_feedback$', 'util.views.submit_feedback_via_zendesk'),
# TODO: These urls no longer work. They need to be updated before they are re-enabled
# url(r'^reactivate/(?P<key>[^/]*)$', 'student.views.reactivation_email'),
) )
# Semi-static views only used by edX, not by themes
if not settings.MITX_FEATURES["USE_CUSTOM_THEME"]:
urlpatterns += (
url(r'^jobs$', 'static_template_view.views.render',
{'template': 'jobs.html'}, name="jobs"),
url(r'^press$', 'student.views.press', name="press"),
url(r'^media-kit$', 'static_template_view.views.render',
{'template': 'media-kit.html'}, name="media-kit"),
url(r'^help$', 'static_template_view.views.render',
{'template': 'help.html'}, name="help_edx"),
# TODO: (bridger) The copyright has been removed until it is updated for edX
# url(r'^copyright$', 'static_template_view.views.render',
# {'template': 'copyright.html'}, name="copyright"),
#Press releases
url(r'^press/([_a-zA-Z0-9-]+)$', 'static_template_view.views.render_press_release', name='press_release'),
# Favicon
(r'^favicon\.ico$', 'django.views.generic.simple.redirect_to', {'url': '/static/images/favicon.ico'}),
url(r'^submit_feedback$', 'util.views.submit_feedback_via_zendesk'),
# TODO: These urls no longer work. They need to be updated before they are re-enabled
# url(r'^reactivate/(?P<key>[^/]*)$', 'student.views.reactivation_email'),
)
# Only enable URLs for those marketing links actually enabled in the
# settings. Disable URLs by marking them as None.
for key, value in settings.MKTG_URL_LINK_MAP.items():
# Skip disabled URLs
if value is None:
continue
# These urls are enabled separately
if key == "ROOT" or key == "COURSES":
continue
# Make the assumptions that the templates are all in the same dir
# and that they all match the name of the key (plus extension)
template = "%s.html" % key.lower()
# To allow theme templates to inherit from default templates,
# prepend a standard prefix
if settings.MITX_FEATURES["USE_CUSTOM_THEME"]:
template = "theme-" + template
# Make the assumption that the URL we want is the lowercased
# version of the map key
urlpatterns += (url(r'^%s' % key.lower(),
'static_template_view.views.render',
{'template': template}, name=value),)
if settings.PERFSTATS: if settings.PERFSTATS:
urlpatterns += (url(r'^reprofile$', 'perfstats.views.end_profile'),) urlpatterns += (url(r'^reprofile$', 'perfstats.views.end_profile'),)
......
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