Commit | Line | Data |
---|---|---|
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 |
17 | from collections import namedtuple |
18 | # Give a License attribute names: uri, name, abbreviation | |
19 | License = namedtuple("License", ["abbreviation", "name", "uri"]) | |
5d775ebd | 20 | |
8e5fae9b SS |
21 | SORTED_LICENSES = [ |
22 | License("All rights reserved", "No license specified", ""), | |
23 | License("CC BY 3.0", "Creative Commons Attribution Unported 3.0", | |
24 | "http://creativecommons.org/licenses/by/3.0/"), | |
25 | License("CC BY-SA 3.0", | |
26 | "Creative Commons Attribution-ShareAlike Unported 3.0", | |
27 | "http://creativecommons.org/licenses/by-sa/3.0/"), | |
28 | License("CC BY-ND 3.0", | |
29 | "Creative Commons Attribution-NoDerivs 3.0 Unported", | |
30 | "http://creativecommons.org/licenses/by-nd/3.0/"), | |
31 | License("CC BY-NC 3.0", | |
32 | "Creative Commons Attribution-NonCommercial Unported 3.0", | |
33 | "http://creativecommons.org/licenses/by-nc/3.0/"), | |
34 | License("CC BY-NC-SA 3.0", | |
35 | "Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported", | |
36 | "http://creativecommons.org/licenses/by-nc-sa/3.0/"), | |
37 | License("CC BY-NC-ND 3.0", | |
38 | "Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported", | |
39 | "http://creativecommons.org/licenses/by-nc-nd/3.0/"), | |
40 | License("CC0 1.0", | |
41 | "Creative Commons CC0 1.0 Universal", | |
42 | "http://creativecommons.org/publicdomain/zero/1.0/"), | |
43 | License("Public Domain","Public Domain", | |
44 | "http://creativecommons.org/publicdomain/mark/1.0/"), | |
45 | ] | |
5d775ebd | 46 | |
8e5fae9b SS |
47 | # dict {uri: License,...} to enable fast license lookup by uri. Ideally, |
48 | # we'd want to use an OrderedDict (python 2.7+) here to avoid having the | |
49 | # same data in two structures | |
50 | SUPPORTED_LICENSES = dict(((l.uri, l) for l in SORTED_LICENSES)) | |
0bfb4dc2 | 51 | |
0bfb4dc2 | 52 | |
138a18fd SS |
53 | def get_license_by_url(url): |
54 | """Look up a license by its url and return the License object""" | |
55 | try: | |
56 | return SUPPORTED_LICENSES[url] | |
57 | except KeyError: | |
58 | # in case of an unknown License, just display the url given | |
59 | # rather than exploding in the user's face. | |
60 | return License(url, url, url) | |
61 | ||
62 | ||
8e5fae9b SS |
63 | def licenses_as_choices(): |
64 | """List of (uri, abbreviation) tuples for HTML choice field population | |
0bfb4dc2 | 65 | |
8e5fae9b SS |
66 | The data seems to be consumed/deleted during usage, so hand over a |
67 | throwaway list, rather than just a generator. | |
68 | """ | |
69 | return [(lic.uri, lic.abbreviation) for lic in SORTED_LICENSES] |