def footer(request): """Retrieve the branded footer. This end-point provides information about the site footer, allowing for consistent display of the footer across other sites (for example, on the marketing site and blog). It can be used in one of two ways: 1) A client renders the footer from a JSON description. 2) A browser loads an HTML representation of the footer and injects it into the DOM. The HTML includes CSS and JavaScript links. In case (2), we assume that the following dependencies are included on the page: a) JQuery (same version as used in edx-platform) b) font-awesome (same version as used in edx-platform) c) Open Sans web fonts Example: Retrieving the footer as JSON GET /api/branding/v1/footer Accepts: application/json { "navigation_links": [ { "url": "http://example.com/about", "name": "about", "title": "About" }, # ... ], "social_links": [ { "url": "http://example.com/social", "name": "facebook", "icon-class": "fa-facebook-square", "title": "Facebook", "action": "Sign up on Facebook!" }, # ... ], "mobile_links": [ { "url": "http://example.com/android", "name": "google", "image": "http://example.com/google.png", "title": "Google" }, # ... ], "legal_links": [ { "url": "http://example.com/terms-of-service.html", "name": "terms_of_service", "title': "Terms of Service" }, # ... ], "openedx_link": { "url": "http://open.edx.org", "title": "Powered by Open edX", "image": "http://example.com/openedx.png" }, "logo_image": "http://example.com/static/images/logo.png", "copyright": "EdX, Open edX, and the edX and Open edX logos are \ registered trademarks or trademarks of edX Inc." } Example: Retrieving the footer as HTML GET /api/branding/v1/footer Accepts: text/html Example: Including the footer with the "Powered by OpenEdX" logo GET /api/branding/v1/footer?show-openedx-logo=1 Accepts: text/html Example: Retrieving the footer in a particular language GET /api/branding/v1/footer?language=en Accepts: text/html Example: Retrieving the footer with all JS and CSS dependencies (for testing) GET /api/branding/v1/footer?include-dependencies=1 Accepts: text/html """ if not branding_api.is_enabled(): raise Http404 # Use the content type to decide what representation to serve accepts = request.META.get('HTTP_ACCEPT', '*/*') # Show the OpenEdX logo in the footer show_openedx_logo = bool(request.GET.get('show-openedx-logo', False)) # Include JS and CSS dependencies # This is useful for testing the end-point directly. include_dependencies = bool(request.GET.get('include-dependencies', False)) # Override the language if necessary language = request.GET.get('language', translation.get_language()) # Render the footer information based on the extension if 'text/html' in accepts or '*/*' in accepts: cache_key = u"branding.footer.{params}.html".format( params=urllib.urlencode({ 'language': language, 'show_openedx_logo': show_openedx_logo, 'include_dependencies': include_dependencies, }) ) content = cache.get(cache_key) if content is None: with translation.override(language): content = _render_footer_html(request, show_openedx_logo, include_dependencies) cache.set(cache_key, content, settings.FOOTER_CACHE_TIMEOUT) return HttpResponse(content, status=200, content_type="text/html; charset=utf-8") elif 'application/json' in accepts: cache_key = u"branding.footer.{params}.json".format( params=urllib.urlencode({ 'language': language, 'is_secure': request.is_secure(), }) ) footer_dict = cache.get(cache_key) if footer_dict is None: with translation.override(language): footer_dict = branding_api.get_footer(is_secure=request.is_secure()) cache.set(cache_key, footer_dict, settings.FOOTER_CACHE_TIMEOUT) return JsonResponse(footer_dict, 200, content_type="application/json; charset=utf-8") else: return HttpResponse(status=406)
def branding_context_processor(request): # pylint: disable=unused-argument """Add the feature flag to Django template context. """ return { "ENABLE_BRANDING_API": branding_api.is_enabled() }
def footer(request): """Retrieve the branded footer. This end-point provides information about the site footer, allowing for consistent display of the footer across other sites (for example, on the marketing site and blog). It can be used in one of two ways: 1) A client renders the footer from a JSON description. 2) A browser loads an HTML representation of the footer and injects it into the DOM. The HTML includes CSS and JavaScript links. In case (2), we assume that the following dependencies are included on the page: a) JQuery (same version as used in edx-platform) b) font-awesome (same version as used in edx-platform) c) Open Sans web fonts Example: Retrieving the footer as JSON GET /api/branding/v1/footer Accepts: application/json { "navigation_links": [ { "url": "http://example.com/about", "name": "about", "title": "About" }, # ... ], "social_links": [ { "url": "http://example.com/social", "name": "facebook", "icon-class": "fa-facebook-square", "title": "Facebook", "action": "Sign up on Facebook!" }, # ... ], "mobile_links": [ { "url": "http://example.com/android", "name": "google", "image": "http://example.com/google.png", "title": "Google" }, # ... ], "legal_links": [ { "url": "http://example.com/terms-of-service.html", "name": "terms_of_service", "title': "Terms of Service" }, # ... ], "openedx_link": { "url": "http://open.edx.org", "title": "Powered by Open edX", "image": "http://example.com/openedx.png" }, "logo_image": "http://example.com/static/images/logo.png", "copyright": "edX, Open edX and their respective logos are registered trademarks of edX Inc." } Example: Retrieving the footer as HTML GET /api/branding/v1/footer Accepts: text/html Example: Including the footer with the "Powered by Open edX" logo GET /api/branding/v1/footer?show-openedx-logo=1 Accepts: text/html Example: Retrieving the footer in a particular language GET /api/branding/v1/footer?language=en Accepts: text/html Example: Retrieving the footer with a language selector GET /api/branding/v1/footer?include-language-selector=1 Accepts: text/html Example: Retrieving the footer with all JS and CSS dependencies (for testing) GET /api/branding/v1/footer?include-dependencies=1 Accepts: text/html """ if not branding_api.is_enabled(): raise Http404 # Use the content type to decide what representation to serve accepts = request.META.get('HTTP_ACCEPT', '*/*') # Show the OpenEdX logo in the footer show_openedx_logo = bool(request.GET.get('show-openedx-logo', False)) # Include JS and CSS dependencies # This is useful for testing the end-point directly. include_dependencies = bool(request.GET.get('include-dependencies', False)) # Override the language if necessary language = request.GET.get('language', translation.get_language()) try: language = get_supported_language_variant(language) except LookupError: language = settings.LANGUAGE_CODE # Include a language selector include_language_selector = request.GET.get('include-language-selector', '') == '1' # Render the footer information based on the extension if 'text/html' in accepts or '*/*' in accepts: cache_params = { 'language': language, 'show_openedx_logo': show_openedx_logo, 'include_dependencies': include_dependencies } if include_language_selector: cache_params['language_selector_options'] = ','.join( sorted([lang.code for lang in released_languages()])) cache_key = u"branding.footer.{params}.html".format( params=six.moves.urllib.parse.urlencode(cache_params)) content = cache.get(cache_key) if content is None: with translation.override(language): content = _render_footer_html(request, show_openedx_logo, include_dependencies, include_language_selector, language) cache.set(cache_key, content, settings.FOOTER_CACHE_TIMEOUT) return HttpResponse(content, status=200, content_type="text/html; charset=utf-8") elif 'application/json' in accepts: cache_key = u"branding.footer.{params}.json".format( params=six.moves.urllib.parse.urlencode( { 'language': language, 'is_secure': request.is_secure(), })) footer_dict = cache.get(cache_key) if footer_dict is None: with translation.override(language): footer_dict = branding_api.get_footer( is_secure=request.is_secure()) cache.set(cache_key, footer_dict, settings.FOOTER_CACHE_TIMEOUT) return JsonResponse(footer_dict, 200, content_type="application/json; charset=utf-8") else: return HttpResponse(status=406)
def branding_context_processor(request): # pylint: disable=unused-argument """Add the feature flag to Django template context. """ return {"ENABLE_BRANDING_API": branding_api.is_enabled()}