Exemple #1
0
def test_publicdomain_partner_get_params():
    result = util.publicdomain_partner_get_params({'lang': 'en'})
    assert result == 'lang=en'

    # ignore garbage parameters
    result = util.publicdomain_partner_get_params({
        'lang': 'en',
        'floobie': 'blech'
    })
    assert result == 'lang=en'

    result = util.publicdomain_partner_get_params({
        'lang':
        'en',
        'partner':
        'http://nethack.org/',
        'exit_url':
        'http://nethack.org/return_from_cc?license_url=[license_url]&license_name=[license_name]',
        'stylesheet':
        'http://nethack.org/yendor.css',
        'extraneous_argument':
        'large mimic'
    })

    result_pieces = result.split('&')
    assert len(result_pieces) == 4

    assert 'lang=en' in result_pieces
    assert 'partner=http%3A%2F%2Fnethack.org%2F' in result_pieces
    assert 'exit_url=http%3A%2F%2Fnethack.org%2Freturn_from_cc%3Flicense_url%3D%5Blicense_url%5D%26license_name%3D%5Blicense_name%5D' in result_pieces
    assert 'stylesheet=http%3A%2F%2Fnethack.org%2Fyendor.css' in result_pieces
Exemple #2
0
def test_publicdomain_partner_get_params():
    result = util.publicdomain_partner_get_params({"lang": "en"})
    assert result == "lang=en"

    # ignore garbage parameters
    result = util.publicdomain_partner_get_params({"lang": "en", "floobie": "blech"})
    assert result == "lang=en"

    result = util.publicdomain_partner_get_params(
        {
            "lang": "en",
            "partner": "http://nethack.org/",
            "exit_url": "http://nethack.org/return_from_cc?license_url=[license_url]&license_name=[license_name]",
            "stylesheet": "http://nethack.org/yendor.css",
            "extraneous_argument": "large mimic",
        }
    )

    result_pieces = result.split("&")
    assert len(result_pieces) == 4

    assert "lang=en" in result_pieces
    assert "partner=http%3A%2F%2Fnethack.org%2F" in result_pieces
    assert (
        "exit_url=http%3A%2F%2Fnethack.org%2Freturn_from_cc%3Flicense_url%3D%5Blicense_url%5D%26license_name%3D%5Blicense_name%5D"
        in result_pieces
    )
    assert "stylesheet=http%3A%2F%2Fnethack.org%2Fyendor.css" in result_pieces
def pdmark_partner(request):
    """
    Partner page for PDM
    """
    target_lang = util.get_target_lang_from_request(request)

    request_form = request.GET or request.POST

    pdm_license = cc.license.by_code('mark')

    # Used for recommending CC0 in case that's more appropriate
    get_params = util.publicdomain_partner_get_params(request_form)
    
    context = _base_context(request, target_lang)
    context.update(
        {'request_form': request_form,
         'get_params': get_params,
         'exit_url': _generate_exit_url(
                request_form.get('exit_url', ''),
                request_form.get('referrer', ''),
                pdm_license)})

    return util.render_to_response(
        request, target_lang,
        'chooser_pages/pdmark/partner.html', context)
Exemple #4
0
def pdmark_partner(request):
    """
    Partner page for PDM
    """
    target_lang = util.get_target_lang_from_request(request)

    request_form = request.GET or request.POST

    pdm_license = cc.license.by_code('mark')

    # Used for recommending CC0 in case that's more appropriate
    get_params = util.publicdomain_partner_get_params(request_form)

    context = _base_context(request, target_lang)
    context.update({
        'request_form':
        request_form,
        'get_params':
        get_params,
        'exit_url':
        _generate_exit_url(request_form.get('exit_url', ''),
                           request_form.get('referrer', ''), pdm_license)
    })

    return util.render_to_response(request, target_lang,
                                   'chooser_pages/pdmark/partner.html',
                                   context)
Exemple #5
0
def pdmark_partner(request):
    """
    Partner page for PDM
    """
    target_lang = util.get_target_lang_from_request(request)

    request_form = request.GET or request.POST

    pdm_license = cc.license.by_code("mark")

    # Used for recommending CC0 in case that's more appropriate
    get_params = util.publicdomain_partner_get_params(request_form)

    context = _base_context(request, target_lang)
    context.update(
        {
            "request_form": request_form,
            "get_params": get_params,
            "exit_url": _generate_exit_url(
                request_form.get("exit_url", ""), request_form.get("referrer", ""), pdm_license
            ),
        }
    )

    return util.render_to_response(request, target_lang, "chooser_pages/pdmark/partner.html", context)
