コード例 #1
0
    def test_get_courses_by_org(self):
        """
        Verify that org filtering performs as expected, and that an empty result
        is returned if the org passed by the caller does not match the designated
        org.
        """
        primary = 'primary'
        alternate = 'alternate'

        def _fake_get_value(value, default=None):
            """Used to stub out site_configuration.helpers.get_value()."""
            if value == 'course_org_filter':
                return alternate

            return default

        user = UserFactory.create()

        # Pass `emit_signals=True` so that these courses are cached with CourseOverviews.
        primary_course = CourseFactory.create(org=primary, emit_signals=True)
        alternate_course = CourseFactory.create(org=alternate, emit_signals=True)

        self.assertNotEqual(primary_course.org, alternate_course.org)

        unfiltered_courses = get_courses(user)
        for org in [primary_course.org, alternate_course.org]:
            self.assertTrue(
                any(course.org == org for course in unfiltered_courses)
            )

        filtered_courses = get_courses(user, org=primary)
        self.assertTrue(
            all(course.org == primary_course.org for course in filtered_courses)
        )

        with mock.patch(
            'openedx.core.djangoapps.site_configuration.helpers.get_value',
            autospec=True,
        ) as mock_get_value:
            mock_get_value.side_effect = _fake_get_value

            # Request filtering for an org distinct from the designated org.
            no_courses = get_courses(user, org=primary)
            self.assertEqual(no_courses, [])

            # Request filtering for an org matching the designated org.
            site_courses = get_courses(user, org=alternate)
            self.assertTrue(
                all(course.org == alternate_course.org for course in site_courses)
            )
コード例 #2
0
ファイル: views.py プロジェクト: louyihua/edx-ss
def search_courses(request):
    """
    Render "find courses" page.  The course selection work is done in courseware.courses.
    """
    courses = get_courses1(request,request.user, request.META.get('HTTP_HOST'))
    courses = sort_by_announcement(courses)
    c_list=[]
    c_num=[]
    c_len=CourseCategory.objects.all().count()
    for i in range(1,c_len+1):
	    c_name=CourseCategory.objects.get(id = i).category_name
	    c_list.append(c_name)
    all_courses = get_courses(request.user, request.META.get('HTTP_HOST'))
    all_c_num = len(all_courses)
    for j in range(1,17):
	    c_num.append(0)
    for c in all_courses:
        c_category = c.display_number_with_default[0:2]
        c_category_no = int(c_category)
        num_t=c_num[c_category_no-1]
        c_num[c_category_no-1]=num_t+1
    name_list=[]
    category_list=[]
    category_num=[]
    for i in range (0,len(c_num)):
        if c_num[i]!=0:
            if i<9:
                num='0'+str(int(i+1))
                name_list.append(num)
            else:
                name_list.append(i+1)
            category_list.append(c_list[i])
            category_num.append(c_num[i])
    none_zero=len(category_num)
    return render_to_response("courseware/courses.html", {'courses': courses,'name_list':name_list,'category_list':category_list,'category_num':category_num,'all_c_num':all_c_num,'none_zero':none_zero})
コード例 #3
0
ファイル: views.py プロジェクト: louyihua/edx-ss
def get_search_category(request):
    courses = get_courses2(request,request.user, request.META.get('HTTP_HOST'))
    courses = sort_by_announcement(courses)
    json_list=json_courses(request,courses)
    decodejson = json.loads(json_list)
    c_list=[]
    c_num=[]
    c_len=CourseCategory.objects.all().count()
    for i in range(1,c_len+1):
	    c_name=CourseCategory.objects.get(id = i).category_name
	    c_list.append(c_name)
    all_courses = get_courses(request.user, request.META.get('HTTP_HOST'))
    all_c_num = len(all_courses)
    for j in range(1,17):
	    c_num.append(0)
    for c in all_courses:
        c_category = c.display_number_with_default[0:2]
        c_category_no = int(c_category)
        num_t=c_num[c_category_no-1]
        c_num[c_category_no-1]=num_t+1
    decodejson.append(c_list)
    decodejson.append(c_num)
    decodejson.append(all_c_num)
    decodejson.append(c_len)

    return JsonResponse(decodejson)
