licenses.py 3.0 KB

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