コード例 #1
0
def get_visible_courses(org=None, filter_=None):
    """
    Return the set of CourseOverviews that should be visible in this branded
    instance.

    Arguments:
        org (string): Optional parameter that allows case-insensitive
            filtering by organization.
        filter_ (dict): Optional parameter that allows custom filtering by
            fields on the course.
    """
    microsite_org = microsite.get_value('course_org_filter')

    if org and microsite_org:
        # When called in the context of a microsite, return an empty result if the org
        # passed by the caller does not match the designated microsite org.
        courses = CourseOverview.get_all_courses(
            org=org,
            filter_=filter_,
        ) if org == microsite_org else []
    else:
        # We only make it to this point if one of org or microsite_org is defined.
        # If both org and microsite_org were defined, the code would have fallen into the
        # first branch of the conditional above, wherein an equality check is performed.
        target_org = org or microsite_org
        courses = CourseOverview.get_all_courses(org=target_org,
                                                 filter_=filter_)

    courses = sorted(courses, key=lambda course: course.number)

    # When called in the context of a microsite, filtering can stop here.
    if microsite_org:
        return courses

    # See if we have filtered course listings in this domain
    filtered_visible_ids = None

    # this is legacy format which is outside of the microsite feature -- also handle dev case, which should not filter
    subdomain = microsite.get_value('subdomain', 'default')
    if hasattr(
            settings, 'COURSE_LISTINGS'
    ) and subdomain in settings.COURSE_LISTINGS and not settings.DEBUG:
        filtered_visible_ids = frozenset([
            SlashSeparatedCourseKey.from_deprecated_string(c)
            for c in settings.COURSE_LISTINGS[subdomain]
        ])

    if filtered_visible_ids:
        return [
            course for course in courses if course.id in filtered_visible_ids
        ]
    else:
        # Filter out any courses belonging to a microsite, to avoid leaking these.
        microsite_orgs = microsite.get_all_orgs()
        return [
            course for course in courses
            if course.location.org not in microsite_orgs
        ]
コード例 #2
0
ファイル: __init__.py プロジェクト: ntakma/edx-platform-1
def get_visible_courses(org=None, filter_=None):
    """
    Yield the CourseOverviews that should be visible in this branded
    instance.

    Arguments:
        org (string): Optional parameter that allows case-insensitive
            filtering by organization.
        filter_ (dict): Optional parameter that allows custom filtering by
            fields on the course.
    """
    # Import is placed here to avoid model import at project startup.
    from openedx.core.djangoapps.content.course_overviews.models import CourseOverview

    current_site_orgs = configuration_helpers.get_current_site_orgs()

    courses = CourseOverview.objects.none()

    if org:
        # Check the current site's orgs to make sure the org's courses should be displayed
        if not current_site_orgs or org in current_site_orgs:
            courses = CourseOverview.get_all_courses(orgs=[org],
                                                     filter_=filter_)
    elif current_site_orgs:
        # Only display courses that should be displayed on this site
        courses = CourseOverview.get_all_courses(orgs=current_site_orgs,
                                                 filter_=filter_)
    else:
        courses = CourseOverview.get_all_courses(filter_=filter_)

    courses = courses.order_by('id')

    # Filtering can stop here.
    if current_site_orgs:
        return courses

    # See if we have filtered course listings in this domain
    filtered_visible_ids = None

    # this is legacy format, which also handle dev case, which should not filter
    subdomain = configuration_helpers.get_value('subdomain', 'default')
    if hasattr(
            settings, 'COURSE_LISTINGS'
    ) and subdomain in settings.COURSE_LISTINGS and not settings.DEBUG:
        filtered_visible_ids = frozenset([
            CourseKey.from_string(c)
            for c in settings.COURSE_LISTINGS[subdomain]
        ])

    if filtered_visible_ids:
        return courses.filter(id__in=filtered_visible_ids)
    else:
        # Filter out any courses based on current org, to avoid leaking these.
        orgs = configuration_helpers.get_all_orgs()
        return courses.exclude(org__in=orgs)
