Skip to content

Commit

Permalink
Merge pull request #11073 from edx/ziafazal/WL-245
Browse files Browse the repository at this point in the history
Ziafazal/wl-245: multiple backend support for microsite
  • Loading branch information
mattdrayer committed Jan 15, 2016
2 parents fdf540d + 4742e66 commit 9bcb116
Show file tree
Hide file tree
Showing 28 changed files with 1,928 additions and 186 deletions.
16 changes: 13 additions & 3 deletions cms/envs/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,6 @@
MAX_FAILED_LOGIN_ATTEMPTS_ALLOWED = ENV_TOKENS.get("MAX_FAILED_LOGIN_ATTEMPTS_ALLOWED", 5)
MAX_FAILED_LOGIN_ATTEMPTS_LOCKOUT_PERIOD_SECS = ENV_TOKENS.get("MAX_FAILED_LOGIN_ATTEMPTS_LOCKOUT_PERIOD_SECS", 15 * 60)

MICROSITE_CONFIGURATION = ENV_TOKENS.get('MICROSITE_CONFIGURATION', {})
MICROSITE_ROOT_DIR = path(ENV_TOKENS.get('MICROSITE_ROOT_DIR', ''))

#### PASSWORD POLICY SETTINGS #####
PASSWORD_MIN_LENGTH = ENV_TOKENS.get("PASSWORD_MIN_LENGTH")
PASSWORD_MAX_LENGTH = ENV_TOKENS.get("PASSWORD_MAX_LENGTH")
Expand Down Expand Up @@ -365,6 +362,19 @@
PROCTORING_BACKEND_PROVIDER = AUTH_TOKENS.get("PROCTORING_BACKEND_PROVIDER", PROCTORING_BACKEND_PROVIDER)
PROCTORING_SETTINGS = ENV_TOKENS.get("PROCTORING_SETTINGS", PROCTORING_SETTINGS)

################# MICROSITE ####################
# microsite specific configurations.
MICROSITE_CONFIGURATION = ENV_TOKENS.get('MICROSITE_CONFIGURATION', {})
MICROSITE_ROOT_DIR = path(ENV_TOKENS.get('MICROSITE_ROOT_DIR', ''))
# this setting specify which backend to be used when pulling microsite specific configuration
MICROSITE_BACKEND = ENV_TOKENS.get("MICROSITE_BACKEND", MICROSITE_BACKEND)
# this setting specify which backend to be used when loading microsite specific templates
MICROSITE_TEMPLATE_BACKEND = ENV_TOKENS.get("MICROSITE_TEMPLATE_BACKEND", MICROSITE_TEMPLATE_BACKEND)
# TTL for microsite database template cache
MICROSITE_DATABASE_TEMPLATE_CACHE_TTL = ENV_TOKENS.get(
"MICROSITE_DATABASE_TEMPLATE_CACHE_TTL", MICROSITE_DATABASE_TEMPLATE_CACHE_TTL
)

############################ OAUTH2 Provider ###################################

# OpenID Connect issuer ID. Normally the URL of the authentication endpoint.
Expand Down
19 changes: 19 additions & 0 deletions cms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,10 @@
# other apps that are. Django 1.8 wants to have imported models supported
# by installed apps.
'lms.djangoapps.verify_student',

# Microsite configuration application
'microsite_configuration',

)


Expand Down Expand Up @@ -1129,6 +1133,21 @@
'graphical_slider_tool',
]


################################ Settings for Microsites ################################

### Select an implementation for the microsite backend
# for MICROSITE_BACKEND possible choices are
# 1. microsite_configuration.backends.filebased.FilebasedMicrositeBackend
# 2. microsite_configuration.backends.database.DatabaseMicrositeBackend
MICROSITE_BACKEND = 'microsite_configuration.backends.filebased.FilebasedMicrositeBackend'
# for MICROSITE_TEMPLATE_BACKEND possible choices are
# 1. microsite_configuration.backends.filebased.FilebasedMicrositeTemplateBackend
# 2. microsite_configuration.backends.database.DatabaseMicrositeTemplateBackend
MICROSITE_TEMPLATE_BACKEND = 'microsite_configuration.backends.filebased.FilebasedMicrositeTemplateBackend'
# TTL for microsite database template cache
MICROSITE_DATABASE_TEMPLATE_CACHE_TTL = 5 * 60

