def get_course(course_id):
    try:
        if not isinstance(course_id, CourseKey):
            course_id = SlashSeparatedCourseKey.from_string(course_id)
        return modulestore().get_course(course_id)
    except:
        return None
Esempio n. 2
0
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
Esempio n. 3
0
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
Esempio n. 4
0
    def get(self, request, course_name, format=None):
        """ Get course navigational elements """
        course = get_course(course_name)
        now = datetime.now(UTC())

        # try:
        #     courses = CourseEnrollment.objects.get(
        #         user=request.user, course_id=course_name, is_active=True)
        # except:
        #     return Response(status=status.HTTP_404_NOT_FOUND)

        is_enrolled = CourseEnrollment.is_enrolled(request.user, course_name)
        if not is_enrolled:
            return Response(status=status.HTTP_404_NOT_FOUND)

        result = {
            "success": True,
            "course": {
                "display_name": course.display_name,
                "location": str(course.location),
                "start": course.start,
                "children": _get_children(course_name, course.children, 'chapter', now),
            }
        }

        chapters = result['course']['children']
        for chapter in chapters:
            sequentials = chapter['children'] = _get_children(
                course_name, chapter['children'], 'sequential', now)
            for sequential in sequentials:
                verticals = sequential['children'] = _get_children(
                    course_name, sequential['children'], 'vertical', now)
                for vertical in verticals:
                    children = [get_item(course_name, 'video', item_id) for item_id in _get_item_id_list(
                        vertical['children'], 'video')]
                    children = filter(lambda x: x and x.start < now, children)
                    vertical['children'] = []
                    course_key = SlashSeparatedCourseKey.from_string(course_name)
                    for video in children:
                        data = {
                            'display_name': video.display_name,
                            'location': str(video.location),
                            'start': video.start,
                            'track_zh': get_track_zh(video, course_key),
                            'track_en': get_track_en(video, course_key),
                            'source': get_video_source(video),
                        }
                        try:
                            ccsource = video.ccsource.strip()
                            data['length'] = VideoInfo.objects.get(
                                vid=ccsource).duration
                        except:
                            data['length'] = 0

                        vertical['children'].append(data)

        return Response(result)
def get_item(course_id, category, id):
    try:
        if isinstance(course_id, basestring):
            course_id = SlashSeparatedCourseKey.from_string(course_id)
        usage_key = course_id.make_usage_key(category, id)
        data = modulestore().get_item(usage_key)
    except Exception as ex:
        log.warn(ex)
        return None

    return data
def get_items(course_id, category):
    #org, course_num, run = course_id.split("/")
    #loc = Location('i4x', org, course_num, category)
    try:
        if not isinstance(course_id, CourseKey):
            course_id = SlashSeparatedCourseKey.from_string(course_id)
        data = modulestore().get_items(course_id, qualifiers={'category':category})
    except:
        return []

    return data
Esempio n. 7
0
def delete_report_download(request, course_id):
    """
    Delete a downloaded report from the Instructor Dashboard
    """
    course_id = SlashSeparatedCourseKey.from_string(course_id)
    filename = request.POST.get('filename')
    report_store = ReportStore.from_config(config_name='GRADES_DOWNLOAD')
    report_store.delete_file(course_id, filename)
    message = {
        'status': _('The report was successfully deleted!'),
    }
    return JsonResponse(message)
 def test_deprecated_from_dep_string_bad(self):
     with self.assertDeprecationWarning():
         with self.assertRaises(InvalidKeyError):
             SlashSeparatedCourseKey.from_string("foo/bar")
 def test_deprecated_from_dep_string(self):
     with self.assertDeprecationWarning():
         ssck = SlashSeparatedCourseKey.from_string("foo/bar/baz")
     self.assertTrue(isinstance(ssck, CourseLocator))
Esempio n. 10
0
def get_visible_courses():
    """
    Return the set of CourseDescriptors that should be visible in this branded instance
    """

    # In the event we don't want any course tiles displayed
    if not getattr(settings, 'DISPLAY_COURSE_TILES', False):
        return []

    filtered_by_org = microsite.get_value('course_org_filter')
    if filtered_by_org:
        _courses = modulestore().get_courses(org=filtered_by_org)
    else:
        _courses = modulestore().get_courses()

    courses = [c for c in _courses
               if isinstance(c, CourseDescriptor)]
    courses = sorted(courses, key=lambda course: course.number)

    subdomain = microsite.get_value('subdomain', 'default')

    # 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
    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_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])
        return [course for course in courses if course.id in filtered_by_db_keys]
    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]

    subdomain = microsite.get_value('subdomain', 'default')

    # 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
    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]
Esempio n. 11
0
 def __init__(self, course_id, videoes, **kwargs):
     self.course_id = course_id
     self.course_key = SlashSeparatedCourseKey.from_string(self.course_id)
     super(VideoSerializer, self).__init__(videoes, **kwargs)
 def test_deprecated_from_string(self):
     with self.assertDeprecationWarning():
         with self.assertRaises(InvalidKeyError):
             SlashSeparatedCourseKey.from_string("slashes:foo+bar+baz")