1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011 Free Software Foundation, Inc
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.
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.
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/>.
18 from mediagoblin
.db
.util
import DESCENDING
19 from mediagoblin
.util
import Pagination
, render_to_response
21 from mediagoblin
.decorators
import uses_pagination
, get_user_media_entry
23 from werkzeug
.contrib
.atom
import AtomFeed
26 def user_home(request
, page
):
27 """'Homepage' of a User()"""
28 user
= request
.db
.User
.find_one({
29 'username': request
.matchdict
['user'],
32 return exc
.HTTPNotFound()
34 cursor
= request
.db
.MediaEntry
.find(
35 {'uploader': user
['_id'],
36 'state': 'processed'}).sort('created', DESCENDING
)
38 pagination
= Pagination(page
, cursor
)
39 media_entries
= pagination()
41 #if no data is available, return NotFound
42 if media_entries
== None:
43 return exc
.HTTPNotFound()
45 return render_to_response(
47 'mediagoblin/user_pages/user.html',
49 'media_entries': media_entries
,
50 'pagination': pagination
})
53 def user_gallery(request
, page
):
54 """'Gallery' of a User()"""
55 user
= request
.db
.User
.find_one({
56 'username': request
.matchdict
['user'],
59 return exc
.HTTPNotFound()
61 cursor
= request
.db
.MediaEntry
.find(
62 {'uploader': user
['_id'],
63 'state': 'processed'}).sort('created', DESCENDING
)
65 pagination
= Pagination(page
, cursor
)
66 media_entries
= pagination()
68 #if no data is available, return NotFound
69 if media_entries
== None:
70 return exc
.HTTPNotFound()
72 return render_to_response(
74 'mediagoblin/user_pages/gallery.html',
76 'media_entries': media_entries
,
77 'pagination': pagination
})
81 def media_home(request
, media
):
82 """'Homepage' of a MediaEntry()"""
83 return render_to_response(
85 'mediagoblin/user_pages/media.html',
89 ATOM_DEFAULT_NR_OF_UPDATED_ITEMS
= 5
91 def atom_feed(request
):
93 generates the atom feed with the newest images
96 user
= request
.db
.User
.find_one({
97 'username': request
.matchdict
['user'],
100 return exc
.HTTPNotFound()
102 cursor
= request
.db
.MediaEntry
.find({
103 'uploader': user
['_id'],
104 'state': 'processed'}) \
105 .sort('created', DESCENDING
) \
106 .limit(ATOM_DEFAULT_NR_OF_UPDATED_ITEMS
)
108 feed
= AtomFeed(request
.matchdict
['user'],
109 feed_url
=request
.url
,
110 url
=request
.host_url
)
113 feed
.add(entry
.get('title'),
114 entry
.get('description_html'),
116 author
=request
.matchdict
['user'],
117 updated
=entry
.get('created'),
118 url
=entry
.url_for_self(request
.urlgen
))
120 return feed
.get_response()