-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11073 from edx/ziafazal/WL-245
Ziafazal/wl-245: multiple backend support for microsite
- Loading branch information
Showing
28 changed files
with
1,928 additions
and
186 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
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 |
This file contains 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
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) |
7 changes: 7 additions & 0 deletions
7
common/djangoapps/microsite_configuration/backends/__init__.py
This file contains 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
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. | ||
""" |
Oops, something went wrong.