Пример #1
0
    def new_controller_func(request, *args, **kwargs):
        license = by_code(request.matchdict['code'],
                          jurisdiction=request.matchdict.get('jurisdiction'),
                          version=request.matchdict.get('version'))
        if not license:
            return HTTPNotFound()

        return controller(request, license=license, *args, **kwargs)
Пример #2
0
    def new_controller_func(request, *args, **kwargs):
        license = by_code(
            request.matchdict['code'],
            jurisdiction=request.matchdict.get('jurisdiction'),
            version=request.matchdict.get('version'))
        if not license:
            return HTTPNotFound()

        return controller(request, license=license, *args, **kwargs)
Пример #3
0
def license_deed_view(request):
    """
    The main and major deed generating view.
    """
    ##########################
    # Try and get the license.
    ##########################
    license = by_code(request.matchdict['code'],
                      jurisdiction=request.matchdict.get('jurisdiction'),
                      version=request.matchdict.get('version'))
    if not license:
        license_versions = util.catch_license_versions_from_request(request)

        if license_versions:
            # If we can't get it, but others of that code exist, give
            # a special 404.
            return license_catcher(request)
        else:
            # Otherwise, give the normal 404.
            return exc.HTTPNotFound()

    ####################
    # Everything else ;)
    ####################
    # "color" of the license; the color reflects the relative amount
    # of freedom.
    if license.license_code in ('devnations', 'sampling'):
        color = 'red'
    elif license.license_code.find('sampling') > -1 or \
             license.license_code.find('nc') > -1 or \
             license.license_code.find('nd') > -1:
        color = 'yellow'
    else:
        color = 'green'

    # Get the language this view will be displayed in.
    #  - First checks to see if the routing matchdict specifies the language
    #  - Or, next gets the jurisdictions' default language if the jurisdiction
    #    specifies one
    #  - Otherwise it's english!
    if request.matchdict.has_key('target_lang'):
        target_lang = request.matchdict.get('target_lang')
    elif license.jurisdiction.default_language:
        target_lang = locale_to_lower_upper(
            license.jurisdiction.default_language)
    else:
        target_lang = 'en'

    # True if the legalcode for this license is available in
    # multiple languages (or a single language with a language code different
    # than that of the jurisdiction).
    #
    # Stored in the RDF, we'll just check license.legalcodes() :)
    legalcodes = license.legalcodes(target_lang)
    if len(legalcodes) > 1 \
            or list(legalcodes)[0][2] is not None:
        multi_language = True
        legalcodes = sorted(legalcodes, key=lambda lc: lc[2])
    else:
        multi_language = False

    # Use the lower-dash style for all RDF-related locale stuff
    rdf_style_target_lang = locale_to_lower_lower(target_lang)

    license_title = None
    try:
        license_title = license.title(rdf_style_target_lang)
    except KeyError:
        # don't have one for that language, use default
        license_title = license.title()

    conditions = {}
    for code in license.license_code.split('-'):
        conditions[code] = 1

    # Find out all the active languages
    active_languages = get_well_translated_langs()
    negotiated_locale = negotiate_locale(target_lang)

    # If negotiating the locale says that this isn't a valid language,
    # let's fall back to something that is.
    if target_lang != negotiated_locale:
        base_url = REMOVE_DEED_URL_RE.match(request.path_info).groups()[0]
        redirect_to = base_url + 'deed.' + negotiated_locale
        return exc.HTTPFound(location=redirect_to)

    if DEED_TEMPLATE_MAPPING.has_key(license.license_code):
        main_template = DEED_TEMPLATE_MAPPING[license.license_code]
    else:
        main_template = 'licenses/standard_deed.html'

    get_this = "/choose/results-one?license_code=%s&jurisdiction=%s&version=%s&lang=%s" % (
        urllib.quote(license.license_code), license.jurisdiction.code,
        license.version, target_lang)

    context = {
        'request': request,
        'license_code': license.license_code,
        'license_code_quoted': urllib.quote(license.license_code),
        'license_title': license_title,
        'license': license,
        'multi_language': multi_language,
        'legalcodes': legalcodes,
        'color': color,
        'conditions': conditions,
        'active_languages': active_languages,
        'target_lang': target_lang,
        'jurisdiction': license.jurisdiction.code,
        'get_this': get_this,
    }
    context.update(util.rtl_context_stuff(target_lang))

    return Response(
        util.render_template(request, target_lang, main_template, context))
