Merged changes with upstream
authorAaron Williamson <aaron@copiesofcopies.org>
Tue, 17 Jan 2012 05:59:21 +0000 (00:59 -0500)
committerAaron Williamson <aaron@copiesofcopies.org>
Tue, 17 Jan 2012 05:59:21 +0000 (00:59 -0500)
1  2 
mediagoblin/db/mongo/models.py
mediagoblin/edit/forms.py
mediagoblin/edit/views.py
mediagoblin/submit/forms.py
mediagoblin/submit/views.py
mediagoblin/templates/mediagoblin/user_pages/media.html

Simple merge
index 3d1d9fd4a751c57814134d34cbd6173f86260f3a,5c191fba62e7efa40b8183f8cc5b000b0290b0fd..d49b9b28578d411f464a15db5ad7b8b7d71ecfdf
@@@ -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(
index f92eabace2593483bfe81d685a437c9a7e8a0039,ec748028300c17a175ff9e6227ae7dfd7549ecc1..6f4585cf217b2a526c5153f55e93392ee61fb4f8
@@@ -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,
              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(
index be85b9a9d983d815fee7b70a1f3ef850611bfeff,7ef3638f980f1819e0285e2a02f312cbcc8f9710..0823482235de27fb3db2f6842c508ca7f2d34ee0
@@@ -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
+                       <a href="http://daringfireball.net/projects/markdown/basics">
+                       Markdown</a> 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())
index ecfa99430ededa1ab00f7652e3e8946b3c718871,dd273c7f8ca03156f6d39bf7836577a0e0e3c104..c3f5699e29afc866ee3dcf82e6b33d7603fe9c88
@@@ -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,
index efbd7e53ba733e3ba510e2195b16413894d4763d,865a94ab5e81ce61a782218983d4ad897240f25b..cbe26cbfb546553034625fe68b8a4676e98aa2ea
                 src="{{ display_media }}"
                 alt="Image for {{ media.title }}" />
          {% endif %}
-       </div>
-       <h2 class="media_title">
-         {{ media.title }}
-       </h2>
-       <p class="media_uploader">
-         {% 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 <a href="{{ user_url }}">{{ username }}</a>
-         {%- endtrans %}
-       </p>
-       {% autoescape False %}
-         <p>{{ media.description_html }}</p>
-       {% endautoescape %}
-       <br />
-       <h3>{% trans %}Comments{% endtrans %}</h3>
+       {% endblock %}
+     </div>
+     <h2 class="media_title">
+       {{ media.title }}
+     </h2>
+     {% autoescape False %}
+       <p>{{ media.description_html }}</p>
+     {% endautoescape %}       
+     <p class="media_specs">
+       {% 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) %}
+         <a class="button_action" href="{{ edit_url }}">{% trans %}Edit{% endtrans %}</a>
+         {% set delete_url = request.urlgen('mediagoblin.user_pages.media_confirm_delete',
+                                    user= media.get_uploader.username,
+                                    media= media._id) %}
+         <a class="button_action" href="{{ delete_url }}">{% trans %}Delete{% endtrans %}</a>
+       {% endif %}
+     </p>
+     {% if comments %}
+       <h3>
+         {% 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 %}
+         <div class="right_align">
+           <a
+             {% if not request.user %}
+               href="{{ request.urlgen('mediagoblin.auth.login') }}"
+             {% endif %}
+             class="button_action" id="button_addcomment" title="Add a comment">
+             {% trans %}Add one{% endtrans %}
+           </a>
+         </div>
+       </h3>
        {% if request.user %}
-         <p><a href="#comment_form">{% trans %}Post a comment{% endtrans %}</a></p>
+         <form action="{{ request.urlgen('mediagoblin.user_pages.media_post_comment', 
+                                          user= media.get_uploader.username,
+                                          media=media._id) }}" method="POST" id="form_comment">
+           <p>
+             {% trans %}You can use <a href="http://daringfireball.net/projects/markdown/basics">Markdown</a> for formatting.{% endtrans %}
+           </p>
+           {{ wtforms_util.render_divs(comment_form) }}
+           <div class="form_submit_buttons">
+             <input type="submit" value="{% trans %}Add this comment{% endtrans %}" class="button_action" />
+               {{ csrf_token }}
+           </div>
+         </form>
        {% endif %}
-       {% if comments %}
-         {% for comment in comments %}
-           {% set comment_author = comment.author() %}
-           {% if pagination.active_id == comment._id %}
-               <div class="comment_wrapper comment_active" id="comment-{{ comment['_id'] }}">
-               <a name="comment" id="comment"></a>
-             {% else %}
-               <div class="comment_wrapper" id="comment-{{ comment['_id'] }}">
-           {% endif %}
-             <div class="comment_content">
-               {% autoescape False %}
-                 {{ comment.content_html }}
-               {% endautoescape %}
-             </div>
-             <div class="comment_author">&mdash; 
-               <a href="{{ request.urlgen('mediagoblin.user_pages.user_home',
-                             user = comment_author['username']) }}">
-                 {{ comment_author['username'] }}</a>
-               {% trans %}at{% endtrans %} 
-               <a href="{{ request.urlgen('mediagoblin.user_pages.media_home.view_comment',
-                      comment = comment['_id'],
-                      user = media.uploader().username,
-                      media = media._id) }}#comment">
-                 {{ comment.created.strftime("%Y-%m-%d %I:%M%p") }}
-               </a>
-             </div>
+       {% for comment in comments %}
+         {% set comment_author = comment.get_author %}
+               {% if pagination.active_id == comment._id %}
+             <div class="comment_wrapper comment_active" id="comment-{{ comment._id }}">
+                         <a name="comment" id="comment"></a>
+           {% else %}
+             <div class="comment_wrapper" id="comment-{{ comment._id }}">
+               {% endif %}
+           <div class="comment_content">
+             {% autoescape False %}
+               {{ comment.content_html }}
+             {% endautoescape %}
+             <img src="{{ request.staticdirect('/images/icon_comment.png') }}" />
+             <a href="{{ request.urlgen('mediagoblin.user_pages.user_home',
+                             user = comment_author.username) }}">
+               {{ comment_author.username }}
+             </a>
+             {% trans %}at{% endtrans %}
+             <a href="{{ request.urlgen('mediagoblin.user_pages.media_home.view_comment',
+                    comment = comment._id,
+                    user = media.get_uploader.username,
+                    media = media.slug) }}#comment">
+               {{ comment.created.strftime("%I:%M%p %Y-%m-%d") }}
+             </a>
            </div>
