license.html 2.15 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
<%page args="license, button=False, button_size='88x31'"/>
## keep this synchronized with the contents of cms/templates/js/license-selector.underscore
<%!
from django.utils.translation import ugettext as _

def parse_license(lic):
    """
    Returns a two-tuple: license type, and options.
    """
    if not lic:
        return None, {}
    if ":" not in lic:
        # no options, so the entire thing is the license type
        return lic, {}

    ltype, option_str = lic.split(":", 1)
    options = {}
    for part in option_str.split():
        if "=" in part:
            key, value = part.split("=", 1)
            options[key] = value
        else:
            options[part] = True
    return ltype, options
%>
<% license_type, license_options = parse_license(license) %>
% if license_type == "all-rights-reserved":
    © <span class="license-text">${_("All Rights Reserved")}</span>
% elif license_type == "creative-commons":
    <%
    possible = ["by", "nc", "nd", "sa"]
32 33 34 35
    names = {
       "by": _("Attribution"), "nc": _("Noncommercial"),
       "nd": _("No Derivatives"), "sa": _("Share Alike")
    }
36 37 38 39 40 41 42
    enabled = [opt for opt in possible
               if license_options.get(opt) or license_options.get(opt.upper())]
    version = license_options.get("ver", "4.0")
    if len(enabled) == 0:
        enabled = ["zero"]
        version = license_options.get("ver", "1.0")
    %>
43
    <a rel="license" href="https://creativecommons.org/licenses/${'-'.join(enabled)}/${version}/" target="_blank">
44 45 46 47 48 49
    % if button:
        <img src="https://licensebuttons.net/l/${'-'.join(enabled)}/${version}/${button_size}.png"
             alt="${license}"
             />
        </a>
    % else:
50 51
        ## <span> must come before <i> icon or else spacing gets messed up
        <span class="sr">${_("Creative Commons licensed content, with terms as follow:")}&nbsp;</span><i aria-hidden="true" class="icon-cc"></i>
52
        % for option in enabled:
53
            <span class="sr">${names[option]}&nbsp;</span><i aria-hidden="true" class="icon-cc-${option}"></i>
54 55 56 57 58 59 60
        % endfor
        <span class="license-text">${_("Some Rights Reserved")}</span>
    % endif
    </a>
% else:
    ${license}
% endif