From 2db0ec2cc3b5269e19bf883c5adc927e6ab1b696 Mon Sep 17 00:00:00 2001
From: Sebastian Spaeth <Sebastian@SSpaeth.de>
Date: Wed, 11 May 2011 08:39:57 +0200
Subject: [PATCH] Improve user homepage
1) Only consider user's with 'status': 'active'. We don't want to
display unconfirmed/blocked users, right?
2) Actually query user's media in the view and display on their home
page.
3) Throw an error 404 if we don't find a valid user, rather than saying,
"User not found" (from within the template).
4) Pass in medias as media_entries to remain compatible with the 'root'
page.
Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
---
.../templates/mediagoblin/user_pages/user.html | 15 ++++++++++++++-
mediagoblin/user_pages/views.py | 12 +++++++-----
2 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/mediagoblin/templates/mediagoblin/user_pages/user.html b/mediagoblin/templates/mediagoblin/user_pages/user.html
index 4fa8443..85f05e0 100644
a
|
b
|
|
19 | 19 | {% block mediagoblin_content -%} |
20 | 20 | {% if user %} |
21 | 21 | <h2>User page for '{{ user.username }}'</h2> |
22 | | {{ user }} |
| 22 | |
| 23 | {#- Should we outsource such a media 'gallery' view to it's own file? |
| 24 | It could be useful for the home page and other views too -#} |
| 25 | <ul> |
| 26 | {%- for entry in media_entries %} |
| 27 | <li> |
| 28 | <a href="{{ request.urlgen('mediagoblin.user_pages.media_home', |
| 29 | user= entry.uploader.username, m_id= entry._id) }}"> |
| 30 | <img src="{{ request.app.public_store.file_url( |
| 31 | entry['media_files']['thumb']) }}" /></a> |
| 32 | </li> |
| 33 | {%- endfor %} |
| 34 | </ul> |
23 | 35 | {% else %} |
| 36 | {# This *should* not occur as the view makes sure we pass in a user. #} |
24 | 37 | <p>Sorry, no such user found.<p/> |
25 | 38 | {% endif %} |
26 | 39 | {% endblock %} |
diff --git a/mediagoblin/user_pages/views.py b/mediagoblin/user_pages/views.py
index cc613c4..6b0e03c 100644
a
|
b
|
|
14 | 14 | # You should have received a copy of the GNU Affero General Public License |
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 | | from webob import Response |
| 17 | from webob import Response, exc |
18 | 18 | from mongokit import ObjectId |
19 | 19 | import wtforms |
20 | 20 | |
… |
… |
import wtforms
|
22 | 22 | def user_home(request): |
23 | 23 | """'Homepage' of a User()""" |
24 | 24 | user = request.db.User.find_one( |
25 | | {'username': request.matchdict['user']}) |
| 25 | {'username': request.matchdict['user'], 'status': 'active'}) |
| 26 | if not user: |
| 27 | return exc.HTTPNotFound() |
26 | 28 | |
27 | | medias = request.db.MediaEntry.find() |
| 29 | medias = request.db.MediaEntry.find({'uploader': user}) |
28 | 30 | |
29 | 31 | template = request.template_env.get_template( |
30 | 32 | 'mediagoblin/user_pages/user.html') |
… |
… |
def user_home(request):
|
32 | 34 | template.render( |
33 | 35 | {'request': request, |
34 | 36 | 'user': user, |
35 | | 'medias': medias})) |
| 37 | 'media_entries': medias})) |
36 | 38 | |
37 | 39 | |
38 | 40 | def media_home(request): |
… |
… |
def media_home(request):
|
40 | 42 | media = request.db.MediaEntry.find_one( |
41 | 43 | ObjectId(request.matchdict['m_id'])) |
42 | 44 | |
43 | | #check that media uploader and user correspond |
| 45 | # Check that media uploader and user correspond. |
44 | 46 | if media['uploader'].get('username') != request.matchdict['user']: |
45 | 47 | return exc.HTTPNotFound() |
46 | 48 | |