Example #1
0
def catch_license_versions_from_request(request):
    """
    If we're a view that tries to figure out what alternate licenses
    might exist from the user's request, this utility helps look for
    those.
    """

    license_versions = []
    code = request.matchdict['code']
    searches = [[code]]
    if request.matchdict.has_key('jurisdiction'):
        # Look to see if there are other licenses of that code, possibly of
        # that jurisdiction.  Otherwise, we'll just look it up by code.  Also,
        # if by jurisdiction fails, by code will be the fallback.
        searches.insert(0, [code, request.matchdict['jurisdiction']])

    for search_args in searches:
        license_versions += all_possible_license_versions(*search_args)
        if code == u'by-nc-nd':
            other_search = [u'by-nd-nc'] + search_args[1:]
            license_versions += all_possible_license_versions(*other_search)
        if license_versions:
            break

    return license_versions
Example #2
0
def catch_license_versions_from_request(request):
    """
    If we're a view that tries to figure out what alternate licenses
    might exist from the user's request, this utility helps look for
    those.
    """

    license_versions = []
    code = request.matchdict['code']
    searches = [[code]]
    if request.matchdict.has_key('jurisdiction'):
        # Look to see if there are other licenses of that code, possibly of
        # that jurisdiction.  Otherwise, we'll just look it up by code.  Also,
        # if by jurisdiction fails, by code will be the fallback.
        searches.insert(0, [code, request.matchdict['jurisdiction']])

    for search_args in searches:
        license_versions += all_possible_license_versions(*search_args)
        if code == u'by-nc-nd':
            other_search = [u'by-nd-nc'] + search_args[1:]
            license_versions += all_possible_license_versions(*other_search)
        if license_versions:
            break

    return license_versions
Example #3
0
def test_all_possible_license_versions():
    """
    Make sure all_possible_license_versions works
    """
    license_uris = [
        lic.uri
        for lic in lib.all_possible_license_versions('by')]

    nose.tools.assert_equal(
        license_uris,
        ['http://creativecommons.org/licenses/by/1.0/',
         'http://creativecommons.org/licenses/by/2.0/',
         'http://creativecommons.org/licenses/by/2.5/',
         'http://creativecommons.org/licenses/by/3.0/'])

    license_uris = [
        lic.uri
        for lic in lib.all_possible_license_versions('by-sa', 'es')]

    nose.tools.assert_equal(
        license_uris,
        ['http://creativecommons.org/licenses/by-sa/2.0/es/',
         'http://creativecommons.org/licenses/by-sa/2.1/es/',
         'http://creativecommons.org/licenses/by-sa/2.5/es/',
         'http://creativecommons.org/licenses/by-sa/3.0/es/'])