Beispiel #1
0
 def on_get(self, model):
     import branding
     model.data = xdj.dobject()
     model.data.courses = branding.get_visible_courses()
     for item in model.data.courses:
         item.key = item.id.html_id()
     return self.render(model)
Beispiel #2
0
def get_courses(user, org=None, filter_=None):
    """
    Return a LazySequence of courses available, optionally filtered by org code (case-insensitive).
    """
    courses = branding.get_visible_courses(
        org=org,
        filter_=filter_,
    ).prefetch_related(
        Prefetch(
            'modes',
            queryset=CourseMode.objects.exclude(mode_slug__in=CourseMode.CREDIT_MODES),
            to_attr='selectable_modes',
        ),
    ).select_related(
        'image_set'
    )

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

    return LazySequence(
        (c for c in courses if has_access(user, permission_name, c)),
        est_len=courses.count()
    )
Beispiel #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
Beispiel #4
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
Beispiel #5
0
def get_courses(user, org=None, filter_=None):
    """
    Return a LazySequence of courses available, optionally filtered by org code (case-insensitive).
    """
    courses = branding.get_visible_courses(
        org=org,
        filter_=filter_,
    ).prefetch_related(
        Prefetch(
            'modes',
            queryset=CourseMode.objects.exclude(mode_slug__in=CourseMode.CREDIT_MODES),
            to_attr='selectable_modes',
        ),
    ).select_related(
        'image_set'
    )

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

    return LazySequence(
        (c for c in courses if has_access(user, permission_name, c)),
        est_len=courses.count()
    )
Beispiel #6
0
def get_programming(user, org=None, filter_={'course_subject':'programming'}):
    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    
Beispiel #7
0
def get_courses_by_search(domain=None):
    """
    Returns a list of courses available, sorted by course.number
    """
    courses = branding.get_visible_courses()
    # courses = [c for c in courses if has_access(user, c, 'see_exists')]

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

    return courses
def get_courses(user, domain=None):
    '''
    Returns a list of courses available, sorted by course.number
    '''
    courses = branding.get_visible_courses()
    courses = [c for c in courses if has_access(user, 'see_exists', c)]

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

    return courses
Beispiel #9
0
def courses(request, show_hidden):
    """
    Renders the courses list for the API.

    :param request: The django HttpRequest object.
    :param show_hidden: True or False, (controlled from the urls.py file) to show courses with
                        upcoming enrollment date.

    :return: JsonResponse with a list of the courses.
    """
    courses_list = branding.get_visible_courses()

    if not show_hidden:
        # Using `AnonymousUser()` to hide unpublished courses
        anonymous_user = AnonymousUser()

        # The logic bellow has been copied (with amendments) from `courseware.courses.get_courses`,
        # Just in case something changes with edX releases.
        permission_name = settings.COURSE_CATALOG_VISIBILITY_PERMISSION

        courses_list = [
            c for c in courses_list
            if has_access(anonymous_user, permission_name, c)
        ]

    courses_list = sort_by_announcement(courses_list)
    courses_list = edraak_courses_logic(courses_list)

    courses_json_list = []

    prefix = get_absolute_url_prefix(request)

    for course in courses_list:
        video_tag = get_course_about_section(course, "video")
        youtube_id = video_tag[video_tag.find("embed") + 6:video_tag.find("?")]

        courses_json_list.append({
            "id": unicode(course.id),
            "number": course.display_number_with_default,
            "name": course.display_name_with_default,
            "organization": course.display_org_with_default,
            "description": get_course_about_section(course, "short_description").strip(),
            "startDate": course.start,
            "endDate": course.end,
            "enrollmentStartDate": course.enrollment_start,
            "enrollmentEndDate": course.enrollment_end,
            "overview": get_course_about_section(course, "overview").strip(),
            "aboutPage": prefix + reverse('about_course', args=[unicode(course.id)]),
            "image": prefix + course_image_url(course),
            "state": _get_course_status(course),
            "youtube_id": youtube_id,
            "effort": get_course_about_section(course, "effort").strip(),
        })

    return JsonResponse(courses_json_list)
