diff options
-rw-r--r-- | mediagoblin/db/mixin.py | 6 | ||||
-rw-r--r-- | mediagoblin/db/mongo/migrations.py | 7 | ||||
-rw-r--r-- | mediagoblin/db/mongo/models.py | 3 | ||||
-rw-r--r-- | mediagoblin/db/sql/models.py | 7 | ||||
-rw-r--r-- | mediagoblin/edit/forms.py | 5 | ||||
-rw-r--r-- | mediagoblin/edit/views.py | 10 | ||||
-rw-r--r-- | mediagoblin/submit/forms.py | 4 | ||||
-rw-r--r-- | mediagoblin/submit/views.py | 4 | ||||
-rw-r--r-- | mediagoblin/templates/mediagoblin/user_pages/media.html | 2 | ||||
-rw-r--r-- | mediagoblin/templates/mediagoblin/utils/license.html | 26 | ||||
-rw-r--r-- | mediagoblin/tools/licenses.py | 62 |
11 files changed, 130 insertions, 6 deletions
diff --git a/mediagoblin/db/mixin.py b/mediagoblin/db/mixin.py index 5145289e..b0fecad3 100644 --- a/mediagoblin/db/mixin.py +++ b/mediagoblin/db/mixin.py @@ -28,7 +28,7 @@ real objects. """ from mediagoblin.auth import lib as auth_lib -from mediagoblin.tools import common +from mediagoblin.tools import common, licenses class UserMixin(object): @@ -90,3 +90,7 @@ class MediaEntryMixin(object): """ if self['fail_error']: return common.import_component(self['fail_error']) + + def get_license_data(self): + """Return license dict for requested license""" + return licenses.SUPPORTED_LICENSES[self.license] diff --git a/mediagoblin/db/mongo/migrations.py b/mediagoblin/db/mongo/migrations.py index cf4e94ae..f66ade2b 100644 --- a/mediagoblin/db/mongo/migrations.py +++ b/mediagoblin/db/mongo/migrations.py @@ -108,3 +108,10 @@ def media_type_image_to_multimedia_type_image(database): {'media_type': 'image'}, {'$set': {'media_type': 'mediagoblin.media_types.image'}}, multi=True) + +@RegisterMigration(8) +def mediaentry_add_license(database): + """ + Add the 'license' field for entries that don't have it. + """ + add_table_field(database, 'media_entries', 'license', '') diff --git a/mediagoblin/db/mongo/models.py b/mediagoblin/db/mongo/models.py index 906d2849..56ed7dcf 100644 --- a/mediagoblin/db/mongo/models.py +++ b/mediagoblin/db/mongo/models.py @@ -151,6 +151,8 @@ class MediaEntry(Document, MediaEntryMixin): "unprocessed": uploaded but needs to go through processing for display "processed": processed and able to be displayed + - license: URI for media's license. + - queued_media_file: storage interface style filepath describing a file queued for processing. This is stored in the mg_globals.queue_store storage system. @@ -183,6 +185,7 @@ class MediaEntry(Document, MediaEntryMixin): 'plugin_data': dict, # plugins can dump stuff here. 'tags': [dict], 'state': unicode, + 'license': unicode, # For now let's assume there can only be one main file queued # at a time diff --git a/mediagoblin/db/sql/models.py b/mediagoblin/db/sql/models.py index aa63e34a..53ac3d3f 100644 --- a/mediagoblin/db/sql/models.py +++ b/mediagoblin/db/sql/models.py @@ -77,10 +77,11 @@ class MediaEntry(Base, MediaEntryMixin): title = Column(Unicode, nullable=False) slug = Column(Unicode, nullable=False) created = Column(DateTime, nullable=False, default=datetime.datetime.now) - description = Column(UnicodeText) # ?? - description_html = Column(UnicodeText) # ?? + description = Column(UnicodeText) # ?? + description_html = Column(UnicodeText) # ?? media_type = Column(Unicode, nullable=False) - state = Column(Unicode, nullable=False) # or use sqlalchemy.types.Enum? + state = Column(Unicode, nullable=False) # or use sqlalchemy.types.Enum? + license = Column(Unicode, nullable=False) fail_error = Column(Unicode) fail_metadata = Column(UnicodeText) diff --git a/mediagoblin/edit/forms.py b/mediagoblin/edit/forms.py index 5c191fba..d49b9b28 100644 --- a/mediagoblin/edit/forms.py +++ b/mediagoblin/edit/forms.py @@ -18,6 +18,7 @@ import wtforms from mediagoblin.tools.text import tag_length_validator, TOO_LONG_TAG_WARNING from mediagoblin.tools.translate import fake_ugettext_passthrough as _ +from mediagoblin.tools.licenses import licenses_as_choices class EditForm(wtforms.Form): title = wtforms.TextField( @@ -39,7 +40,9 @@ class EditForm(wtforms.Form): description=_( "The title part of this media's address. " "You usually don't need to change this.")) - + license = wtforms.SelectField( + _('License'), + choices=licenses_as_choices()) class EditProfileForm(wtforms.Form): bio = wtforms.TextAreaField( diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index ec748028..cffb8a3c 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -35,6 +35,8 @@ from mediagoblin.tools.translate import pass_to_ugettext as _ from mediagoblin.tools.text import ( clean_html, convert_to_tag_list_of_dicts, media_tags_as_string, cleaned_markdown_conversion) +from mediagoblin.tools.licenses import SUPPORTED_LICENSES + @get_user_media_entry @require_active_login @@ -46,7 +48,8 @@ def edit_media(request, media): title=media.title, slug=media.slug, description=media.description, - tags=media_tags_as_string(media.tags)) + tags=media_tags_as_string(media.tags), + license=media.license) form = forms.EditForm( request.POST, @@ -72,7 +75,12 @@ def edit_media(request, media): media.description_html = cleaned_markdown_conversion( media.description) + media.license = ( + unicode(request.POST.get('license')) + or '') + media.slug = unicode(request.POST['slug']) + media.save() return exc.HTTPFound( diff --git a/mediagoblin/submit/forms.py b/mediagoblin/submit/forms.py index 7ef3638f..4ff52609 100644 --- a/mediagoblin/submit/forms.py +++ b/mediagoblin/submit/forms.py @@ -19,6 +19,7 @@ import wtforms from mediagoblin.tools.text import tag_length_validator from mediagoblin.tools.translate import fake_ugettext_passthrough as _ +from mediagoblin.tools.licenses import licenses_as_choices class SubmitStartForm(wtforms.Form): @@ -36,3 +37,6 @@ class SubmitStartForm(wtforms.Form): [tag_length_validator], description=_( "Separate tags by commas.")) + license = wtforms.SelectField( + _('License'), + choices=licenses_as_choices()) diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 33868785..8911bf82 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -69,6 +69,10 @@ def submit_start(request): entry.description_html = cleaned_markdown_conversion( entry.description) + entry.license = ( + unicode(request.POST.get('license')) + or '') + entry.uploader = request.user._id # Process the user's folksonomy "tags" diff --git a/mediagoblin/templates/mediagoblin/user_pages/media.html b/mediagoblin/templates/mediagoblin/user_pages/media.html index 865a94ab..cbe26cbf 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/media.html +++ b/mediagoblin/templates/mediagoblin/user_pages/media.html @@ -170,5 +170,7 @@ {% if media.tags %} {% include "mediagoblin/utils/tags.html" %} {% endif %} + + {% include "mediagoblin/utils/license.html" %} </div> {% endblock %} diff --git a/mediagoblin/templates/mediagoblin/utils/license.html b/mediagoblin/templates/mediagoblin/utils/license.html new file mode 100644 index 00000000..056c356e --- /dev/null +++ b/mediagoblin/templates/mediagoblin/utils/license.html @@ -0,0 +1,26 @@ +{# +# GNU MediaGoblin -- federated, autonomous media hosting +# Copyright (C) 2011 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/>. +#} + +{% block license_content -%} + {% trans %}License:{% endtrans %} + {% if media.license %} + <a href="{{ media.license }}">{{ media.get_license_data().abbreviation }}</a> + {% else %} + {% trans %}All rights reserved{% endtrans %} + {% endif %} +{% endblock %} diff --git a/mediagoblin/tools/licenses.py b/mediagoblin/tools/licenses.py new file mode 100644 index 00000000..cb137fa8 --- /dev/null +++ b/mediagoblin/tools/licenses.py @@ -0,0 +1,62 @@ +# GNU MediaGoblin -- federated, autonomous media hosting +# Copyright (C) 2011 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/>. + +SUPPORTED_LICENSES = { + "": { + "name": "No license specified", + "abbreviation": "All rights reserved" + }, + "http://creativecommons.org/licenses/by/3.0/": { + "name": "Creative Commons Attribution Unported 3.0", + "abbreviation": "CC BY 3.0" + }, + "http://creativecommons.org/licenses/by-sa/3.0": { + "name": "Creative Commons Attribution-ShareAlike Unported 3.0", + "abbreviation": "CC BY-SA 3.0" + }, + "http://creativecommons.org/licenses/by-nd/3.0": { + "name": "Creative Commons Attribution-NoDerivs 3.0 Unported", + "abbreviation": "CC BY-ND 3.0" + }, + "http://creativecommons.org/licenses/by-nc/3.0": { + "name": "Creative Commons Attribution-NonCommercial Unported 3.0", + "abbreviation": "CC BY-NC 3.0" + }, + "http://creativecommons.org/licenses/by-nc-sa/3.0": { + "name": "Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported", + "abbreviation": "CC BY-NC-SA 3.0" + }, + "http://creativecommons.org/licenses/by-nc-nd/3.0": { + "name": "Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported", + "abbreviation": "CC BY-NC-ND 3.0" + }, + "http://creativecommons.org/publicdomain/zero/1.0/": { + "name": "Creative Commons CC0 1.0 Universal", + "abbreviation": "CC0 1.0" + }, + "http://creativecommons.org/publicdomain/mark/1.0/": { + "name": "Public Domain", + "abbreviation": "Public Domain" + }, +} + +def licenses_as_choices(): + license_list = [] + + for uri, data in SUPPORTED_LICENSES.items(): + license_list.append((uri, data["abbreviation"])) + + return license_list |