#### PROCTORING CONFIGURATION DEFAULTS

PROCTORING_BACKEND_PROVIDER = {
Expand Down
44 changes: 41 additions & 3 deletions cms/envs/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@
FEATURES['EMBARGO'] = True

# set up some testing for microsites
FEATURES['USE_MICROSITES'] = True
MICROSITE_ROOT_DIR = COMMON_ROOT / 'test' / 'test_microsites'
MICROSITE_CONFIGURATION = {
"test_microsite": {
"domain_prefix": "testmicrosite",
Expand All @@ -231,15 +233,51 @@
"show_homepage_promo_video": False,
"course_index_overlay_text": "This is a Test Microsite Overlay Text.",
"course_index_overlay_logo_file": "test_microsite/images/header-logo.png",
"homepage_overlay_html": "<h1>This is a Test Microsite Overlay HTML</h1>"
"homepage_overlay_html": "<h1>This is a Test Microsite Overlay HTML</h1>",
"ALWAYS_REDIRECT_HOMEPAGE_TO_DASHBOARD_FOR_AUTHENTICATED_USER": False,
"COURSE_CATALOG_VISIBILITY_PERMISSION": "see_in_catalog",
"COURSE_ABOUT_VISIBILITY_PERMISSION": "see_about_page",
"ENABLE_SHOPPING_CART": True,
"ENABLE_PAID_COURSE_REGISTRATION": True,
"SESSION_COOKIE_DOMAIN": "test_microsite.localhost",
"urls": {
'ABOUT': 'testmicrosite/about',
'PRIVACY': 'testmicrosite/privacy',
'TOS_AND_HONOR': 'testmicrosite/tos-and-honor',
},
},
"microsite_with_logistration": {
"domain_prefix": "logistration",
"university": "logistration",
"platform_name": "Test logistration",
"logo_image_url": "test_microsite/images/header-logo.png",
"email_from_address": "test_microsite@edx.org",
"payment_support_email": "test_microsite@edx.org",
"ENABLE_MKTG_SITE": False,
"ENABLE_COMBINED_LOGIN_REGISTRATION": True,
"SITE_NAME": "test_microsite.localhost",
"course_org_filter": "LogistrationX",
"course_about_show_social_links": False,
"css_overrides_file": "test_microsite/css/test_microsite.css",
"show_partners": False,
"show_homepage_promo_video": False,
"course_index_overlay_text": "Logistration.",
"course_index_overlay_logo_file": "test_microsite/images/header-logo.png",
"homepage_overlay_html": "<h1>This is a Logistration HTML</h1>",
"ALWAYS_REDIRECT_HOMEPAGE_TO_DASHBOARD_FOR_AUTHENTICATED_USER": False,
"COURSE_CATALOG_VISIBILITY_PERMISSION": "see_in_catalog",
"COURSE_ABOUT_VISIBILITY_PERMISSION": "see_about_page",
"ENABLE_SHOPPING_CART": True,
"ENABLE_PAID_COURSE_REGISTRATION": True,
"SESSION_COOKIE_DOMAIN": "test_logistration.localhost",
},
"default": {
"university": "default_university",
"domain_prefix": "www",
}
}
MICROSITE_ROOT_DIR = COMMON_ROOT / 'test' / 'test_microsites'
FEATURES['USE_MICROSITES'] = True
MICROSITE_TEST_HOSTNAME = 'testmicrosite.testserver'
MICROSITE_LOGISTRATION_HOSTNAME = 'logistration.testserver'

# For consistency in user-experience, keep the value of this setting in sync with
# the one in lms/envs/test.py
Expand Down
13 changes: 13 additions & 0 deletions common/djangoapps/edxmako/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from django.conf import settings
from mako.lookup import TemplateLookup

from microsite_configuration import microsite
from . import LOOKUP


Expand Down Expand Up @@ -46,6 +47,18 @@ def add_directory(self, directory, prepend=False):
self._collection.clear()
self._uri_cache.clear()

def get_template(self, uri):
"""
Overridden method which will hand-off the template lookup to the microsite subsystem
"""
microsite_template = microsite.get_template(uri)

return (
microsite_template
if microsite_template
else super(DynamicTemplateLookup, self).get_template(uri)
)


def clear_lookups(namespace):
"""
Expand Down
31 changes: 31 additions & 0 deletions common/djangoapps/microsite_configuration/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,32 @@
"""
This file implements a class which is a handy utility to make any
call to the settings completely microsite aware by replacing the:
from django.conf import settings
with:
from microsite_configuration import settings
"""
from django.conf import settings as base_settings

from microsite_configuration import microsite
from .templatetags.microsite import page_title_breadcrumbs


class MicrositeAwareSettings(object):
"""
This class is a proxy object of the settings object from django.
It will try to get a value from the microsite and default to the
django settings
"""

def __getattr__(self, name):
try:
if isinstance(microsite.get_value(name), dict):
return microsite.get_dict(name, getattr(base_settings, name))
return microsite.get_value(name, getattr(base_settings, name))
except KeyError:
return getattr(base_settings, name)

settings = MicrositeAwareSettings() # pylint: disable=invalid-name
83 changes: 83 additions & 0 deletions common/djangoapps/microsite_configuration/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
"""
Django admin page for microsite models
"""
from django.contrib import admin
from django import forms

from .models import (
Microsite,
MicrositeHistory,
MicrositeOrganizationMapping,
MicrositeTemplate
)
from util.organizations_helpers import get_organizations


class MicrositeAdmin(admin.ModelAdmin):
""" Admin interface for the Microsite object. """
list_display = ('key', 'site')
search_fields = ('site__domain', 'values')

class Meta(object): # pylint: disable=missing-docstring
model = Microsite


class MicrositeHistoryAdmin(admin.ModelAdmin):
""" Admin interface for the MicrositeHistory object. """
list_display = ('key', 'site', 'created')
search_fields = ('site__domain', 'values')

ordering = ['-created']

class Meta(object): # pylint: disable=missing-docstring
model = MicrositeHistory

def has_add_permission(self, request):
"""Don't allow adds"""
return False

def has_delete_permission(self, request, obj=None):
"""Don't allow deletes"""
return False


class MicrositeOrganizationMappingForm(forms.ModelForm):
"""
Django admin form for MicrositeOrganizationMapping model
"""
def __init__(self, *args, **kwargs):
super(MicrositeOrganizationMappingForm, self).__init__(*args, **kwargs)
organizations = get_organizations()
org_choices = [(org["short_name"], org["name"]) for org in organizations]
org_choices.insert(0, ('', 'None'))
self.fields['organization'] = forms.TypedChoiceField(
choices=org_choices, required=False, empty_value=None
)

class Meta(object):
model = MicrositeOrganizationMapping
fields = '__all__'


class MicrositeOrganizationMappingAdmin(admin.ModelAdmin):
""" Admin interface for the MicrositeOrganizationMapping object. """
list_display = ('organization', 'microsite')
search_fields = ('organization', 'microsite')
form = MicrositeOrganizationMappingForm

class Meta(object): # pylint: disable=missing-docstring
model = MicrositeOrganizationMapping


class MicrositeTemplateAdmin(admin.ModelAdmin):
""" Admin interface for the MicrositeTemplate object. """
list_display = ('microsite', 'template_uri')
search_fields = ('microsite', 'template_uri')

class Meta(object): # pylint: disable=missing-docstring
model = MicrositeTemplate

admin.site.register(Microsite, MicrositeAdmin)
admin.site.register(MicrositeHistory, MicrositeHistoryAdmin)
admin.site.register(MicrositeOrganizationMapping, MicrositeOrganizationMappingAdmin)
admin.site.register(MicrositeTemplate, MicrositeTemplateAdmin)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""
Supported backends for microsites
1. filebased
This backend supports retrieval of microsite configurations/templates from filesystem.
2. database
This backend supports retrieval of microsite configurations/templates from database.
"""
Loading

0 comments on commit 9bcb116

Please sign in to comment.