コード例 #4
0
def courses_search(request):
    """
    Render "find courses" page.  The course selection work is done in courseware.courses.
    """
    if request.is_ajax():
        query_string=""
        courses=[]
        query_string = request.GET['search_string']
        if query_string is not None:
            print "----------------------------------"+query_string+"\n"
            entry_query=normalize_query(query_string)
            allCourses = get_courses(request.user, request.META.get('HTTP_HOST'))
            for course in allCourses:
                title=get_course_about_section(course,'title').lower()
                flag=True
                for query in entry_query:
                    if not query.lower() in title:
                        flag=False
                        break
                if flag:
                    courses.append(course)
            courses = sort_by_announcement(courses)
            
            if courses:
                return render_to_response("courseware/courses_search.html", {'courses': courses})
            else:
                return HttpResponse("No Courses Found")
コード例 #5
0
ファイル: views.py プロジェクト: a-nassif/edraak
def courses(request):
    """
    Render "find courses" page.  The course selection work is done in courseware.courses.
    """
    courses = get_courses(request.user, request.META.get('HTTP_HOST'))[:9]
    courses = sort_by_announcement(courses)

    return render_to_response("courseware/courses.html", {'courses': courses, 'homepage_promo_video_youtube_id': 'yY2gsC8bL3U'})
コード例 #6
0
def drop_courses(request):
    r = list()
    courses = get_courses(None)
    for course in courses:
        course = course_from_id(course.id)
        r.append({"id": course.id, "name": str(course.display_coursenumber) + ' ' + course.display_name})
    r.sort(key=lambda x: x['name'], reverse=False)
    return HttpResponse(json.dumps(r), content_type="application/json")
コード例 #7
0
ファイル: views.py プロジェクト: BenjiLee/edx-platform
def courses(request):
    """
    Render "find courses" page.  The course selection work is done in courseware.courses.
    """
    courses = get_courses(request.user, request.META.get('HTTP_HOST'))
    courses = sort_by_announcement(courses)

    return render_to_response("courseware/courses.html", {'courses': courses})
コード例 #8
0
ファイル: views.py プロジェクト: XiaodunServerGroup/ddyedx
def courses_list_handler(request, action):
    """
    Return courses based on request params
    """
    try:
        user = request.user
    except:
        user = AnonymousUser()

    if action not in ["homefalls", "all", "hot", "latest", "my", "search", "rolling", "sync"]:
        return JsonResponse({"success": False, "errmsg": "not support other actions except homefalls all hot latest rolling and my"})

    def get_courses_depend_action(courses):
        """
        Return courses depend on action
            action: [homefalls, hot, lastest, my, search]
                homefalls: get all courses
                hot: Number of attended people > ?
                lastest: News last week
                my: I registered
                all: like 'homefalls'
        """
        courses = sort_and_audited_items(courses)
        courses_list = []

        if action == "latest":
            default_count = 20
            if len(courses) < default_count:
                default_count = len(courses)

            courses_list = courses[0:default_count]
        elif action == "my":
            # filter my registered courses
            for course in courses:
                if registered_for_course(course, user):
                    courses_list.append(course)
        elif action == "rolling":
            default_count = 5
            courses_list = courses[0:default_count]
        elif action == 'search':
            keyword = request.GET.get("keyword")

            if keyword:
                for c in courses:
                    if keyword in c.org or keyword in c.id or keyword in c.display_name_with_default:
                        courses_list.append(c)
        else:
            courses_list = courses

        return courses_list

    courses = get_courses(user, request.META.get('HTTP_HOST'))
    if action != "sync":
        courses = get_courses_depend_action(courses)

    return return_fixed_courses(request, courses, action)
コード例 #9
0
ファイル: views.py プロジェクト: jirkamarsik/fun-apps
def get_filtered_course_infos(request):
    course_infos = get_course_infos(get_courses(request.user))
    pattern = request.GET.get('search')

    if pattern:
        course_infos = [course for course in course_infos
                if pattern in course.title
                or pattern in course.course.id.to_deprecated_string()]

    return course_infos, pattern
コード例 #10
0
ファイル: views.py プロジェクト: XiaodunServerGroup/ddyedx
def audit_courses(request, user=AnonymousUser()):
    # The course selection work is done in courseware.courses.
    domain = settings.FEATURES.get('FORCE_UNIVERSITY_DOMAIN')  # normally False
    # do explicit check, because domain=None is valid
    if domain is False:
        domain = request.META.get('HTTP_HOST')

    courses = get_courses(user, domain=domain)

    return filter_audited_items(sort_by_announcement(courses))
