Implement theme admin UI to support previewing
LEARNER-2017
This commit is contained in:
@@ -8,6 +8,7 @@ from django.conf import settings
|
||||
from django.contrib.staticfiles.storage import staticfiles_storage
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import render_to_response
|
||||
from edxmako.shortcuts import is_any_marketing_link_set, is_marketing_link_set, marketing_link
|
||||
from web_fragments.views import FragmentView
|
||||
|
||||
log = logging.getLogger('plugin_api')
|
||||
@@ -17,8 +18,6 @@ class EdxFragmentView(FragmentView):
|
||||
"""
|
||||
The base class of all Open edX fragment views.
|
||||
"""
|
||||
USES_PATTERN_LIBRARY = True
|
||||
|
||||
page_title = None
|
||||
|
||||
@staticmethod
|
||||
@@ -78,6 +77,44 @@ class EdxFragmentView(FragmentView):
|
||||
for js_file in self.js_dependencies():
|
||||
fragment.add_javascript_url(staticfiles_storage.url(js_file))
|
||||
|
||||
def create_base_standalone_context(self, request, fragment, **kwargs):
|
||||
"""
|
||||
Creates the base context for rendering a fragment as a standalone page.
|
||||
"""
|
||||
return {
|
||||
'uses_pattern_library': True,
|
||||
'disable_accordion': True,
|
||||
'allow_iframing': True,
|
||||
'disable_header': True,
|
||||
'disable_footer': True,
|
||||
'disable_window_wrap': True,
|
||||
}
|
||||
|
||||
def _add_studio_standalone_context_variables(self, request, context):
|
||||
"""
|
||||
Adds Studio-specific context variables for fragment standalone pages.
|
||||
|
||||
Note: this is meant to be a temporary hack to ensure that Studio
|
||||
receives the context variables that are expected by some of its
|
||||
shared templates. Ideally these templates shouldn't depend upon
|
||||
this data being provided but should instead import the functionality
|
||||
it needs.
|
||||
"""
|
||||
context.update({
|
||||
'request': request,
|
||||
'settings': settings,
|
||||
'EDX_ROOT_URL': settings.EDX_ROOT_URL,
|
||||
'marketing_link': marketing_link,
|
||||
'is_any_marketing_link_set': is_any_marketing_link_set,
|
||||
'is_marketing_link_set': is_marketing_link_set,
|
||||
})
|
||||
|
||||
def standalone_page_title(self, request, fragment, **kwargs):
|
||||
"""
|
||||
Returns the page title for the standalone page, or None if there is no title.
|
||||
"""
|
||||
return None
|
||||
|
||||
def render_standalone_response(self, request, fragment, **kwargs):
|
||||
"""
|
||||
Renders a standalone page for the specified fragment.
|
||||
@@ -86,14 +123,18 @@ class EdxFragmentView(FragmentView):
|
||||
"""
|
||||
if fragment is None:
|
||||
return HttpResponse(status=204)
|
||||
context = {
|
||||
'uses-pattern-library': self.USES_PATTERN_LIBRARY,
|
||||
context = self.create_base_standalone_context(request, fragment, **kwargs)
|
||||
self._add_studio_standalone_context_variables(request, context)
|
||||
context.update({
|
||||
'settings': settings,
|
||||
'fragment': fragment,
|
||||
'disable_accordion': True,
|
||||
'allow_iframing': True,
|
||||
'disable_header': True,
|
||||
'disable_footer': True,
|
||||
'disable_window_wrap': True,
|
||||
}
|
||||
return render_to_response(settings.STANDALONE_FRAGMENT_VIEW_TEMPLATE, context)
|
||||
'page_title': self.standalone_page_title(request, fragment, **kwargs),
|
||||
})
|
||||
if context.get('uses_pattern_library', False):
|
||||
template = 'fragments/standalone-page-v2.html'
|
||||
elif context.get('uses_bootstrap', False):
|
||||
template = 'fragments/standalone-page-bootstrap.html'
|
||||
else:
|
||||
template = 'fragments/standalone-page-v1.html'
|
||||
|
||||
return render_to_response(template, context)
|
||||
|
||||
Reference in New Issue
Block a user