Exemplo n.º 1
0
def _filter_and_return(request, context, projects, max_count):
    tag_string = request.GET.get('filter_tags')
    filter_tags = []
    if tag_string:
        filter_tags = tag_string.split('|')
    context['filter_tags'] = filter_tags
    
    if filter_tags:
        projects = get_courses_by_tags(filter_tags, projects)

    language = request.session.get('search_language', 'all')
    projects = get_courses_by_language(language, projects)

    context['popular_tags'] = get_tags_for_courses(projects, filter_tags)
    context['projects'] = projects
    context.update(get_pagination_context(request, projects, max_count))
    if request.is_ajax():
        projects_html = render_to_string('learn/_learn_projects.html',
            context, context_instance=RequestContext(request))
        projects_pagination = render_to_string('learn/_learn_pagination.html',
            context, context_instance=RequestContext(request))
        learn_header = render_to_string('learn/_learn_header.html',
            context, context_instance=RequestContext(request))
        learn_filters = render_to_string('learn/_learn_filters.html',
            context, context_instance=RequestContext(request))
        data = {
            'projects_html': projects_html,
            'projects_pagination': projects_pagination,
            'learn_header': learn_header,
            'learn_filters': learn_filters,
        }
        json = simplejson.dumps(data)
        return http.HttpResponse(json, mimetype="application/json")
    return render_to_response('learn/learn.html', context,
        context_instance=RequestContext(request))
Exemplo n.º 2
0
def _filter_and_return(request, context, projects, max_count):
    tag_string = request.GET.get('filter_tags')
    filter_tags = []
    if tag_string:
        filter_tags = tag_string.split('|')
    context['filter_tags'] = filter_tags

    if filter_tags:
        projects = get_courses_by_tags(filter_tags, projects)

    language = request.session.get('search_language', 'all')
    projects = get_courses_by_language(language, projects)

    context['popular_tags'] = get_tags_for_courses(projects, filter_tags)
    context['projects'] = projects
    context.update(get_pagination_context(request, projects, max_count))
    if request.is_ajax():
        projects_html = render_to_string(
            'learn/_learn_projects.html',
            context,
            context_instance=RequestContext(request))
        projects_pagination = render_to_string(
            'learn/_learn_pagination.html',
            context,
            context_instance=RequestContext(request))
        learn_header = render_to_string(
            'learn/_learn_header.html',
            context,
            context_instance=RequestContext(request))
        learn_filters = render_to_string(
            'learn/_learn_filters.html',
            context,
            context_instance=RequestContext(request))
        data = {
            'projects_html': projects_html,
            'projects_pagination': projects_pagination,
            'learn_header': learn_header,
            'learn_filters': learn_filters,
        }
        json = simplejson.dumps(data)
        return http.HttpResponse(json, mimetype="application/json")
    return render_to_response('learn/learn.html',
                              context,
                              context_instance=RequestContext(request))
Exemplo n.º 3
0
    def test_course_language(self):
        """ test that course languages are handled correctly """

        add_course_listing(**self.test_course)

        es_course = {
            "course_url": "http://p2pu.org/courses/2/", 
            "title": "Course title", 
            "description": "Short description", 
            "data_url": "", 
            "language": "es", 
            "thumbnail_url": "http://p2pu.org/media/image.png", 
            "tags": ["tag1", "tag2", "tag3"]
        }
        add_course_listing(**es_course)

        es_course['course_url'] = "http://p2pu.org/courses/3/"
        add_course_listing(**es_course)

        nl_course = {
            "course_url": "http://p2pu.org/courses/4/", 
            "title": "Course title", 
            "description": "Short description", 
            "data_url": "", 
            "language": "nl", 
            "thumbnail_url": "http://p2pu.org/media/image.png", 
            "tags": ["tag1", "tag2", "tag3"]
        }
        add_course_listing(**nl_course)

        course_list = get_listed_courses()
        self.assertTrue(len(course_list) == 4)
        
        languages = get_active_languages()
        self.assertTrue(len(languages) == 3)

        spanish_courses = get_courses_by_language("es")
        self.assertTrue(len(spanish_courses) == 2)
Exemplo n.º 4
0
    def test_course_language(self):
        """ test that course languages are handled correctly """

        add_course_listing(**self.test_course)

        es_course = {
            "course_url": "http://p2pu.org/courses/2/",
            "title": "Course title",
            "description": "Short description",
            "data_url": "",
            "language": "es",
            "thumbnail_url": "http://p2pu.org/media/image.png",
            "tags": ["tag1", "tag2", "tag3"]
        }
        add_course_listing(**es_course)

        es_course['course_url'] = "http://p2pu.org/courses/3/"
        add_course_listing(**es_course)

        nl_course = {
            "course_url": "http://p2pu.org/courses/4/",
            "title": "Course title",
            "description": "Short description",
            "data_url": "",
            "language": "nl",
            "thumbnail_url": "http://p2pu.org/media/image.png",
            "tags": ["tag1", "tag2", "tag3"]
        }
        add_course_listing(**nl_course)

        course_list = get_listed_courses()
        self.assertTrue(len(course_list) == 4)

        languages = get_active_languages()
        self.assertTrue(len(languages) == 3)

        spanish_courses = get_courses_by_language("es")
        self.assertTrue(len(spanish_courses) == 2)