コード例 #11
0
ファイル: management.py プロジェクト: appsembler/edx-platform
def index(request, extra_context=None, user=AnonymousUser()):
    """
    Render the edX main page.

    extra_context is used to allow immediate display of certain modal windows, eg signup,
    as used by external_auth.
    """
    if extra_context is None:
        extra_context = {}

    courses = get_courses(user)

    if configuration_helpers.get_value(
            "ENABLE_COURSE_SORTING_BY_START_DATE",
            settings.FEATURES["ENABLE_COURSE_SORTING_BY_START_DATE"],
    ):
        courses = sort_by_start_date(courses)
    else:
        courses = sort_by_announcement(courses)

    context = {'courses': courses}

    context['homepage_overlay_html'] = configuration_helpers.get_value('homepage_overlay_html')

    # This appears to be an unused context parameter, at least for the master templates...
    context['show_partners'] = configuration_helpers.get_value('show_partners', True)

    # TO DISPLAY A YOUTUBE WELCOME VIDEO
    # 1) Change False to True
    context['show_homepage_promo_video'] = configuration_helpers.get_value('show_homepage_promo_video', False)

    # Maximum number of courses to display on the homepage.
    context['homepage_course_max'] = configuration_helpers.get_value(
        'HOMEPAGE_COURSE_MAX', settings.HOMEPAGE_COURSE_MAX
    )

    # 2) Add your video's YouTube ID (11 chars, eg "123456789xX"), or specify via site configuration
    # Note: This value should be moved into a configuration setting and plumbed-through to the
    # context via the site configuration workflow, versus living here
    youtube_video_id = configuration_helpers.get_value('homepage_promo_video_youtube_id', "your-youtube-id")
    context['homepage_promo_video_youtube_id'] = youtube_video_id

    # allow for theme override of the courses list
    context['courses_list'] = theming_helpers.get_template_path('courses_list.html')

    # Insert additional context for use in the template
    context.update(extra_context)

    # Add marketable programs to the context.
    context['programs_list'] = get_programs_with_type(request.site, include_hidden=False)

    # TODO: Course Listing Plugin required
    context['journal_info'] = get_journals_context(request)

    return render_to_response('index.html', context)
コード例 #12
0
ファイル: views.py プロジェクト: nicky-ji/edx-nicky
def jump_to(request, school_key_string):
    org = school_key_string
    course_list = []
    courses = get_courses(request.user, request.META.get('HTTP_HOST'))
    for course in courses:
        if course.display_org_with_default == org:
             course_list.append(course)
    return render_to_response("colleges/school_about.html", {
        "course_list": course_list,
        "org": org,
    })
コード例 #13
0
ファイル: views.py プロジェクト: alexmerser/lms
def courses(request):
    """
    Render "find courses" page.  The course selection work is done in courseware.courses.
    """
    courses = get_courses(request.user, request.META.get('HTTP_HOST'))

    if microsite.get_value("ENABLE_COURSE_SORTING_BY_START_DATE",
                           settings.FEATURES["ENABLE_COURSE_SORTING_BY_START_DATE"]):
        courses = sort_by_start_date(courses)
    else:
        courses = sort_by_announcement(courses)

    return render_to_response("courseware/courses.html", {'courses': courses})
コード例 #14
0
def courses(request):
    """
    Render "find courses" page.  The course selection work is done in courseware.courses.
    """
    courses = get_courses(request.user, request.META.get('HTTP_HOST'))
    courses = sort_by_announcement(courses)
    universities = []
    for course in courses:
        university = get_course_about_section(course,'university')
        if not university in universities:
            universities.append(university)
    universities.sort()
    return render_to_response("courseware/courses.html", {'courses': courses,'universities':universities})
コード例 #15
0
def university_search(request,org_id=""):
    if request.is_ajax():
        query_university=org_id
        courses = []
        allCourses = get_courses(request.user, request.META.get('HTTP_HOST'))
        if query_university is not None:
            for course in allCourses:
                university=get_course_about_section(course,'university')
                if (query_university.lower() in university.lower()) and (university.lower() in query_university.lower()):
                    courses.append(course) 
        if courses:
            return render_to_response("courseware/courses_search.html",{'courses':courses})
        else:
            return HttpResponse("No Courses Found")
