From: Aaron Williamson Date: Tue, 17 Jan 2012 05:59:21 +0000 (-0500) Subject: Merged changes with upstream X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=99a270e95298b248a77b07203ab3921078bd7906;p=mediagoblin.git Merged changes with upstream --- 99a270e95298b248a77b07203ab3921078bd7906 diff --cc mediagoblin/edit/forms.py index 3d1d9fd4,5c191fba..d49b9b28 --- a/mediagoblin/edit/forms.py +++ b/mediagoblin/edit/forms.py @@@ -32,11 -37,9 +38,11 @@@ class EditForm(wtforms.Form) _('Slug'), [wtforms.validators.Required(message=_("The slug can't be empty"))], description=_( - "The title part of this media's URL. " + "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 --cc mediagoblin/edit/views.py index f92eabac,ec748028..6f4585cf --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@@ -43,11 -43,10 +44,11 @@@ def edit_media(request, media) return exc.HTTPForbidden() defaults = dict( - title=media['title'], - slug=media['slug'], - description=media['description'], - tags=media_tags_as_string(media['tags']), - license=media['license']) + title=media.title, + slug=media.slug, + description=media.description, + tags=media_tags_as_string(media.tags)) ++ license=media.license) form = forms.EditForm( request.POST, @@@ -70,14 -69,10 +71,15 @@@ media['tags'] = convert_to_tag_list_of_dicts( request.POST.get('tags')) - media['description_html'] = cleaned_markdown_conversion( - media['description']) + media.description_html = cleaned_markdown_conversion( + media.description) - media['license'] = ( ++ media.license = ( + unicode(request.POST.get('license')) + or '') + - media['slug'] = unicode(request.POST['slug']) + media.slug = unicode(request.POST['slug']) ++ media.save() return exc.HTTPFound( diff --cc mediagoblin/submit/forms.py index be85b9a9,7ef3638f..08234822 --- a/mediagoblin/submit/forms.py +++ b/mediagoblin/submit/forms.py @@@ -27,10 -27,12 +27,15 @@@ class SubmitStartForm(wtforms.Form) _('Title'), [wtforms.validators.Length(min=0, max=500)]) description = wtforms.TextAreaField( - _('Description of this work')) + _('Description of this work'), + description=_("""You can use + + Markdown for formatting.""")) tags = wtforms.TextField( _('Tags'), - [tag_length_validator]) + [tag_length_validator], + description=_( + "Separate tags by commas.")) + license = wtforms.SelectField( + _('License'), + choices=licenses_as_choices()) diff --cc mediagoblin/submit/views.py index ecfa9943,dd273c7f..c3f5699e --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@@ -44,88 -48,99 +48,103 @@@ def submit_start(request) and request.POST['file'].file): submit_form.file.errors.append( _(u'You must provide a file.')) - elif not security.check_filetype(request.POST['file']): - submit_form.file.errors.append( - _(u"The file doesn't seem to be an image!")) else: - filename = request.POST['file'].filename - - # create entry and save in database - entry = request.db.MediaEntry() - entry['_id'] = ObjectId() - entry['title'] = ( - unicode(request.POST['title']) - or unicode(splitext(filename)[0])) - - entry['description'] = unicode(request.POST.get('description')) - entry['description_html'] = cleaned_markdown_conversion( - entry['description']) - - entry['license'] = ( - unicode(request.POST.get('license')) - or '') - - entry['media_type'] = u'image' # heh - entry['uploader'] = request.user['_id'] - - # Process the user's folksonomy "tags" - entry['tags'] = convert_to_tag_list_of_dicts( - request.POST.get('tags')) - - # Generate a slug from the title - entry.generate_slug() - - # Now store generate the queueing related filename - queue_filepath = request.app.queue_store.get_unique_filepath( - ['media_entries', - unicode(entry['_id']), - secure_filename(filename)]) - - # queue appropriately - queue_file = request.app.queue_store.get_file( - queue_filepath, 'wb') - - with queue_file: - queue_file.write(request.POST['file'].file.read()) - - # Add queued filename to the entry - entry['queued_media_file'] = queue_filepath - - # We generate this ourselves so we know what the taks id is for - # retrieval later. - # (If we got it off the task's auto-generation, there'd be a risk of - # a race condition when we'd save after sending off the task) - task_id = unicode(uuid.uuid4()) - entry['queued_task_id'] = task_id - - # Save now so we have this data before kicking off processing - entry.save(validate=True) - - # Pass off to processing - # - # (... don't change entry after this point to avoid race - # conditions with changes to the document via processing code) try: - process_media.apply_async( - [unicode(entry['_id'])], {}, - task_id=task_id) - except BaseException as exc: - # The purpose of this section is because when running in "lazy" - # or always-eager-with-exceptions-propagated celery mode that - # the failure handling won't happen on Celery end. Since we - # expect a lot of users to run things in this way we have to - # capture stuff here. - # - # ... not completely the diaper pattern because the exception is - # re-raised :) - mark_entry_failed(entry[u'_id'], exc) - # re-raise the exception - raise + filename = request.POST['file'].filename + media_type, media_manager = get_media_type_and_manager(filename) + + # create entry and save in database + entry = request.db.MediaEntry() + entry['_id'] = ObjectId() + entry.media_type = unicode(media_type) + entry.title = ( + unicode(request.POST['title']) + or unicode(splitext(filename)[0])) + + entry.description = unicode(request.POST.get('description')) + 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" + entry['tags'] = convert_to_tag_list_of_dicts( + request.POST.get('tags')) + + # Generate a slug from the title + entry.generate_slug() - add_message(request, SUCCESS, _('Woohoo! Submitted!')) - return redirect(request, "mediagoblin.user_pages.user_home", - user = request.user['username']) + # Now store generate the queueing related filename + queue_filepath = request.app.queue_store.get_unique_filepath( + ['media_entries', + unicode(entry._id), + secure_filename(filename)]) + + # queue appropriately + queue_file = request.app.queue_store.get_file( + queue_filepath, 'wb') + + with queue_file: + queue_file.write(request.POST['file'].file.read()) + + # Add queued filename to the entry + entry.queued_media_file = queue_filepath + + # We generate this ourselves so we know what the taks id is for + # retrieval later. + + # (If we got it off the task's auto-generation, there'd be + # a risk of a race condition when we'd save after sending + # off the task) + task_id = unicode(uuid.uuid4()) + entry['queued_task_id'] = task_id + + # Save now so we have this data before kicking off processing + entry.save(validate=True) + + # Pass off to processing + # + # (... don't change entry after this point to avoid race + # conditions with changes to the document via processing code) + process_media = registry.tasks[ProcessMedia.name] + try: + process_media.apply_async( + [unicode(entry._id)], {}, + task_id=task_id) + except BaseException as exc: + # The purpose of this section is because when running in "lazy" + # or always-eager-with-exceptions-propagated celery mode that + # the failure handling won't happen on Celery end. Since we + # expect a lot of users to run things in this way we have to + # capture stuff here. + # + # ... not completely the diaper pattern because the + # exception is re-raised :) + mark_entry_failed(entry._id, exc) + # re-raise the exception + raise + + add_message(request, SUCCESS, _('Woohoo! Submitted!')) + + return redirect(request, "mediagoblin.user_pages.user_home", + user=request.user.username) + except Exception as e: + ''' + This section is intended to catch exceptions raised in + mediagobling.media_types + ''' + + if isinstance(e, InvalidFileType) or \ + isinstance(e, FileTypeNotSupported): + submit_form.file.errors.append( + e) + else: + raise return render_to_response( request, diff --cc mediagoblin/templates/mediagoblin/user_pages/media.html index efbd7e53,865a94ab..cbe26cbf --- a/mediagoblin/templates/mediagoblin/user_pages/media.html +++ b/mediagoblin/templates/mediagoblin/user_pages/media.html @@@ -42,139 -48,127 +48,129 @@@ src="{{ display_media }}" alt="Image for {{ media.title }}" /> {% endif %} - - -

- {{ media.title }} -

- -

- {% trans date=media.created.strftime("%Y-%m-%d"), - user_url=request.urlgen( - 'mediagoblin.user_pages.user_home', - user=media.uploader().username), - username=media.uploader().username -%} - Uploaded on {{ date }} by {{ username }} - {%- endtrans %} -

- - {% autoescape False %} -

{{ media.description_html }}

- {% endautoescape %} - -
-

{% trans %}Comments{% endtrans %}

- + {% endblock %} + +

+ {{ media.title }} +

+ {% autoescape False %} +

{{ media.description_html }}

+ {% endautoescape %} +

+ {% trans date=media.created.strftime("%Y-%m-%d") -%} + Added on {{ date }}. + {%- endtrans %} + {% if request.user and + (media.uploader == request.user._id or + request.user.is_admin) %} + {% set edit_url = request.urlgen('mediagoblin.edit.edit_media', + user= media.get_uploader.username, + media= media._id) %} + {% trans %}Edit{% endtrans %} + {% set delete_url = request.urlgen('mediagoblin.user_pages.media_confirm_delete', + user= media.get_uploader.username, + media= media._id) %} + {% trans %}Delete{% endtrans %} + {% endif %} +

+ {% if comments %} +

+ {% if comments.count()==1 %} + {% trans comment_count=comments.count() -%}{{ comment_count }} comment{%- endtrans %} + {% elif comments.count()>1 %} + {% trans comment_count=comments.count() -%}{{ comment_count }} comments{%- endtrans %} + {% else %} + {% trans %}No comments yet.{% endtrans %} + {% endif %} + +

{% if request.user %} -

{% trans %}Post a comment{% endtrans %}

+
+

+ {% trans %}You can use Markdown for formatting.{% endtrans %} +

+ {{ wtforms_util.render_divs(comment_form) }} +
+ + {{ csrf_token }} +
+
{% endif %} - - {% if comments %} - {% for comment in comments %} - {% set comment_author = comment.author() %} - {% if pagination.active_id == comment._id %} -
- - {% else %} -
- {% endif %} - -
- {% autoescape False %} - {{ comment.content_html }} - {% endautoescape %} -
- - + {% for comment in comments %} + {% set comment_author = comment.get_author %} + {% if pagination.active_id == comment._id %} +
+ + {% else %} +
+ {% endif %} +
+ {% autoescape False %} + {{ comment.content_html }} + {% endautoescape %} + + + {{ comment_author.username }} + + {% trans %}at{% endtrans %} + + {{ comment.created.strftime("%I:%M%p %Y-%m-%d") }} +
+
+ {% endfor %} + {{ render_pagination(request, pagination, + media.url_for_self(request.urlgen)) }} + {% endif %} +
+
+ {% trans user_url=request.urlgen( + 'mediagoblin.user_pages.user_home', + user=media.get_uploader.username), + username=media.get_uploader.username -%} +

❖ Browsing media by {{ username }}

+ {%- endtrans %} + {% include "mediagoblin/utils/prev_next.html" %} + {% if media.attachment_files|count %} +

Attachments

+
    + {% for attachment in media.attachment_files %} +
  • + + {{ attachment.name }} + +
  • {% endfor %} - - {% if request.user %} -
    - {{ wtforms_util.render_divs(comment_form) }} -
    - - {{ csrf_token }} -
    -
    - {% endif %} - - {{ render_pagination(request, pagination, - request.urlgen('mediagoblin.user_pages.media_home', - user = media.uploader().username, - media = media._id)) }} -
+ + {% endif %} + {% if app_config['allow_attachments'] + and request.user + and (media.uploader == request.user._id + or request.user.is_admin) %} +

+ Add attachment +

+ {% endif %} + {% if media.tags %} + {% include "mediagoblin/utils/tags.html" %} {% endif %} + -
- {% include "mediagoblin/utils/prev_next.html" %} - - {% if media['uploader'] == request.user['_id'] or - request.user['is_admin'] %} -

{% trans %}Actions{% endtrans %}

-

- {% set edit_url = request.urlgen('mediagoblin.edit.edit_media', - user= media.uploader().username, - media= media._id) %} - - {% trans %}edit{% endtrans %} -

-

- {% set delete_url = request.urlgen('mediagoblin.user_pages.media_confirm_delete', - user= media.uploader().username, - media= media._id) %} - - {% trans %}delete{% endtrans %} -

- {% endif %} - - {% if media.attachment_files|count %} -

Attachments

- - {% endif %} - - {% if app_config['allow_attachments'] - and (media['uploader'] == request.user['_id'] - or request.user['is_admin']) %} -

- Add attachment -

- {% endif %} - - {% if media.tags %} - {% include "mediagoblin/utils/tags.html" %} - {% endif %} - - {% include "mediagoblin/utils/license.html" %} -
- {% else %} -

{% trans %}Sorry, no such media found.{% endtrans %}

- {% endif %} ++ {% include "mediagoblin/utils/license.html" %} +

{% endblock %}