aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/tools/licenses.py
blob: 0940ac56d322943a0380704665553522ab73e507 (plain)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# GNU MediaGoblin -- federated, autonomous media hosting
# Copyright (C) 2011, 2012 MediaGoblin contributors.  See AUTHORS.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from collections import namedtuple
# Give a License attribute names: uri, name, abbreviation
License = namedtuple("License", ["abbreviation", "name", "uri"])

SORTED_LICENSES = [
    License("All rights reserved", "No license specified", ""),
    License("CC BY 4.0", "Creative Commons Attribution 4.0 International",
            "https://creativecommons.org/licenses/by/4.0/"),
    License("CC BY-SA 4.0",
            "Creative Commons Attribution-ShareAlike 4.0 International",
            "https://creativecommons.org/licenses/by-sa/4.0/"),
    License("CC BY-ND 4.0",
            "Creative Commons Attribution-NoDerivs 4.0 International",
            "https://creativecommons.org/licenses/by-nd/4.0/"),
    License("CC BY-NC 4.0",
            "Creative Commons Attribution-NonCommercial 4.0 International",
            "https://creativecommons.org/licenses/by-nc/4.0/"),
    License("CC BY-NC-SA 4.0",
            "Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International",
            "https://creativecommons.org/licenses/by-nc-sa/4.0/"),
    License("CC BY-NC-ND 4.0",
            "Creative Commons Attribution-NonCommercial-NoDerivs 4.0 International",
            "https://creativecommons.org/licenses/by-nc-nd/4.0/"),
    License("CC BY 3.0", "Creative Commons Attribution 3.0 Unported",
           "https://creativecommons.org/licenses/by/3.0/"),
    License("CC BY-SA 3.0",
           "Creative Commons Attribution-ShareAlike 3.0 Unported",
           "https://creativecommons.org/licenses/by-sa/3.0/"),
    License("CC BY-ND 3.0",
           "Creative Commons Attribution-NoDerivs 3.0 Unported",
           "https://creativecommons.org/licenses/by-nd/3.0/"),
    License("CC BY-NC 3.0",
          "Creative Commons Attribution-NonCommercial 3.0 Unported",
          "https://creativecommons.org/licenses/by-nc/3.0/"),
    License("CC BY-NC-SA 3.0",
           "Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported",
           "https://creativecommons.org/licenses/by-nc-sa/3.0/"),
    License("CC BY-NC-ND 3.0",
           "Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported",
           "https://creativecommons.org/licenses/by-nc-nd/3.0/"),
    License("CC0 1.0",
           "Creative Commons CC0 1.0 Universal",
           "https://creativecommons.org/publicdomain/zero/1.0/"),
    License("Public Domain","Public Domain",
           "https://creativecommons.org/publicdomain/mark/1.0/"),
    ]

# dict {uri: License,...} to enable fast license lookup by uri. Ideally,
# we'd want to use an OrderedDict (python 2.7+) here to avoid having the
# same data in two structures
SUPPORTED_LICENSES = {l.uri: l for l in SORTED_LICENSES}


def get_license_by_url(url):
    """Look up a license by its url and return the License object"""
    try:
        return SUPPORTED_LICENSES[url]
    except KeyError:
        # in case of an unknown License, just display the url given
        # rather than exploding in the user's face.
        return License(url, url, url)


def licenses_as_choices():
    """List of (uri, abbreviation) tuples for HTML choice field population

    The data seems to be consumed/deleted during usage, so hand over a
    throwaway list, rather than just a generator.
    """
    return [(lic.uri, lic.abbreviation) for lic in SORTED_LICENSES]