コード例 #3
0
ファイル: __init__.py プロジェクト: vesloguzov/edx-platform
def get_visible_courses(org=None, filter_=None):
    """
    Return the set of CourseOverviews that should be visible in this branded
    instance.

    Arguments:
        org (string): Optional parameter that allows case-insensitive
            filtering by organization.
        filter_ (dict): Optional parameter that allows custom filtering by
            fields on the course.
    """
    courses = []
    current_site_orgs = configuration_helpers.get_current_site_orgs()

    if org:
        # Check the current site's orgs to make sure the org's courses should be displayed
        if not current_site_orgs or org in current_site_orgs:
            courses = CourseOverview.get_all_courses(orgs=[org],
                                                     filter_=filter_)
    elif current_site_orgs:
        # Only display courses that should be displayed on this site
        courses = CourseOverview.get_all_courses(orgs=current_site_orgs,
                                                 filter_=filter_)
    else:
        courses = CourseOverview.get_all_courses(filter_=filter_)

    courses = sorted(courses, key=lambda course: course.number)

    # Filtering can stop here.
    if current_site_orgs:
        return courses

    # See if we have filtered course listings in this domain
    filtered_visible_ids = None

    # this is legacy format, which also handle dev case, which should not filter
    subdomain = configuration_helpers.get_value('subdomain', 'default')
    if hasattr(
            settings, 'COURSE_LISTINGS'
    ) and subdomain in settings.COURSE_LISTINGS and not settings.DEBUG:
        filtered_visible_ids = frozenset([
            CourseKey.from_string(c)
            for c in settings.COURSE_LISTINGS[subdomain]
        ])

    if filtered_visible_ids:
        return [
            course for course in courses if course.id in filtered_visible_ids
        ]
    else:
        # Filter out any courses based on current org, to avoid leaking these.
        orgs = configuration_helpers.get_all_orgs()
        return [
            course for course in courses if course.location.org not in orgs
        ]
コード例 #4
0
def get_visible_courses(org=None, filter_=None):
    """
    Yield the CourseOverviews that should be visible in this branded
    instance.

    Arguments:
        org (string): Optional parameter that allows case-insensitive
            filtering by organization.
        filter_ (dict): Optional parameter that allows custom filtering by
            fields on the course.
    """
    # Import is placed here to avoid model import at project startup.
    from openedx.core.djangoapps.content.course_overviews.models import CourseOverview

    current_site_orgs = configuration_helpers.get_current_site_orgs()

    courses = CourseOverview.objects.none()

    if org:
        # Check the current site's orgs to make sure the org's courses should be displayed
        if not current_site_orgs or org in current_site_orgs:
            courses = CourseOverview.get_all_courses(orgs=[org], filter_=filter_)
    elif current_site_orgs:
        # Only display courses that should be displayed on this site
        courses = CourseOverview.get_all_courses(orgs=current_site_orgs, filter_=filter_)
    else:
        courses = CourseOverview.get_all_courses(filter_=filter_)

    courses = courses.order_by('id')

    # Filtering can stop here.
    if current_site_orgs:
        return courses

    # See if we have filtered course listings in this domain
    filtered_visible_ids = None

    # this is legacy format, which also handle dev case, which should not filter
    subdomain = configuration_helpers.get_value('subdomain', 'default')
    if hasattr(settings, 'COURSE_LISTINGS') and subdomain in settings.COURSE_LISTINGS and not settings.DEBUG:
        filtered_visible_ids = frozenset(
            [CourseKey.from_string(c) for c in settings.COURSE_LISTINGS[subdomain]]
        )

    if filtered_visible_ids:
        return courses.filter(id__in=filtered_visible_ids)
    else:
        # Filter out any courses based on current org, to avoid leaking these.
        orgs = configuration_helpers.get_all_orgs()
        return courses.exclude(org__in=orgs)
