| 1 | From 1dc710ecd3b1d94362981f86bc59c3c44e9f997b Mon Sep 17 00:00:00 2001
|
|---|
| 2 | From: Sebastian Spaeth <Sebastian@SSpaeth.de>
|
|---|
| 3 | Date: Wed, 11 May 2011 08:39:57 +0200
|
|---|
| 4 | Subject: [PATCH] Improve user homepage
|
|---|
| 5 |
|
|---|
| 6 | 1) Only consider user's with 'status': 'active'. We don't want to
|
|---|
| 7 | display unconfirmed/blocked users, right?
|
|---|
| 8 | 2) Actually query user's media in the view and display on their home
|
|---|
| 9 | page.
|
|---|
| 10 | 3) Throw an error 404 if we don't find a valid user, rather than saying,
|
|---|
| 11 | "User not found" (from within the template).
|
|---|
| 12 | 4) Pass in medias as media_entries to remain compatible with the 'root'
|
|---|
| 13 | page.
|
|---|
| 14 |
|
|---|
| 15 | Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
|
|---|
| 16 | ---
|
|---|
| 17 | .../templates/mediagoblin/user_pages/user.html | 15 +++++++++++-
|
|---|
| 18 | mediagoblin/user_pages/views.py | 25 ++++++++++++-------
|
|---|
| 19 | 2 files changed, 30 insertions(+), 10 deletions(-)
|
|---|
| 20 |
|
|---|
| 21 | diff --git a/mediagoblin/templates/mediagoblin/user_pages/user.html b/mediagoblin/templates/mediagoblin/user_pages/user.html
|
|---|
| 22 | index 4fa8443..85f05e0 100644
|
|---|
| 23 | --- a/mediagoblin/templates/mediagoblin/user_pages/user.html
|
|---|
| 24 | +++ b/mediagoblin/templates/mediagoblin/user_pages/user.html
|
|---|
| 25 | @@ -19,8 +19,21 @@
|
|---|
| 26 | {% block mediagoblin_content -%}
|
|---|
| 27 | {% if user %}
|
|---|
| 28 | <h2>User page for '{{ user.username }}'</h2>
|
|---|
| 29 | - {{ user }}
|
|---|
| 30 | +
|
|---|
| 31 | + {#- Should we outsource such a media 'gallery' view to it's own file?
|
|---|
| 32 | + It could be useful for the home page and other views too -#}
|
|---|
| 33 | + <ul>
|
|---|
| 34 | + {%- for entry in media_entries %}
|
|---|
| 35 | + <li>
|
|---|
| 36 | + <a href="{{ request.urlgen('mediagoblin.user_pages.media_home',
|
|---|
| 37 | + user= entry.uploader.username, m_id= entry._id) }}">
|
|---|
| 38 | + <img src="{{ request.app.public_store.file_url(
|
|---|
| 39 | + entry['media_files']['thumb']) }}" /></a>
|
|---|
| 40 | + </li>
|
|---|
| 41 | + {%- endfor %}
|
|---|
| 42 | + </ul>
|
|---|
| 43 | {% else %}
|
|---|
| 44 | + {# This *should* not occur as the view makes sure we pass in a user. #}
|
|---|
| 45 | <p>Sorry, no such user found.<p/>
|
|---|
| 46 | {% endif %}
|
|---|
| 47 | {% endblock %}
|
|---|
| 48 | diff --git a/mediagoblin/user_pages/views.py b/mediagoblin/user_pages/views.py
|
|---|
| 49 | index cc613c4..2c9792f 100644
|
|---|
| 50 | --- a/mediagoblin/user_pages/views.py
|
|---|
| 51 | +++ b/mediagoblin/user_pages/views.py
|
|---|
| 52 | @@ -14,17 +14,22 @@
|
|---|
| 53 | # You should have received a copy of the GNU Affero General Public License
|
|---|
| 54 | # along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 55 |
|
|---|
| 56 | -from webob import Response
|
|---|
| 57 | +from webob import Response, exc
|
|---|
| 58 | from mongokit import ObjectId
|
|---|
| 59 | import wtforms
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 | def user_home(request):
|
|---|
| 63 | """'Homepage' of a User()"""
|
|---|
| 64 | - user = request.db.User.find_one(
|
|---|
| 65 | - {'username': request.matchdict['user']})
|
|---|
| 66 | + user = request.db.User.find_one({
|
|---|
| 67 | + 'username': request.matchdict['user'],
|
|---|
| 68 | + 'status': 'active'})
|
|---|
| 69 | + if not user:
|
|---|
| 70 | + return exc.HTTPNotFound()
|
|---|
| 71 |
|
|---|
| 72 | - medias = request.db.MediaEntry.find()
|
|---|
| 73 | + medias = request.db.MediaEntry.find({
|
|---|
| 74 | + 'uploader': user,
|
|---|
| 75 | + 'state': 'processed'})
|
|---|
| 76 |
|
|---|
| 77 | template = request.template_env.get_template(
|
|---|
| 78 | 'mediagoblin/user_pages/user.html')
|
|---|
| 79 | @@ -32,16 +37,18 @@ def user_home(request):
|
|---|
| 80 | template.render(
|
|---|
| 81 | {'request': request,
|
|---|
| 82 | 'user': user,
|
|---|
| 83 | - 'medias': medias}))
|
|---|
| 84 | + 'media_entries': medias}))
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 | def media_home(request):
|
|---|
| 88 | """'Homepage' of a MediaEntry()"""
|
|---|
| 89 | - media = request.db.MediaEntry.find_one(
|
|---|
| 90 | - ObjectId(request.matchdict['m_id']))
|
|---|
| 91 | + media = request.db.MediaEntry.find_one({
|
|---|
| 92 | + '_id': ObjectId(request.matchdict['m_id']),
|
|---|
| 93 | + 'state': 'processed'})
|
|---|
| 94 |
|
|---|
| 95 | - #check that media uploader and user correspond
|
|---|
| 96 | - if media['uploader'].get('username') != request.matchdict['user']:
|
|---|
| 97 | + # Check that media uploader and user correspond.
|
|---|
| 98 | + if not media or \
|
|---|
| 99 | + media['uploader'].get('username') != request.matchdict['user']:
|
|---|
| 100 | return exc.HTTPNotFound()
|
|---|
| 101 |
|
|---|
| 102 | template = request.template_env.get_template(
|
|---|
| 103 | --
|
|---|
| 104 | 1.7.4.1
|
|---|
| 105 |
|
|---|