Fix consistency in license list.
[mediagoblin.git] / mediagoblin / tools / licenses.py
CommitLineData
0bfb4dc2 1# GNU MediaGoblin -- federated, autonomous media hosting
cf29e8a8 2# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
0bfb4dc2
AW
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU Affero General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU Affero General Public License for more details.
13#
14# You should have received a copy of the GNU Affero General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
8e5fae9b
SS
17from collections import namedtuple
18# Give a License attribute names: uri, name, abbreviation
19License = namedtuple("License", ["abbreviation", "name", "uri"])
5d775ebd 20
8e5fae9b
SS
21SORTED_LICENSES = [
22 License("All rights reserved", "No license specified", ""),
bc179396
D
23 License("CC BY 4.0", "Creative Commons Attribution 4.0 International",
24 "https://creativecommons.org/licenses/by/4.0/"),
25 License("CC BY-SA 4.0",
26 "Creative Commons Attribution-ShareAlike 4.0 International",
27 "https://creativecommons.org/licenses/by-sa/4.0/"),
28 License("CC BY-ND 4.0",
29 "Creative Commons Attribution-NoDerivs 4.0 International",
30 "https://creativecommons.org/licenses/by-nd/4.0/"),
31 License("CC BY-NC 4.0",
32 "Creative Commons Attribution-NonCommercial 4.0 International",
33 "https://creativecommons.org/licenses/by-nc/4.0/"),
34 License("CC BY-NC-SA 4.0",
35 "Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International",
36 "https://creativecommons.org/licenses/by-nc-sa/4.0/"),
37 License("CC BY-NC-ND 4.0",
38 "Creative Commons Attribution-NonCommercial-NoDerivs 4.0 International",
39 "https://creativecommons.org/licenses/by-nc-nd/4.0/"),
3d0c2a77 40 License("CC BY 3.0", "Creative Commons Attribution 3.0 Unported",
bc179396 41 "https://creativecommons.org/licenses/by/3.0/"),
8e5fae9b 42 License("CC BY-SA 3.0",
bc179396
D
43 "Creative Commons Attribution-ShareAlike 3.0 Unported",
44 "https://creativecommons.org/licenses/by-sa/3.0/"),
8e5fae9b
SS
45 License("CC BY-ND 3.0",
46 "Creative Commons Attribution-NoDerivs 3.0 Unported",
bc179396 47 "https://creativecommons.org/licenses/by-nd/3.0/"),
8e5fae9b 48 License("CC BY-NC 3.0",
bc179396
D
49 "Creative Commons Attribution-NonCommercial 3.0 Unported",
50 "https://creativecommons.org/licenses/by-nc/3.0/"),
8e5fae9b
SS
51 License("CC BY-NC-SA 3.0",
52 "Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported",
bc179396 53 "https://creativecommons.org/licenses/by-nc-sa/3.0/"),
8e5fae9b
SS
54 License("CC BY-NC-ND 3.0",
55 "Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported",
bc179396 56 "https://creativecommons.org/licenses/by-nc-nd/3.0/"),
8e5fae9b
SS
57 License("CC0 1.0",
58 "Creative Commons CC0 1.0 Universal",
bc179396 59 "https://creativecommons.org/publicdomain/zero/1.0/"),
8e5fae9b 60 License("Public Domain","Public Domain",
bc179396 61 "https://creativecommons.org/publicdomain/mark/1.0/"),
8e5fae9b 62 ]
5d775ebd 63
8e5fae9b
SS
64# dict {uri: License,...} to enable fast license lookup by uri. Ideally,
65# we'd want to use an OrderedDict (python 2.7+) here to avoid having the
66# same data in two structures
67SUPPORTED_LICENSES = dict(((l.uri, l) for l in SORTED_LICENSES))
0bfb4dc2 68
0bfb4dc2 69
138a18fd
SS
70def get_license_by_url(url):
71 """Look up a license by its url and return the License object"""
72 try:
73 return SUPPORTED_LICENSES[url]
74 except KeyError:
75 # in case of an unknown License, just display the url given
76 # rather than exploding in the user's face.
77 return License(url, url, url)
78
79
8e5fae9b
SS
80def licenses_as_choices():
81 """List of (uri, abbreviation) tuples for HTML choice field population
0bfb4dc2 82
8e5fae9b
SS
83 The data seems to be consumed/deleted during usage, so hand over a
84 throwaway list, rather than just a generator.
85 """
86 return [(lic.uri, lic.abbreviation) for lic in SORTED_LICENSES]