コード例 #5
0
def get_visible_courses(org=None, filter_=None):
    """
    Return the set of CourseOverviews that should be visible in this branded
    instance.

    Arguments:
        org (string): Optional parameter that allows case-insensitive
            filtering by organization.
        filter_ (dict): Optional parameter that allows custom filtering by
            fields on the course.
    """
    microsite_org = microsite.get_value('course_org_filter')

    if org and microsite_org:
        # When called in the context of a microsite, return an empty result if the org
        # passed by the caller does not match the designated microsite org.
        courses = CourseOverview.get_all_courses(
            org=org,
            filter_=filter_,
        ) if org == microsite_org else []
    else:
        # We only make it to this point if one of org or microsite_org is defined.
        # If both org and microsite_org were defined, the code would have fallen into the
        # first branch of the conditional above, wherein an equality check is performed.
        target_org = org or microsite_org
        courses = CourseOverview.get_all_courses(org=target_org, filter_=filter_)

    courses = sorted(courses, key=lambda course: course.number)

    # When called in the context of a microsite, filtering can stop here.
    if microsite_org:
        return courses

    # See if we have filtered course listings in this domain
    filtered_visible_ids = None

    # this is legacy format which is outside of the microsite feature -- also handle dev case, which should not filter
    subdomain = microsite.get_value('subdomain', 'default')
    if hasattr(settings, 'COURSE_LISTINGS') and subdomain in settings.COURSE_LISTINGS and not settings.DEBUG:
        filtered_visible_ids = frozenset(
            [SlashSeparatedCourseKey.from_deprecated_string(c) for c in settings.COURSE_LISTINGS[subdomain]]
        )

    if filtered_visible_ids:
        return [course for course in courses if course.id in filtered_visible_ids]
    else:
        # Filter out any courses belonging to a microsite, to avoid leaking these.
        microsite_orgs = microsite.get_all_orgs()
        return [course for course in courses if course.location.org not in microsite_orgs]
コード例 #6
0
ファイル: courses.py プロジェクト: caesar2164/edx-platform
def get_courses(user, org=None, filter_=None):
    """
    Returns a list of courses available, sorted by course.number and optionally
    filtered by org code (case-insensitive).
    """
    # In the event we don't want any course tiles displayed
    if not getattr(settings, 'DISPLAY_COURSE_TILES', False):
        return []
    courses = CourseOverview.get_all_courses(org=None, filter_=None)
    filtered_by_db = TileConfiguration.objects.filter(
        enabled=True,
    ).values('course_id').order_by('-change_date')
    if filtered_by_db:
        filtered_by_db_ids = [course['course_id'] for course in filtered_by_db]
        filtered_by_db_keys = frozenset([SlashSeparatedCourseKey.from_string(c) for c in filtered_by_db_ids])
        courses = [
            course
            for course in courses
            if course.id in filtered_by_db_keys
        ]
        return courses

    courses = branding.get_visible_courses(org=org, filter_=filter_)

    permission_name = configuration_helpers.get_value(
        'COURSE_CATALOG_VISIBILITY_PERMISSION',
        settings.COURSE_CATALOG_VISIBILITY_PERMISSION
    )

    courses = [c for c in courses if has_access(user, permission_name, c)]

    return courses
コード例 #7
0
    def handle(self, *args, **options):
        course_id = options['course']
        org = options['org']
        from_mode = options['from_mode']
        to_mode = options['to_mode']
        commit = options['commit']
        course_keys = []
        if course_id:
            try:
                course_key = CourseKey.from_string(course_id)
            except InvalidKeyError:
                raise CommandError('Course ID {} is invalid.'.format(course_id))

            if modulestore().get_course(course_key) is None:
                raise CommandError('The given course {} does not exist.'.format(course_id))

            course_keys.append(course_key)
        else:
            course_keys = [course.id for course in CourseOverview.get_all_courses(orgs=[org])]
            if not course_keys:
                raise CommandError('No courses exist for the org "{}".'.format(org))

        for course_key in course_keys:
            self.move_users_for_course(course_key, from_mode, to_mode, commit)

        if not commit:
            logger.info('Dry run, changes have not been saved. Run again with "commit" argument to save changes')
