示例#1
0
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
示例#2
0
"""
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)