Beispiel #10
0
def get_courses1(request, user, domain=None):

    courses = branding.get_visible_courses()
    courses = [c for c in courses if has_access(user, 'see_exists', c)]
    search_name = ''
    if 's_text' in request.GET:
        search_name = request.GET['s_text']
    courses = [c for c in courses if course_select(search_name, c)]
    courses = sorted(courses, key=lambda course: course.number)

    return courses
Beispiel #11
0
def get_courses1(request,user, domain=None):
    
    courses = branding.get_visible_courses()
    courses = [c for c in courses if has_access(user, 'see_exists', c)]
    search_name=''
    if 's_text' in request.GET:
	    search_name=request.GET['s_text']
    courses = [c for c in courses if course_select(search_name, c)]
    courses = sorted(courses, key=lambda course: course.number)

    return courses
Beispiel #12
0
def get_courses2(request, user, domain=None):

    courses = branding.get_visible_courses()
    courses = [c for c in courses if has_access(user, 'see_exists', c)]
    c_name = ''
    if 'name' in request.GET:
        c_name = request.GET['name']
    courses = [c for c in courses if cat_select(c_name, c)]

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

    return courses
Beispiel #13
0
def get_courses2(request,user, domain=None):
    
    courses = branding.get_visible_courses()
    courses = [c for c in courses if has_access(user, 'see_exists', c)]
    c_name=''
    if 'name' in request.GET:
        c_name=request.GET['name']
    courses = [c for c in courses if cat_select(c_name, c)]
    
    courses = sorted(courses, key=lambda course: course.number)

    return courses
Beispiel #14
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).
    """
    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
Beispiel #15
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).
    """
    courses = branding.get_visible_courses(org=org, filter_=filter_)

    permission_name = microsite.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
    def doLoadItems(self, sender):
        """
        https://programtalk.com/python-examples-amp/student.models.anonymous_id_for_user/
        :param sender:
        :return:
        """

        import branding
        import courseware
        from xdj_models.enities import courseware as cw
        from xdj import pymqr
        from xdj import medxdb
        from django.contrib.auth.models import User
        import sysadmin
        import datetime
        from django.db.models import Q

        # courseware.models.StudentModule.objects.all()[0].student.last_name
        ret = branding.get_visible_courses()
        qr = pymqr.query(medxdb.db(), cw.modulestore_active_versions)
        for item in ret:
            # course = courseware.models.StudentModule.objects.get(course_id=item.id)
            x = qr.new().match(pymqr.filters.org==item.id.org)\
                .match(pymqr.filters.run==item.id.run)\
                .match(pymqr.filters.course==item.id.course).object

            #     .match(pymqr.funcs.expr(
            #     (pymqr.docs.org == item.id.org) &
            #     (pymqr.docs.run == item.id.run) &
            #     (pymqr.docs.course == item.id.course)
            # )).object
            from xdj_models.models import CourseAuthors
            fx = CourseAuthors()()
            item.course_id = item.id.__str__()
            if not x.is_empty():
                authors = User.objects.filter(id=x.edited_by)
                if authors.__len__() > 0:
                    sql_items = CourseAuthors().objects.filter(
                        Q(user_id=x.edited_by) & Q(course_id=item.id)).count()
                    item.author = xdj.dobject(username=authors[0].username)
                    if sql_items == 0:
                        fx.user_id = x.edited_by
                        fx.course_id = item.id
                        fx.created_on = datetime.datetime.now()
                        fx.save()
            item.totalActiveStudent = courseware.models.StudentModule.objects.filter(
                course_id=item.id).filter(module_type="course").count()
            """calculate total activates students"""

        return ret
Beispiel #17
0
def get_courses(user, domain=None):
    """
    Returns a list of courses available, sorted by course.number
    """
    courses = branding.get_visible_courses()

    permission_name = microsite.get_value(
        "COURSE_CATALOG_VISIBILITY_PERMISSION", settings.COURSE_CATALOG_VISIBILITY_PERMISSION
    )

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

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

    return courses
Beispiel #18
0
def get_courses(user, domain=None, org=None):  # pylint: disable=unused-argument
    """
    Returns a list of courses available, sorted by course.number and optionally
    filtered by org code (case-insensitive).
    """
    courses = branding.get_visible_courses(org=org)

    permission_name = microsite.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