コード例 #8
0
    def handle(self, *args, **options):
        course_id = options['course']
        org = options['org']
        from_mode = options['from_mode']
        to_mode = options['to_mode']
        commit = options['commit']
        course_keys = []

        if course_id:
            try:
                course_key = CourseKey.from_string(course_id)
            except InvalidKeyError:
                raise CommandError('Course ID {} is invalid.'.format(course_id))

            if modulestore().get_course(course_key) is None:
                raise CommandError('The given course {} does not exist.'.format(course_id))

            course_keys.append(course_key)
        else:
            course_keys = [course.id for course in CourseOverview.get_all_courses(orgs=[org])]
            if not course_keys:
                raise CommandError('No courses exist for the org "{}".'.format(org))

        for course_key in course_keys:
            self.move_users_for_course(course_key, from_mode, to_mode, commit)

        if not commit:
            logger.info('Dry run, changes have not been saved. Run again with "commit" argument to save changes')
コード例 #9
0
ファイル: courses.py プロジェクト: tkim135/edx-platform
def get_courses(user, org=None, filter_=None):
    """
    Returns a list of courses available, sorted by course.number and optionally
    filtered by org code (case-insensitive).
    """
    # In the event we don't want any course tiles displayed
    if not getattr(settings, 'DISPLAY_COURSE_TILES', False):
        return []
    courses = CourseOverview.get_all_courses(org=None, filter_=None)
    filtered_by_db = TileConfiguration.objects.filter(
        enabled=True, ).values('course_id').order_by('-change_date')
    if filtered_by_db:
        filtered_by_db_ids = [course['course_id'] for course in filtered_by_db]
        filtered_by_db_keys = frozenset([
            SlashSeparatedCourseKey.from_string(c) for c in filtered_by_db_ids
        ])
        courses = [
            course for course in courses if course.id in filtered_by_db_keys
        ]
        return courses

    courses = branding.get_visible_courses(org=org, filter_=filter_)

    permission_name = configuration_helpers.get_value(
        'COURSE_CATALOG_VISIBILITY_PERMISSION',
        settings.COURSE_CATALOG_VISIBILITY_PERMISSION)

    courses = [c for c in courses if has_access(user, permission_name, c)]

    return courses
コード例 #10
0
ファイル: __init__.py プロジェクト: tadesanya/edx-platform
def get_visible_courses():
    """
    Return the set of CourseDescriptors that should be visible in this branded instance
    """
    filtered_by_org = microsite.get_value('course_org_filter')
    courses = CourseOverview.get_all_courses(org=filtered_by_org)
    courses = sorted(courses, key=lambda course: course.number)

    # See if we have filtered course listings in this domain
    filtered_visible_ids = None

    # this is legacy format which is outside of the microsite feature -- also handle dev case, which should not filter
    subdomain = microsite.get_value('subdomain', 'default')
    if hasattr(settings, 'COURSE_LISTINGS') and subdomain in settings.COURSE_LISTINGS and not settings.DEBUG:
        filtered_visible_ids = frozenset(
            [SlashSeparatedCourseKey.from_deprecated_string(c) for c in settings.COURSE_LISTINGS[subdomain]]
        )

    if filtered_by_org:
        return [course for course in courses if course.location.org == filtered_by_org]
    if filtered_visible_ids:
        return [course for course in courses if course.id in filtered_visible_ids]
    else:
        # Let's filter out any courses in an "org" that has been declared to be
        # in a Microsite
        org_filter_out_set = microsite.get_all_orgs()
        return [course for course in courses if course.location.org not in org_filter_out_set]
コード例 #11
0
    def handle(self, *args, **options):
        course_id = options.get('course')
        org = options.get('org')
        from_mode = options.get('from_mode')
        to_mode = options.get('to_mode')
        commit = options.get('commit')

        if (not course_id and not org) or (course_id and org):
            raise CommandError('You must provide either a course ID or an org, but not both.')

        if from_mode is None or to_mode is None:
            raise CommandError('Both `from` and `to` course modes must be given.')

        course_keys = []
        if course_id:
            try:
                course_key = CourseKey.from_string(course_id)
            except InvalidKeyError:
                raise CommandError('Course ID {} is invalid.'.format(course_id))

            if modulestore().get_course(course_key) is None:
                raise CommandError('The given course {} does not exist.'.format(course_id))

            course_keys.append(course_key)
        else:
            course_keys = [course.id for course in CourseOverview.get_all_courses(orgs=[org])]
            if not course_keys:
                raise CommandError('No courses exist for the org "{}".'.format(org))

        for course_key in course_keys:
            self.move_users_for_course(course_key, from_mode, to_mode, commit)

        if not commit:
            logger.info('Dry run, changes have not been saved. Run again with "commit" argument to save changes')