Пример #4
0
def license_deed_view(request):
    """
    The main and major deed generating view.
    """
    ##########################
    # Try and get the license.
    ##########################
    license = by_code(
        request.matchdict['code'],
        jurisdiction=request.matchdict.get('jurisdiction'),
        version=request.matchdict.get('version'))
    if not license:
        license_versions = util.catch_license_versions_from_request(request)

        if license_versions:
            # If we can't get it, but others of that code exist, give
            # a special 404.
            return license_catcher(request)
        else:
            # Otherwise, give the normal 404.
            return exc.HTTPNotFound()

    ####################
    # Everything else ;)
    ####################
    # "color" of the license; the color reflects the relative amount
    # of freedom.
    if license.license_code in ('devnations', 'sampling'):
       color = 'red'
    elif license.license_code.find('sampling') > -1 or \
             license.license_code.find('nc') > -1 or \
             license.license_code.find('nd') > -1:
       color = 'yellow'
    else:
       color = 'green'

    # Get the language this view will be displayed in.
    #  - First checks to see if the routing matchdict specifies the language
    #  - Or, next gets the jurisdictions' default language if the jurisdiction
    #    specifies one
    #  - Otherwise it's english!
    if request.matchdict.has_key('target_lang'):
        target_lang = request.matchdict.get('target_lang')
    elif license.jurisdiction.default_language:
        target_lang = locale_to_lower_upper(
            license.jurisdiction.default_language)
    else:
        target_lang = 'en'

    # True if the legalcode for this license is available in
    # multiple languages (or a single language with a language code different
    # than that of the jurisdiction).
    #
    # Stored in the RDF, we'll just check license.legalcodes() :)
    legalcodes = license.legalcodes(target_lang)
    if len(legalcodes) > 1 \
            or list(legalcodes)[0][2] is not None:
        multi_language = True
        legalcodes = sorted(legalcodes, key=lambda lc: lc[2])
    else:
        multi_language = False

    # Use the lower-dash style for all RDF-related locale stuff
    rdf_style_target_lang = locale_to_lower_lower(target_lang)

    license_title = None
    try:
        license_title = license.title(rdf_style_target_lang)
    except KeyError:
        # don't have one for that language, use default
        license_title = license.title()

    conditions = {}
    for code in license.license_code.split('-'):
        conditions[code] = 1

    # Find out all the active languages
    active_languages = get_well_translated_langs()
    negotiated_locale = negotiate_locale(target_lang)

    # If negotiating the locale says that this isn't a valid language,
    # let's fall back to something that is.
    if target_lang != negotiated_locale:
        base_url = REMOVE_DEED_URL_RE.match(request.path_info).groups()[0]
        redirect_to = base_url + 'deed.' + negotiated_locale
        return exc.HTTPFound(location=redirect_to)

    if DEED_TEMPLATE_MAPPING.has_key(license.license_code):
        main_template = DEED_TEMPLATE_MAPPING[license.license_code]
    else:
        main_template = 'licenses/standard_deed.html'

    get_this = "/choose/results-one?license_code=%s&jurisdiction=%s&version=%s&lang=%s" % (urllib.quote(license.license_code), license.jurisdiction.code, license.version, target_lang)

    context = {
        'request': request,
        'license_code': license.license_code,
        'license_code_quoted': urllib.quote(license.license_code),
        'license_title': license_title,
        'license': license,
        'multi_language': multi_language,
        'legalcodes': legalcodes,
        'color': color,
        'conditions': conditions,
        'active_languages': active_languages,
        'target_lang': target_lang,
        'jurisdiction':license.jurisdiction.code,
        'get_this': get_this,
        }
    context.update(util.rtl_context_stuff(target_lang))

    return Response(
        util.render_template(
            request, target_lang,
            main_template, context))