Beispiel #19
0
def get_courses(user, domain=None):
    '''
    Returns a list of courses available, sorted by course.number
    '''
    courses = branding.get_visible_courses()

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

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

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

    return courses
Beispiel #20
0
def get_courses(user, domain=None):
    '''
    Returns a list of courses available, sorted by course.number
    '''
    #取得所有的可见课程。
    courses = branding.get_visible_courses()
    #取得线程参数的键值
    permission_name = microsite.get_value(
        'COURSE_CATALOG_VISIBILITY_PERMISSION',
        settings.COURSE_CATALOG_VISIBILITY_PERMISSION
    )
    #
    courses = [c for c in courses if has_access(user, permission_name, c)]

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

    return courses
Beispiel #21
0
def get_courses_id(user,course_id,uni=None,course=None,courseName=None,domain=None):

    courses=None
    if uni is not None:
        courses = branding.get_course_by_courseid(course_id,uni=1)
    elif course is not None:
        courses = branding.get_course_by_courseid(course_id,courseId=1)
    elif courseName is not None:

        courses = branding.get_course_by_courseid(course_id,courseName=1)
    else:
        courses = branding.get_visible_courses(domain)

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

    courses = sorted(courses, key=lambda course: course.number)
    return courses
Beispiel #22
0
def get_courses_id(user,
                   course_id,
                   uni=None,
                   course=None,
                   courseName=None,
                   domain=None):

    courses = None
    if uni is not None:
        courses = branding.get_course_by_courseid(course_id, uni=1)
    elif course is not None:
        courses = branding.get_course_by_courseid(course_id, courseId=1)
    elif courseName is not None:

        courses = branding.get_course_by_courseid(course_id, courseName=1)
    else:
        courses = branding.get_visible_courses(domain)

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

    courses = sorted(courses, key=lambda course: course.number)
    return courses
Beispiel #23
0
def get_courses(user, org=None, filter_=None, batch_size=100):
    """
    Return a LazySequence of courses available, optionally filtered by org code (case-insensitive).
    """
    courses_qset = branding.get_visible_courses(
        org=org,
        filter_=filter_,
    ).select_related('image_set').prefetch_related(
        Prefetch(
            'modes',
            queryset=CourseMode.objects.exclude(
                mode_slug__in=CourseMode.CREDIT_MODES),
            to_attr='selectable_modes',
        ), )

    permission_name = configuration_helpers.get_value(
        'COURSE_CATALOG_VISIBILITY_PERMISSION',
        settings.COURSE_CATALOG_VISIBILITY_PERMISSION)
    if user.is_authenticated:
        prefetch_related_objects([user], 'roles', 'experimentdata_set')

        def with_prefetched_users():
            for courses in batch_iterator(courses_qset, batch_size=batch_size):
                prefetch_related_objects(
                    [user],
                    Prefetch(
                        'courseenrollment_set',
                        queryset=CourseEnrollment.objects.filter(
                            user=user,
                            course__in=courses).select_related('schedule')))
                for course in courses:
                    if has_access(user, permission_name, course):
                        yield course

        course_iterator = with_prefetched_users()
    else:
        course_iterator = (c for c in iterator(courses_qset)
                           if has_access(user, permission_name, c))
    return LazySequence(course_iterator, est_len=courses_qset.count())