コード例 #12
0
def get_visible_courses(org=None, filter_=None):
    """
    Return the set of CourseOverviews that should be visible in this branded
    instance.

    Arguments:
        org (string): Optional parameter that allows case-insensitive
            filtering by organization.
        filter_ (dict): Optional parameter that allows custom filtering by
            fields on the course.
    """
    courses = []
    current_site_orgs = configuration_helpers.get_current_site_orgs()

    if org:
        # Check the current site's orgs to make sure the org's courses should be displayed
        if not current_site_orgs or org in current_site_orgs:
            courses = CourseOverview.get_all_courses(orgs=[org], filter_=filter_)
    elif current_site_orgs:
        # Only display courses that should be displayed on this site
        courses = CourseOverview.get_all_courses(orgs=current_site_orgs, filter_=filter_)
    else:
        courses = CourseOverview.get_all_courses(filter_=filter_)

    courses = sorted(courses, key=lambda course: course.number)

    # Filtering can stop here.
    if current_site_orgs:
        return courses

    # See if we have filtered course listings in this domain
    filtered_visible_ids = None

    # this is legacy format, which also handle dev case, which should not filter
    subdomain = configuration_helpers.get_value('subdomain', 'default')
    if hasattr(settings, 'COURSE_LISTINGS') and subdomain in settings.COURSE_LISTINGS and not settings.DEBUG:
        filtered_visible_ids = frozenset(
            [SlashSeparatedCourseKey.from_deprecated_string(c) for c in settings.COURSE_LISTINGS[subdomain]]
        )

    if filtered_visible_ids:
        return [course for course in courses if course.id in filtered_visible_ids]
    else:
        # Filter out any courses based on current org, to avoid leaking these.
        orgs = configuration_helpers.get_all_orgs()
        return [course for course in courses if course.location.org not in orgs]
コード例 #13
0
    def handle(self, *args, **options):

        if options['all']:
            # Have CourseOverview generate course overviews for all
            # the courses in the system.
            CourseOverview.get_all_courses(force_reseeding=True)
        else:
            course_keys = []
            if len(args) < 1:
                raise CommandError('At least one course or --all must be specified.')
            try:
                course_keys = [CourseKey.from_string(arg) for arg in args]
            except InvalidKeyError:
                log.fatal('Invalid key specified.')

            if not course_keys:
                log.fatal('No courses specified.')

            CourseOverview.get_select_courses(course_keys)
コード例 #14
0
    def handle(self, *args, **options):
        course_id = options.get('course')
        org = options.get('org')
        from_mode = options.get('from_mode')
        to_mode = options.get('to_mode')
        commit = options.get('commit')

        if (not course_id and not org) or (course_id and org):
            raise CommandError(
                'You must provide either a course ID or an org, but not both.')

        if from_mode is None or to_mode is None:
            raise CommandError(
                'Both `from` and `to` course modes must be given.')

        course_keys = []
        if course_id:
            try:
                course_key = CourseKey.from_string(course_id)
            except InvalidKeyError:
                raise CommandError(
                    'Course ID {} is invalid.'.format(course_id))

            if modulestore().get_course(course_key) is None:
                raise CommandError(
                    'The given course {} does not exist.'.format(course_id))

            course_keys.append(course_key)
        else:
            course_keys = [
                course.id
                for course in CourseOverview.get_all_courses(orgs=[org])
            ]
            if not course_keys:
                raise CommandError(
                    'No courses exist for the org "{}".'.format(org))

        for course_key in course_keys:
            self.move_users_for_course(course_key, from_mode, to_mode, commit)

        if not commit:
            logger.info(
                'Dry run, changes have not been saved. Run again with "commit" argument to save changes'
            )