コード例 #16
0
ファイル: courses.py プロジェクト: aureliencroq/fun-apps
def get_university_courses(user, university_code):
    """
    Returns an array containing courses object for the given
    organization.
    """
    courses = get_courses(user)
    if university_code == "other":
        # "other" courses that are associated to organizations that are not
        # listed in the university page.
        university_codes = University.objects.values_list('code', flat=True)
        courses = [c for c in courses if c.org not in university_codes]
    else:
        courses = [c for c in courses if c.org == university_code]
    courses = sort_by_announcement(courses)
    return courses
コード例 #17
0
ファイル: views.py プロジェクト: wwj718/murp-edx
def course_list(request, extra_context={}, user=AnonymousUser()):
    def course_filter(course,org='ncepu',subject=''):
        #print request    
        if course.org == org:
            return True
        return False	
    domain = settings.FEATURES.get('FORCE_UNIVERSITY_DOMAIN')
    if domain is False:
        domain = request.META.get('HTTP_HOST')
    courses = get_courses(user, domain=domain)
    courses = filter(course_filter,courses)
    courses = sort_by_announcement(courses)
    context = {'courses': courses,'request':request}
    #return render_to_response('murp/selects.html',context)
    return render_to_response('murp/mytest.html',context)
コード例 #18
0
ファイル: views.py プロジェクト: XiaodunServerGroup/ddyedx
def course_attr_list_handler(request, course_category, course_level=None):

    courses = get_courses(request.user, request.META.get('HTTP_HOST'))
    courses = sort_and_audited_items(courses)
    courses_list = []

    for course in courses:
        if course_level:
            if course.course_level == course_level and course.course_category == course_category:
                courses_list.append(course)
        elif course.course_category == course_category:
            courses_list.append(course)
        else:
            continue

    return return_fixed_courses(request, courses_list, None)
コード例 #19
0
def major_search(request):
    major_result = request.POST
    major_s = major_result.get('search').lower()
    major_m = major_result.get('major_name').lower()#choise major
    major_g = major_result.get('grade').lower()#choice grade
    course_select=[]
    courses_L = get_courses(request.user, request.META.get('HTTP_HOST'))

    courses_L = sort_by_announcement(courses_L)
    if major_s==None:
        return render_to_response("courseware/courses.html", {'courses': courses_L})
    else:
        for course in courses_L:
            major_title=get_course_about_section(course, 'title').lower()
            if major_s in major_title:
                course_select.append(course)
        return render_to_response("courseware/courses.html", {'courses': course_select})
コード例 #20
0
ファイル: views.py プロジェクト: louyihua/edx-buaa
def courses(request):
    """
    Render "find courses" page.  The course selection work is done in courseware.courses.
    """
    courses = sort_by_announcement(get_courses(request.user, request.META.get('HTTP_HOST')))
    course_list = []
    for course in courses:
        course_item = {
            "display_number": course.display_number_with_default,
            "course_title": get_course_about_section(course, 'title'),
            "course_description": get_course_about_section(course, 'short_description'),
            "display_organization": get_course_about_section(course, 'university'),
            "course_image_url": course_image_url(course),
            "course_start": course.start,
            "course_id": course.id.to_deprecated_string(),
        }
        course_list.append(course_item)

    return JsonResponse(course_list)
コード例 #21
0
ファイル: test_courses.py プロジェクト: hastexo/edx-platform
    def test_get_courses_with_filter(self):
        """
        Verify that filtering performs as expected.
        """
        user = UserFactory.create()
        non_mobile_course = CourseFactory.create(emit_signals=True)
        mobile_course = CourseFactory.create(mobile_available=True, emit_signals=True)

        test_cases = (
            (None, {non_mobile_course.id, mobile_course.id}),
            (dict(mobile_available=True), {mobile_course.id}),
            (dict(mobile_available=False), {non_mobile_course.id}),
        )
        for filter_, expected_courses in test_cases:
            self.assertEqual(
                {course.id for course in get_courses(user, filter_=filter_)},
                expected_courses,
                "testing get_courses with filter_={}".format(filter_),
            )