Beispiel #24
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).
    """
    # [COLARAZ_CUSTOM]
    # Manage course visibility to anonymous users
    if (not user or not user.is_authenticated) and not configuration_helpers.get_value(
            'SHOW_COURSES_TO_ANONYMOUS_USERS',
            settings.SHOW_COURSES_TO_ANONYMOUS_USERS
        ):
        return []

    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
Beispiel #25
0
    def _courses_with_access_type(self, data, access_type):
        """
        Utility function to list all courses for a user according to the
        access type.

        The field `data` follows the handler specification in:

            `oauth2_provider/oidc/handlers.py`

        """

        user = data['user']
        values = set(data.get('values', []))

        courses = branding.get_visible_courses()
        courses = (c for c in courses if has_access(user, access_type, c))
        course_ids = (unicode(c.id) for c in courses)

        # If values was provided, return only the requested authorized courses
        if values:
            return [c for c in course_ids if c in values]
        else:
            return [c for c in course_ids]
Beispiel #26
0
    def _courses_with_access_type(self, data, access_type):
        """
        Utility function to list all courses for a user according to the
        access type.

        The field `data` follows the handler specification in:

            `oauth2_provider/oidc/handlers.py`

        """

        user = data['user']
        values = set(data.get('values', []))

        courses = branding.get_visible_courses()
        courses = (c for c in courses if has_access(user, access_type, c))
        course_ids = (unicode(c.id) for c in courses)

        # If values was provided, return only the requested authorized courses
        if values:
            return [c for c in course_ids if c in values]
        else:
            return [c for c in course_ids]
Beispiel #27
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).
    """
    include_hidden = filter_.pop('include_hidden', False) if filter_ else False
    courses = branding.get_visible_courses(org=org, filter_=filter_)

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

    # see_in_catalog is the permission that checks the catalog visibility setting.
    # include_hidden refers to showing courses that are normally not visible due to this setting.
    # We don't want to show courses that are hidden for other reasons, which is why we don't
    # use the override for other permissions.
    if permission_name is 'see_in_catalog':
        courses = [
            c for c in courses
            if include_hidden or has_access(user, permission_name, c)
        ]
    else:
        courses = [c for c in courses if has_access(user, permission_name, c)]
    return courses
Beispiel #28
0
def courses(request, show_hidden):
    """
    Renders the courses list for the API.

    :param request: The django HttpRequest object.
    :param show_hidden: True or False, (controlled from the urls.py file) to show courses with
                        upcoming enrollment date.

    :return: JsonResponse with a list of the courses.
    """
    courses_list = branding.get_visible_courses()

    if not show_hidden:
        # Using `AnonymousUser()` to hide unpublished courses
        anonymous_user = AnonymousUser()

        # The logic bellow has been copied (with amendments) from `courseware.courses.get_courses`,
        # Just in case something changes with edX releases.
        permission_name = settings.COURSE_CATALOG_VISIBILITY_PERMISSION

        courses_list = [
            c for c in courses_list
            if has_access(anonymous_user, permission_name, c)
        ]

    courses_list = sort_by_announcement(courses_list)
    courses_list = edraak_courses_logic(courses_list)

    courses_json_list = []

    prefix = get_absolute_url_prefix(request)

    for course_overview in courses_list:

        try:
            course = get_course(course_overview.id)

            video_tag = get_course_about_section(request, course, "video")
            youtube_id = video_tag[video_tag.find("embed") + 6:video_tag.find("?")]

            courses_json_list.append({
                "id": unicode(course.id),
                "number": course.display_number_with_default,
                "name": course.display_name_with_default_escaped,
                "organization": course.display_org_with_default,
                "description": get_course_about_section(request, course, "short_description").strip(),
                "startDate": course.start,
                "endDate": course.end,
                "enrollmentStartDate": course.enrollment_start,
                "enrollmentEndDate": course.enrollment_end,
                "overview": get_course_about_section(request, course, "overview").strip(),
                "aboutPage": prefix + reverse('about_course', args=[unicode(course.id)]),
                "image": prefix + course_image_url(course),
                "state": _get_course_status(course),
                "youtube_id": youtube_id,
                "effort": get_course_about_section(request, course, "effort").strip(),
            })
        except ValueError:
            log.error(u"Course with id '{0}' not found".format(course_overview.id))


    return JsonResponse(courses_json_list)
Beispiel #29
0
 def get_object_list(self, request):
     return mount_course_object_list(get_visible_courses())
Beispiel #30
0
def get_course_by_author(user, auther):
    
    courses = branding.get_visible_courses()
    courses = [c for c in courses if has_access(user, 'see_exists', c)]
    
    return [course for course in courses if auther == list_with_level_username(course, 'instructor')]
Beispiel #31
0
def get_courses_by_name(user, input_name):
    
    courses = branding.get_visible_courses()
    courses = [c for c in courses if has_access(user, 'see_exists', c)]

    return [course for course in courses if get_course_about_section(course, 'title') == input_name]
Beispiel #32
0
def get_courses_by_org(user, input_org):
    
    courses = branding.get_visible_courses()
    courses = [c for c in courses if has_access(user, 'see_exists', c)]

    return [course for course in courses if course.location.org == input_org]