Exemple #6
0
def classic_chooser_view(request):
    target_lang = util.get_target_lang_from_request(request)
    context = _base_context(request, target_lang)
    gettext = context["gettext"]

    available_jurisdiction_codes = [j.code for j in get_selector_jurisdictions("standard") if j.code != ""]

    requested_jurisdiction = None
    if request.GET.has_key("jurisdiction") and request.GET["jurisdiction"] in available_jurisdiction_codes:
        requested_jurisdiction = request.GET["jurisdiction"]

    # Sort the jurisdictions for the dropdown via the translated name
    jurisdictions_names = [(juris, gettext(mappers.COUNTRY_MAP[juris])) for juris in available_jurisdiction_codes]
    jurisdictions_names = sorted(jurisdictions_names, key=lambda juris: juris[1])

    show_jurisdiction = request.GET.get("jurisdiction_choose") == "1"

    context.update(
        {
            "jurisdictions_names": jurisdictions_names,
            "show_jurisdiction": show_jurisdiction,
            "requested_jurisdiction": requested_jurisdiction,
            "referrer": request.headers.get("REFERER", ""),
            "page_style": "2cols",
        }
    )

    if request.GET.get("partner"):
        context["pd_get_params"] = util.publicdomain_partner_get_params(request.GET)

        return Response(util.render_template(request, target_lang, "chooser_pages/partner/index.html", context))
    else:
        return Response(util.render_template(request, target_lang, "chooser_pages/classic_chooser.html", context))
def test_publicdomain_partner_get_params():
    result = util.publicdomain_partner_get_params({'lang': 'en'})
    assert result == 'lang=en'

    # ignore garbage parameters
    result = util.publicdomain_partner_get_params({'lang': 'en', 'floobie': 'blech'})
    assert result == 'lang=en'

    result = util.publicdomain_partner_get_params(
        {'lang': 'en',
         'partner': 'http://nethack.org/',
         'exit_url': 'http://nethack.org/return_from_cc?license_url=[license_url]&license_name=[license_name]',
         'stylesheet': 'http://nethack.org/yendor.css',
         'extraneous_argument': 'large mimic'})

    result_pieces = result.split('&')
    assert len(result_pieces) == 4

    assert 'lang=en' in result_pieces
    assert 'partner=http%3A%2F%2Fnethack.org%2F' in result_pieces
    assert 'exit_url=http%3A%2F%2Fnethack.org%2Freturn_from_cc%3Flicense_url%3D%5Blicense_url%5D%26license_name%3D%5Blicense_name%5D' in result_pieces
    assert 'stylesheet=http%3A%2F%2Fnethack.org%2Fyendor.css' in result_pieces
def classic_chooser_view(request):
    target_lang = util.get_target_lang_from_request(request)
    context = _base_context(request, target_lang)
    gettext = context['gettext']

    available_jurisdiction_codes = [
        j.code for j in get_selector_jurisdictions('standard')
        if j.code != '']
    
    requested_jurisdiction = None
    if request.GET.has_key('jurisdiction') and \
            request.GET['jurisdiction'] in available_jurisdiction_codes:
        requested_jurisdiction = request.GET['jurisdiction']        

    # Sort the jurisdictions for the dropdown via the translated name
    jurisdictions_names = [
        (juris, gettext(mappers.COUNTRY_MAP[juris]))
        for juris in available_jurisdiction_codes]
    jurisdictions_names = sorted(
        jurisdictions_names, key=lambda juris: juris[1])

    show_jurisdiction = request.GET.get('jurisdiction_choose') == '1'

    context.update(
        {'jurisdictions_names': jurisdictions_names,
         'show_jurisdiction': show_jurisdiction,
         'requested_jurisdiction': requested_jurisdiction,
         'referrer': request.headers.get('REFERER',''),
         'page_style': '2cols'})

    if request.GET.get('partner'):
        context['pd_get_params'] = util.publicdomain_partner_get_params(
            request.GET)

        return Response(
            util.render_template(
                request, target_lang,
                'chooser_pages/partner/index.html', context))
    else:
        return Response(
            util.render_template(
                request, target_lang,
                'chooser_pages/classic_chooser.html', context))
Exemple #9
0
def classic_chooser_view(request):
    target_lang = util.get_target_lang_from_request(request)
    context = _base_context(request, target_lang)
    gettext = context['gettext']

    available_jurisdiction_codes = [
        j.code for j in get_selector_jurisdictions('standard') if j.code != ''
    ]

    requested_jurisdiction = None
    if request.GET.has_key('jurisdiction') and \
            request.GET['jurisdiction'] in available_jurisdiction_codes:
        requested_jurisdiction = request.GET['jurisdiction']

    # Sort the jurisdictions for the dropdown via the translated name
    jurisdictions_names = [(juris, gettext(mappers.COUNTRY_MAP[juris]))
                           for juris in available_jurisdiction_codes]
    jurisdictions_names = sorted(jurisdictions_names,
                                 key=lambda juris: juris[1])

    show_jurisdiction = request.GET.get('jurisdiction_choose') == '1'

    context.update({
        'jurisdictions_names': jurisdictions_names,
        'show_jurisdiction': show_jurisdiction,
        'requested_jurisdiction': requested_jurisdiction,
        'referrer': request.headers.get('REFERER', ''),
        'page_style': '2cols'
    })

    if request.GET.get('partner'):
        context['pd_get_params'] = util.publicdomain_partner_get_params(
            request.GET)

        return Response(
            util.render_template(request, target_lang,
                                 'chooser_pages/partner/index.html', context))
    else:
        return Response(
            util.render_template(request, target_lang,
                                 'chooser_pages/classic_chooser.html',
                                 context))