+         </div>
+       {% endfor %}
+       {{ render_pagination(request, pagination,
+                  media.url_for_self(request.urlgen)) }}
+     {% endif %}
+   </div>
+   <div class="media_sidebar">
+     {% trans user_url=request.urlgen(
+                 'mediagoblin.user_pages.user_home',
+                 user=media.get_uploader.username),
+                 username=media.get_uploader.username -%}
+       <p>❖ Browsing media by <a href="{{ user_url }}">{{ username }}</a></p>
+     {%- endtrans %}  
+     {% include "mediagoblin/utils/prev_next.html" %}
+     {% if media.attachment_files|count %}
+       <h3>Attachments</h3>
+       <ul>
+         {% for attachment in media.attachment_files %}
+           <li>
+             <a href="{{ request.app.public_store.file_url(attachment.filepath) }}">
+               {{ attachment.name }}
+             </a>
+           </li>
          {% endfor %}
-         {% if request.user %}
-           <form action="{{ request.urlgen('mediagoblin.user_pages.media_post_comment', 
-                                            user= media.uploader().username,
-                                            media=media._id) }}" method="POST">
-             {{ wtforms_util.render_divs(comment_form) }}
-             <div class="form_submit_buttons">
-               <input type="submit" value="{% trans %}Post comment!{% endtrans %}" class="button" />
-                 {{ csrf_token }}
-             </div>
-           </form>
-         {% endif %}
-         {{ render_pagination(request, pagination, 
-             request.urlgen('mediagoblin.user_pages.media_home',
-             user = media.uploader().username,
-             media = media._id)) }}
-       </div>
+       </ul>
+     {% endif %}
+     {% if app_config['allow_attachments']
+           and request.user
+           and (media.uploader == request.user._id
+                or request.user.is_admin) %}
+       <p>
+         <a href="{{ request.urlgen('mediagoblin.edit.attachments',
+                       user=media.get_uploader.username,
+                       media=media._id) }}">Add attachment</a>
+       </p>
+     {% endif %}
+     {% if media.tags %}
+       {% include "mediagoblin/utils/tags.html" %}
      {% endif %}
-     <div class="grid_5 omega">
-       {% include "mediagoblin/utils/prev_next.html" %}
-       {% if media['uploader'] == request.user['_id'] or 
-                                  request.user['is_admin'] %}
-         <h3>{% trans %}Actions{% endtrans %}</h3>
-         <p>
-           {% set edit_url = request.urlgen('mediagoblin.edit.edit_media',
-                                      user= media.uploader().username,
-                                      media= media._id) %}
-           <a href="{{ edit_url }}"
-              ><img src="{{ request.staticdirect('/images/icon_edit.png') }}"
-                    class="media_icon" /></a>
-           <a href="{{ edit_url }}">{% trans %}edit{% endtrans %}</a>
-         </p>
-         <p>
-           {% set delete_url = request.urlgen('mediagoblin.user_pages.media_confirm_delete',
-                                      user= media.uploader().username,
-                                      media= media._id) %}
-           <a href="{{ delete_url }}"
-              ><img src="{{ request.staticdirect('/images/icon_delete.png') }}"
-                class="media_icon" /></a>
-           <a href="{{ delete_url }}">{% trans %}delete{% endtrans %}</a>
-         </p>
-       {% endif %}
-       {% if media.attachment_files|count %}
-         <h3>Attachments</h3>
-         <ul>
-           {% for attachment in media.attachment_files %}
-             <li>
-               <a href="{{ request.app.public_store.file_url(attachment.filepath) }}">
-                 {{ attachment.name }}
-               </a>
-             </li>
-           {% endfor %}
-         </ul>
-       {% endif %}
-       {% if app_config['allow_attachments']
-             and (media['uploader'] == request.user['_id']
-                  or request.user['is_admin']) %}
-         <p>
-           <a href="{{ request.urlgen('mediagoblin.edit.attachments',
-                         user=media.uploader().username,
-                         media=media._id) }}">Add attachment</a>
-         </p>
-       {% endif %}
-       {% if media.tags %}
-         {% include "mediagoblin/utils/tags.html" %}
-       {% endif %}
-       {% include "mediagoblin/utils/license.html" %}
-     </div>
-   {% else %}
-     <p>{% trans %}Sorry, no such media found.{% endtrans %}<p/>
-   {% endif %}
 +
++    {% include "mediagoblin/utils/license.html" %}
+   </div>
  {% endblock %}