コード例 #22
0
ファイル: views.py プロジェクト: torchingloom/edx-platform
def courses_list(request, status = "all", subject="all", destiny="all"):
    all_courses =  get_courses(request.user)
    courses = []
    for course in all_courses:
        if (status == "new"):
            if (not course.is_newish): continue
        elif (status ==  "past"):
            if (not course.has_ended()): continue
        elif (status == "current"):
            if (not course.has_started()): continue
        elif (status != "all"):
            continue
        if (subject != "all"):
            if not (subject in course.tags or dict(SUBJECTS).get(subject, '') in course.tags): continue
        if (destiny != "all"):
            if not (destiny in course.tags or dict(DESTINY).get(destiny, '') in course.tags): continue
        courses += [course]
    courses = sort_by_announcement(courses)
    context = {'courses': courses, 'destiny': destiny, 'subject': subject}
    return render_to_response("courses_list.html", context)
コード例 #23
0
ファイル: views.py プロジェクト: louyihua/edx-ss
def search_category(request):
    courses = get_courses2(request,request.user, request.META.get('HTTP_HOST'))
    courses = sort_by_announcement(courses)
    c_list=[]
    c_num=[]
    c_len=CourseCategory.objects.all().count()
    for i in range(1,c_len+1):
	    c_name=CourseCategory.objects.get(id = i).category_name
	    c_list.append(c_name)
    all_courses = get_courses(request.user, request.META.get('HTTP_HOST'))
    all_c_num = len(all_courses)
    for j in range(1,17):
	    c_num.append(0)
    for c in all_courses:
        c_category = c.display_number_with_default[0:2]
        c_category_no = int(c_category)
        num_t=c_num[c_category_no-1]
        c_num[c_category_no-1]=num_t+1
    
    return render_to_response("courseware/courses.html", {'courses': courses,'c_list':c_list,'c_num':c_num,'all_c_num':all_c_num})
コード例 #24
0
ファイル: views.py プロジェクト: nageshgoyal/edx-platform
def index(request, extra_context={}, user=None):
    '''
    Render the edX main page.

    extra_context is used to allow immediate display of certain modal windows, eg signup,
    as used by external_auth.
    '''

    # The course selection work is done in courseware.courses.
    domain = settings.MITX_FEATURES.get('FORCE_UNIVERSITY_DOMAIN')  # normally False
    # do explicit check, because domain=None is valid
    if domain == False:
        domain = request.META.get('HTTP_HOST')

    courses = get_courses(None, domain=domain)
    courses = sort_by_announcement(courses)

    context = {'courses': courses}
    context.update(extra_context)
    return render_to_response('index.html', context)
コード例 #25
0
ファイル: views.py プロジェクト: altsen/diandiyun-platform
    def get_courses_depend_action():
        """
        Return courses depend on action
            action: [homefalls, hot, lastest, my, search]
                homefalls: get all courses
                hot: Number of attended people > ?
                lastest: News last week
                my: I registered
                all: like 'homefalls'
        """

        courses = get_courses(user, request.META.get('HTTP_HOST'))
        courses = sort_by_announcement(courses)
        courses_list = []

        if action == "latest":
            default_count = 20
            if len(courses) < default_count:
                default_count = len(courses)

            courses_list = courses[0:default_count]
        elif action == "my":
            # filter my registered courses
            for course in courses:
                if registered_for_course(course, user):
                    courses_list.append(course)
        elif action == "rolling":
            default_count = 5
            courses_list = courses[0:default_count]
        elif action == 'search':
            keyword = request.GET.get("keyword")

            if keyword:
                for c in courses:
                    print (keyword in c.org or keyword in c.id or keyword in c.display_name_with_default)
                    if keyword in c.org or keyword in c.id or keyword in c.display_name_with_default:
                        courses_list.append(c)
        else:
            courses_list = courses

        return courses_list
