예제 #1
0
def url_surt(request, slug, surt):
    # Add back the slash lost by Apache removing null path segments.
    surt = fix_http_double_slash(surt)
    # Get the project by the project slug.
    project = get_project(slug)
    # Create the SURT dictionary containing url_list and single_letter.
    surt_dict = create_surt_dict(project, surt)
    # Create the alphabetical browse dictionary.
    browse_dict = alphabetical_browse(project)
    # Add Browse by if browsing surts by letter.
    top_domain_search = re.compile(r'^http://\(([^,]+),?').search(surt, 0)
    if top_domain_search:
        top_domain = top_domain_search.group(1)
    else:
        top_domain = None
    return render_to_response(
        'nomination/url_surt.html',
        {
            'surt': surt,
            'project': project,
            'url_list': surt_dict['url_list'],
            'letter': surt_dict['letter'],
            'browse_domain': top_domain,
            'browse_dict': browse_dict,
        },
        RequestContext(request, {}),
    )
    def test_returns_browse_dict(self):
        surts = {
            'A': ('http://(org,alarm,)', 'http://(org,a'),
            'C': ('http://(org,charlie,)', 'http://(org,c'),
            '1': ('http://(org,123,)', 'http://(org,1')
        }
        project = factories.ProjectFactory()
        # Create the surts we're expecting to see represented in the returned dict.
        [factories.SURTFactory(url_project=project, value=surts[key][0]) for key in surts]
        expected = {
            'org': [(char, surts[char][1] if surts.get(char) else None) for char in alnum_list]
        }
        # Create another unrelated SURT to make sure we aren't grabbing everything.
        factories.SURTFactory()
        results = url_handler.alphabetical_browse(project)

        assert results == expected
예제 #3
0
def project_urls(request, slug):
    #get the project by the project slug
    project = get_project(slug)

    #Create the alphabetical browse dictionary
    browse_tup = sorted(tuple(alphabetical_browse(project).items()))

    #get general project statistics
    urls = URL.objects.filter(url_project__project_slug__exact=slug)
    url_count = get_project_url_count(urls)
    nominator_count = get_project_nominator_count(urls)

    return render_to_response(
        'nomination/project_urls.html',
        {
         'project': project,
         'browse_tup': browse_tup,
         'url_count': url_count,
         'nominator_count': nominator_count,
        },
        RequestContext(request, {}),
        )
 def test_project_not_found(self):
     project = 'not a real project'
     with pytest.raises(http.Http404):
         url_handler.alphabetical_browse(project)
    def test_no_valid_surts_found(self, surt, expected):
        project = factories.ProjectFactory()
        factories.SURTFactory(url_project=project, value=surt)
        results = url_handler.alphabetical_browse(project)

        assert results == expected