aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/tools/licenses.py
diff options
context:
space:
mode:
authorSebastian Spaeth <Sebastian@SSpaeth.de>2012-11-26 14:55:33 +0100
committerSebastian Spaeth <Sebastian@SSpaeth.de>2012-11-30 14:31:43 +0100
commit138a18fd6ed18b7415bc3bdcf9c0300c3d6a8c85 (patch)
treeb9ec8486b8807383a810ddd2a010d727ec79aded /mediagoblin/tools/licenses.py
parent8e5fae9b437afced1f8b55a44565c5032b8e7424 (diff)
downloadmediagoblin-138a18fd6ed18b7415bc3bdcf9c0300c3d6a8c85.tar.lz
mediagoblin-138a18fd6ed18b7415bc3bdcf9c0300c3d6a8c85.tar.xz
mediagoblin-138a18fd6ed18b7415bc3bdcf9c0300c3d6a8c85.zip
Implement licenses.get_license_by_url
Rather than exploding in the user's face (for example if we custom-configure licenses in our MG instance, and there are still media with now "unknown" licenses in the db), simply return a License object as a fallback, where all attributes are set to the URL we were handed. Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
Diffstat (limited to 'mediagoblin/tools/licenses.py')
-rw-r--r--mediagoblin/tools/licenses.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/mediagoblin/tools/licenses.py b/mediagoblin/tools/licenses.py
index cda3c1f6..a964980e 100644
--- a/mediagoblin/tools/licenses.py
+++ b/mediagoblin/tools/licenses.py
@@ -50,6 +50,16 @@ SORTED_LICENSES = [
SUPPORTED_LICENSES = dict(((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