コード例 #15
0
    def handle(self, *args, **options):
        course_id = None
        if len(args) == 1:
            course_id = CourseKey.from_string(args[0])

        course_keys = [course_id] if course_id else (
            overview.id for overview in CourseOverview.get_all_courses())

        for course_key in course_keys:
            users_with_profiles = CompletionProfile.objects.filter(
                course_key=course_key).values_list('user_id', flat=True)
            users_without_profiles = User.objects.exclude(
                id__in=users_with_profiles)

            for user in users_without_profiles:
                LOG.info(
                    'Creating a new Completion Profile for user %s and course %s',
                    user.username, course_key)
                CompletionProfile.objects.create(user=user,
                                                 course_key=course_key)
コード例 #16
0
ファイル: test_api.py プロジェクト: AlexxNica/edx-platform
 def setUpClass(cls):
     super(CourseApiTestMixin, cls).setUpClass()
     cls.request_factory = APIRequestFactory()
     CourseOverview.get_all_courses()  # seed the CourseOverview table
コード例 #17
0
 def setUpClass(cls):
     super(CourseApiTestMixin, cls).setUpClass()
     cls.request_factory = APIRequestFactory()
     CourseOverview.get_all_courses()  # seed the CourseOverview table
コード例 #18
0
    def handle(self, *args, **options):
        output = '\n'.join(
            text_type(course_overview.id)
            for course_overview in CourseOverview.get_all_courses()) + '\n'

        return output
コード例 #19
0
    def handle(self, *args, **options):
        output = u'\n'.join(unicode(course_overview.id) for course_overview in CourseOverview.get_all_courses()) + '\n'

        return output
コード例 #20
0
def get_visible_courses(org=None, filter_=None):
    """
    Return the set of CourseOverviews that should be visible in this branded
    instance.

    Arguments:
        org (string): Optional parameter that allows case-insensitive
            filtering by organization.
        filter_ (dict): Optional parameter that allows custom filtering by
            fields on the course.
    """
    current_site_org = configuration_helpers.get_value('course_org_filter')

    if isinstance(current_site_org, list):
        courses = []
        for org in current_site_org:
            _partial = CourseOverview.get_all_courses(org=org, filter_=filter_)
            courses = courses + list(_partial)

    elif org and current_site_org:
        # Return an empty result if the org passed by the caller does not match the designated site org.
        courses = CourseOverview.get_all_courses(
            org=org,
            filter_=filter_,
        ) if org == current_site_org else []
    else:
        # We only make it to this point if one of org or current_site_org is defined.
        # If both org and current_site_org were defined, the code would have fallen into the
        # first branch of the conditional above, wherein an equality check is performed.
        target_org = org or current_site_org
        courses = CourseOverview.get_all_courses(org=target_org, filter_=filter_)

    courses = sorted(courses, key=lambda course: course.number)

    # Filtering can stop here.
    if current_site_org:
        return courses

    # See if we have filtered course listings in this domain
    filtered_visible_ids = None

    # this is legacy format, which also handle dev case, which should not filter
    subdomain = configuration_helpers.get_value('subdomain', 'default')
    if hasattr(settings, 'COURSE_LISTINGS') and subdomain in settings.COURSE_LISTINGS and not settings.DEBUG:
        filtered_visible_ids = frozenset(
            [SlashSeparatedCourseKey.from_deprecated_string(c) for c in settings.COURSE_LISTINGS[subdomain]]
        )

    filtered_by_org = configuration_helpers.get_value('course_org_filter')

    if filtered_by_org and isinstance(filtered_by_org, basestring):
        return [course for course in courses if course.location.org == filtered_by_org]
    if filtered_by_org and isinstance(filtered_by_org, list):
        return [course for course in courses if course.location.org in filtered_by_org]
    if filtered_visible_ids:
        return [course for course in courses if course.id in filtered_visible_ids]
    else:
        # Let's filter out any courses in an "org" that has been declared to be
        # in a Microsite
        org_filter_out_set = microsite.get_all_orgs()
        return [course for course in courses if course.location.org not in org_filter_out_set]