コード例 #26
0
ファイル: views.py プロジェクト: jirkamarsik/fun-apps
def courses_index(request):
    courses = [_dates_description(course) for course in get_courses(request.user)]
    form = CourseFilteringForm(request.GET or None)
    by = request.GET.get('by', COURSES_BY_PAGE)  # override default page size

    if form.is_valid():
        if form.cleaned_data['university']:
            university = University.objects.get(code=form.cleaned_data['university'])
            children = [child.code for child in university.children.all()]
            courses = [c for c in courses if c.org == form.cleaned_data['university'] or c.org in children]
        if form.cleaned_data['state']:
            now = timezone.make_aware(datetime.datetime.utcnow(), timezone.get_current_timezone())
            if form.cleaned_data['state'] == 'future':
                courses = [c for c in courses if c.start and c.start > now]
            elif form.cleaned_data['state'] == 'current':
                courses = [c for c in courses if c.start and c.start < now and c.end and c.end > now]
            elif form.cleaned_data['state'] == 'past':
                courses = [c for c in courses if c.end and c.end < now]
    elif form.errors:
        return redirect(course_index)
    courses = _sort_courses(courses)

    # paginate courses
    paginator = Paginator(courses, by, orphans=3)
    page = request.GET.get('page')

    try:
        courses = paginator.page(page)
    except PageNotAnInteger:
        courses = paginator.page(1)
    except EmptyPage:
        courses = paginator.page(paginator.num_pages)

    return render(request, 'courses/index.html', {
        'form': form,
        'courses': courses,
        'current_language': translation.get_language(),
    })
コード例 #27
0
ファイル: views.py プロジェクト: nicky-ji/edx-nicky
def course_kinds_about(request, course_kind):
    """this is to show the kinds of course page"""
    #print course_kind
    courses = get_courses(request.user, request.META.get('HTTP_HOST'))
    plist = get_primary_course(courses, course_kind)
    mlist = get_Intermediate_course(courses, course_kind)
    slist = get_senior_course(courses, course_kind)

    plen = len(plist)
    mlen = len(mlist)
    slen = len(slist)

    content = {
        'course_kind': course_kind,
        'slist': slist,
        'plist': plist,
        'mlist': mlist,
        'plen': plen,
        'mlen': mlen,
        'slen': slen,

    }
    return render_to_response('courseware/course_kinds.html', content)
コード例 #28
0
def index_list(request):
    state_temp = []
    district_temp = []
    district_name = {}
    district_list = []
    
    courses = get_courses(request.user, request.META.get('HTTP_HOST'))
    courses = sort_by_custom(courses)
    
    for course in courses:
        if request.user.is_superuser is False:
            if request.user.profile.district.state.name in course.display_state:
                state_temp.append(request.user.profile.district.state.name)

            if request.user.profile.district.code in course.display_district:
                district = District.objects.filter(code=request.user.profile.district.code)[0]
                district_temp.append(request.user.profile.district.code)
                district_name[request.user.profile.district.code] = district.name
        else:
            if len(course.display_state) > 0 and is_all(course, 'state') is False:
                state_temp.extend(course.display_state)

            if len(course.display_district) > 0 and is_all(course, 'district') is False:
                districts = District.objects.filter(code__in=course.display_district)
                district_temp.extend(course.display_district)
                for district in districts:
                    district_name[district.code] = district.name

        state_list = sorted(set(state_temp), key=lambda x: x[0])
        district_temp = sorted(set(district_temp), key=lambda x: x[0])
        for dl in district_temp:
            district_list.append({'id': dl, 'name': district_name[dl]})
    
    return render_to_response('access_resource_library_list.html', {
                                                          "states": state_list,
                                                          "districts": district_list})
コード例 #29
0
def all_courses(request, extra_context={}, user=AnonymousUser()):
    """
    Render the edX main page.

    extra_context is used to allow immediate display of certain modal windows, eg signup,
    as used by external_auth.
    """

    # The course selection work is done in courseware.courses.
    domain = settings.FEATURES.get('FORCE_UNIVERSITY_DOMAIN')  # normally False
    # do explicit check, because domain=None is valid
    if domain is False:
        domain = request.META.get('HTTP_HOST')

    # Hardcoded `AnonymousUser()` to hide unpublished courses always
    courses = get_courses(AnonymousUser(), domain=domain)
    courses = sort_by_announcement(courses)

    courses = edraak_courses_logic(courses)

    context = {'courses': courses}

    context.update(extra_context)
    return render_to_response('all_courses.html', context)
コード例 #30
0
ファイル: views.py プロジェクト: regisb/fun-apps
 def items(self, request):
     return courses.utils.sort_courses(get_courses(None))[:16]