コード例 #1
0
ファイル: test_wrappers.py プロジェクト: grinderz/eox-tenant
    def test_imported_module_is_used(self, import_mock):
        """
        Testing the backend is imported and used
        """
        backend = Mock()
        import_mock.side_effect = backend

        site_configuration_module.get_configuration_helpers()

        import_mock.assert_called()
        backend.assert_called()
コード例 #2
0
ファイル: enrollments.py プロジェクト: grinderz/eox-tenant
def filter_enrollments(enrollments):
    """
    Given a list of enrollment objects, we filter out the enrollments to orgs that
    do not belong to the current microsite
    """

    theming_helpers = get_theming_helpers()
    test_skip = getattr(settings, "EOX_TENANT_SKIP_FILTER_FOR_TESTS", False)
    # If test setting is true, returns the same enrollments,
    # or if we do not have a microsite context, there is nothing we can do.
    if test_skip or not theming_helpers.is_request_in_themed_site():
        for enrollment in enrollments:
            yield enrollment
        return

    configuration_helpers = get_configuration_helpers()
    orgs_to_include = configuration_helpers.get_value('course_org_filter',
                                                      None)
    orgs_to_exclude = []

    # Make sure we have a list
    if orgs_to_include and not isinstance(orgs_to_include, list):
        orgs_to_include = [orgs_to_include]

    if not orgs_to_include:
        # Making orgs_to_include an empty iterable
        orgs_to_include = []
        orgs_to_exclude = configuration_helpers.get_all_orgs()

    for enrollment in enrollments:

        org = enrollment.course_id.org

        # Filter out anything that is not attributed to the inclusion rule.
        if org not in orgs_to_include:
            continue

        # Conversely, filter out any enrollments with courses attributed to exclusion rule.
        elif org in orgs_to_exclude:
            continue

        # Else, include the enrollment.
        else:
            yield enrollment
コード例 #3
0
ファイル: ednx.py プロジェクト: grinderz/eox-tenant
Template tags and helper functions for displaying breadcrumbs in page titles
based on the current micro site.
"""
import warnings

from django import template
from django.conf import settings
from django.contrib.staticfiles.storage import staticfiles_storage
from django.templatetags.static import static
from django.utils.translation import get_language_bidi

from eox_tenant.edxapp_wrapper.branding_api import get_branding_api
from eox_tenant.edxapp_wrapper.site_configuration_module import get_configuration_helpers
from eox_tenant.edxapp_wrapper.theming_helpers import get_theming_helpers

configuration_helpers = get_configuration_helpers()
branding_api = get_branding_api()
theming_helpers = get_theming_helpers()

register = template.Library()  # pylint: disable=invalid-name


@register.simple_tag(name="favicon_path")
def favicon_path(default=getattr(settings, 'FAVICON_PATH',
                                 'images/favicon.ico')):
    """
    Django template tag that outputs the configured favicon:
    {% favicon_path %}
    """
    path = configuration_helpers.get_value('favicon_path', default)
    return path if path.startswith("http") else staticfiles_storage.url(path)
コード例 #4
0
ファイル: middleware.py プロジェクト: grinderz/eox-tenant
import re

from django.conf import settings
from django.contrib.sites.shortcuts import get_current_site
from django.http import Http404, HttpResponseNotFound
from django.utils import six
from django.utils.deprecation import MiddlewareMixin
from opaque_keys import InvalidKeyError
from opaque_keys.edx.keys import CourseKey

from eox_tenant.edxapp_wrapper.edxmako_module import get_edxmako_module
from eox_tenant.edxapp_wrapper.site_configuration_module import get_configuration_helpers
from eox_tenant.edxapp_wrapper.theming_helpers import get_theming_helpers
from eox_tenant.tenant_wise.proxies import TenantSiteConfigProxy

configuration_helper = get_configuration_helpers()  # pylint: disable=invalid-name
theming_helper = get_theming_helpers()
HOST_VALIDATION_RE = re.compile(
    r"^(?:[0-9]{1,3}\.){3}[0-9]{1,3}(:[0-9]{2,5})?$")
LOG = logging.getLogger(__name__)


class MicrositeCrossBrandingFilterMiddleware():
    """
    Middleware class that prevents a course defined in a branded ORG trough a microsite, to be displayed
    on a different microsite with a different branding.
    """
    def process_request(self, request):
        """
        Raise an 404 exception if the course being rendered belongs to an ORG in a
        microsite, but it is not the current microsite