Commit | Line | Data |
---|---|---|
9a16e16f SS |
1 | # GNU MediaGoblin -- federated, autonomous media hosting |
2 | # Copyright (C) 2011 Free Software Foundation, Inc | |
3 | # | |
4 | # This program is free software: you can redistribute it and/or modify | |
5 | # it under the terms of the GNU Affero General Public License as published by | |
6 | # the Free Software Foundation, either version 3 of the License, or | |
7 | # (at your option) any later version. | |
8 | # | |
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU Affero General Public License for more details. | |
13 | # | |
14 | # You should have received a copy of the GNU Affero General Public License | |
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | ||
1c63ad5d | 17 | from webob import exc |
439e37f7 | 18 | from mediagoblin.db.util import DESCENDING |
1c63ad5d | 19 | from mediagoblin.util import Pagination, render_to_response |
f6249408 | 20 | |
01674e10 | 21 | from mediagoblin.decorators import uses_pagination, get_user_media_entry |
9a16e16f | 22 | |
00c39256 | 23 | from werkzeug.contrib.atom import AtomFeed |
1301a8ad | 24 | |
3eb6fc4f | 25 | @uses_pagination |
1301a8ad | 26 | def user_home(request, page): |
9a16e16f | 27 | """'Homepage' of a User()""" |
7acdbfd3 SS |
28 | user = request.db.User.find_one({ |
29 | 'username': request.matchdict['user'], | |
30 | 'status': 'active'}) | |
31 | if not user: | |
32 | return exc.HTTPNotFound() | |
9a16e16f | 33 | |
434b3221 | 34 | cursor = request.db.MediaEntry.find( |
16509be1 | 35 | {'uploader': user['_id'], |
434b3221 | 36 | 'state': 'processed'}).sort('created', DESCENDING) |
9a16e16f | 37 | |
1301a8ad | 38 | pagination = Pagination(page, cursor) |
ca3ca51c | 39 | media_entries = pagination() |
44e3e917 | 40 | |
ae85ed0f BK |
41 | #if no data is available, return NotFound |
42 | if media_entries == None: | |
43 | return exc.HTTPNotFound() | |
44 | ||
9038c9f9 CAW |
45 | return render_to_response( |
46 | request, | |
c9c24934 E |
47 | 'mediagoblin/user_pages/user.html', |
48 | {'user': user, | |
49 | 'media_entries': media_entries, | |
50 | 'pagination': pagination}) | |
f6249408 | 51 | |
434b3221 | 52 | |
01674e10 | 53 | @get_user_media_entry |
724933b1 | 54 | def media_home(request, media): |
9a16e16f | 55 | """'Homepage' of a MediaEntry()""" |
9038c9f9 CAW |
56 | return render_to_response( |
57 | request, | |
c9c24934 E |
58 | 'mediagoblin/user_pages/media.html', |
59 | {'media': media}) | |
b5d3aec6 | 60 | |
00c39256 BK |
61 | |
62 | ATOM_DEFAULT_NR_OF_UPDATED_ITEMS = 5 | |
63 | ||
64 | def atom_feed(request): | |
65 | """ | |
66 | generates the atom feed with the newest images | |
67 | """ | |
68 | ||
69 | user = request.db.User.find_one({ | |
70 | 'username': request.matchdict['user'], | |
71 | 'status': 'active'}) | |
72 | if not user: | |
73 | return exc.HTTPNotFound() | |
74 | ||
75 | cursor = request.db.MediaEntry.find({ | |
76 | 'uploader': user['_id'], | |
77 | 'state': 'processed'}) \ | |
78 | .sort('created', DESCENDING) \ | |
79 | .limit(ATOM_DEFAULT_NR_OF_UPDATED_ITEMS) | |
80 | ||
81 | feed = AtomFeed(request.matchdict['user'], | |
82 | feed_url=request.url, | |
83 | url=request.host_url) | |
44e2da2f | 84 | |
00c39256 BK |
85 | for entry in cursor: |
86 | feed.add(entry.get('title'), | |
44e2da2f | 87 | entry.get('description_html'), |
00c39256 BK |
88 | content_type='html', |
89 | author=request.matchdict['user'], | |
90 | updated=entry.get('created'), | |
91 | url=entry.url_for_self(request.urlgen)) | |
92 | ||
93 | return feed.get_response() |