Merge remote-tracking branch 'remotes/lorochka85/bug852_use_media_slug_instead_of_id'
authorChristopher Allan Webber <cwebber@dustycloud.org>
Mon, 5 Dec 2011 05:14:08 +0000 (23:14 -0600)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Mon, 5 Dec 2011 05:14:08 +0000 (23:14 -0600)
Conflicts:
mediagoblin/decorators.py
mediagoblin/templates/mediagoblin/user_pages/media.html
mediagoblin/templates/mediagoblin/user_pages/media_confirm_delete.html

1  2 
mediagoblin/decorators.py
mediagoblin/templates/mediagoblin/user_pages/media.html
mediagoblin/templates/mediagoblin/user_pages/media_confirm_delete.html
mediagoblin/tests/test_submission.py

index 1cdce23a1ff4ddad1851b93e077f28665bb5e427,9cac1cfaa9fd1c1529e709cfde5cad389029f9fc..56dddb44b8a876b87e41ec005694394ea73ead90
@@@ -58,7 -58,7 +58,7 @@@ def user_may_delete_media(controller)
      """
      def wrapper(request, *args, **kwargs):
          uploader = request.db.MediaEntry.find_one(
-             {'_id': ObjectId(request.matchdict['media'])}).get_uploader()
 -            {'slug': request.matchdict['media'] }).uploader()
++            {'slug': request.matchdict['media']}).get_uploader()
          if not (request.user['is_admin'] or
                  request.user._id == uploader._id):
              return exc.HTTPForbidden()
index caa99eb70c91c0cfe910307deaedb564af275010,de5db81568888e0bcc0c584c7ec0c047cef493d3..c78180122de714cfbe4934621f5155830f00f862
                 src="{{ display_media }}"
                 alt="Image for {{ media.title }}" />
          {% endif %}
 -      </div>
 +      {% endblock %}
 +    </div>
  
 -      <h2 class="media_title">
 -        {{ media.title }}
 -      </h2>
 -      {% autoescape False %}
 -        <p>{{ media.description_html }}</p>
 -      {% endautoescape %}
 -      <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 -%}
 -          By <a href="{{ user_url }}">{{ username }}</a> on {{ date }}
 -        {%- endtrans %}
 -      </p>
 -      <h3></h3>
 -      {% if request.user and comments.count() %}
 -        <p><a href="#comment_form">{% trans %}Post a comment{% endtrans %}</a></p>
 -      {% 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 %}
 +    <h2 class="media_title">
 +      {{ media.title }}
 +    </h2>
 +    {% autoescape False %}
 +      <p>{{ media.description_html }}</p>
 +    {% endautoescape %}
 +    <p class="media_uploader">
 +      {% trans date=media.created.strftime("%Y-%m-%d"),
 +               user_url=request.urlgen(
 +                 'mediagoblin.user_pages.user_home',
 +                 user=media.get_uploader().username),
 +               username=media.get_uploader().username -%}
 +        By <a href="{{ user_url }}">{{ username }}</a> on {{ date }}
 +      {%- endtrans %}
 +    </p>
 +    <h3></h3>
 +    {% if request.user and comments.count() %}
 +      <p><a href="#comment_form">{% trans %}Post a comment{% endtrans %}</a></p>
 +    {% 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 %}
 -            <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.uploader().username,
 -                     media = media._id) }}#comment">
 -                {{ comment.created.strftime("%I:%M%p %Y-%m-%d") }}
 -              </a>
 -            </div>
 +          <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._id) }}#comment">
 +              {{ comment.created.strftime("%I:%M%p %Y-%m-%d") }}
 +            </a>
            </div>
 -        {% endfor %}
 +        </div>
 +      {% 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 %}
 +      {% if request.user %}
 +        <form action="{{ request.urlgen('mediagoblin.user_pages.media_post_comment', 
 +                                         user= media.get_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_form" />
 +              {{ csrf_token }}
 +          </div>
 +        </form>
 +      {% endif %}
  
 -        {{ render_pagination(request, pagination, 
 -            request.urlgen('mediagoblin.user_pages.media_home',
 -            user = media.uploader().username,
 -            media = media._id)) }}
 -      </div>
 -    {% endif %}
 +      {{ render_pagination(request, pagination, 
 +            request.urlgen('mediagoblin.user_pages.media_home',
 +            user = media.get_uploader().username,
 +            media = media._id)) }}
 +    </div>
 +  {% endif %}
  
 -    <div class="grid_5 omega">
 -      {% include "mediagoblin/utils/prev_next.html" %}
 +  <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.slug) %}
 -          <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.slug) %}
 -          <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['uploader'] == request.user._id or 
 +                               request.user['is_admin'] %}
 +      <p>
 +        {% set edit_url = request.urlgen('mediagoblin.edit.edit_media',
 +                                   user= media.get_uploader().username,
-                                    media= media._id) %}
++                                   media= media.slug) %}
 +        <a href="{{ edit_url }}">{% trans %}Edit{% endtrans %}</a>
 +      </p>
 +      <p>
 +        {% set delete_url = request.urlgen('mediagoblin.user_pages.media_confirm_delete',
 +                                   user= media.get_uploader().username,
-                                    media= media._id) %}
++                                   media= media.slug) %}
 +        <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 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 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.get_uploader().username,
 +                      media=media._id) }}">Add attachment</a>
 +      </p>
 +    {% endif %}
  
 -      {% if media.tags %}
 -        {% include "mediagoblin/utils/tags.html" %}
 -      {% endif %}
 -    </div>
 -  {% else %}
 -    <p>{% trans %}Sorry, no such media found.{% endtrans %}<p/>
 -  {% endif %}
 +    {% if media.tags %}
 +      {% include "mediagoblin/utils/tags.html" %}
 +    {% endif %}
 +  </div>
  {% endblock %}
index 058351a5a90d5f3a85451c2bd60c2b494f1f29b5,0f650ab6ecca6918ec7e01ab89a81290607cac42..e36891d6728e8b4021f4c2ea2c92b9ee40cf1c57
@@@ -22,8 -22,8 +22,8 @@@
  {% block mediagoblin_content %}
  
    <form action="{{ request.urlgen('mediagoblin.user_pages.media_confirm_delete',
 -                                user=media.uploader().username,
 +                                user=media.get_uploader().username,
-                                 media=media._id) }}"
+                                 media=media.slug) }}"
          method="POST" enctype="multipart/form-data">
      <div class="grid_8 prefix_1 suffix_1 edit_box form_box">
        <h1>
index 7ea6c4bcd7a9ae0c411dc545480f530248a211c9,dec7118b76281ebef4d63b981f19c4c88e33b9bc..a3453f2f012d2988981959ed63602106bb36a662
@@@ -171,7 -177,7 +171,7 @@@ class TestSubmission
              request.urlgen('mediagoblin.user_pages.media_confirm_delete',
                             # No work: user=media.uploader().username,
                             user=self.test_user['username'],
--                           media=media._id),
++                           media=media.slug),
              # no value means no confirm
              {})
  
              request.urlgen('mediagoblin.user_pages.media_confirm_delete',
                             # No work: user=media.uploader().username,
                             user=self.test_user['username'],
--                           media=media._id),
++                           media=media.slug),
              {'confirm': 'y'})
  
          response.follow()