Commit | Line | Data |
---|---|---|
7f4ebeed | 1 | # GNU MediaGoblin -- federated, autonomous media hosting |
cf29e8a8 | 2 | # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. |
9a16e16f SS |
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 | ||
fb2fbe2c | 17 | import logging |
64712915 | 18 | import datetime |
52359e91 | 19 | |
3a8c3a38 | 20 | from mediagoblin import messages, mg_globals |
9074ee7c | 21 | from mediagoblin.db.util import DESCENDING, ObjectId |
af008743 SS |
22 | from mediagoblin.db.sql.models import (MediaEntry, Collection, CollectionItem, |
23 | User) | |
152a3bfa | 24 | from mediagoblin.tools.response import render_to_response, render_404, redirect |
ae3bc7fa | 25 | from mediagoblin.tools.translate import pass_to_ugettext as _ |
152a3bfa AW |
26 | from mediagoblin.tools.pagination import Pagination |
27 | from mediagoblin.tools.files import delete_media_files | |
9074ee7c | 28 | from mediagoblin.user_pages import forms as user_forms |
252eaf21 | 29 | from mediagoblin.user_pages.lib import send_comment_email |
f6249408 | 30 | |
50854db0 | 31 | from mediagoblin.decorators import (uses_pagination, get_user_media_entry, |
6d1e55b2 | 32 | require_active_login, user_may_delete_media, user_may_alter_collection, |
64c2a400 | 33 | get_user_collection, get_user_collection_item, active_user_from_url) |
9a16e16f | 34 | |
00c39256 | 35 | from werkzeug.contrib.atom import AtomFeed |
1301a8ad | 36 | |
9074ee7c | 37 | |
fb2fbe2c JAN |
38 | _log = logging.getLogger(__name__) |
39 | _log.setLevel(logging.DEBUG) | |
40 | ||
64712915 | 41 | |
3eb6fc4f | 42 | @uses_pagination |
1301a8ad | 43 | def user_home(request, page): |
9a16e16f | 44 | """'Homepage' of a User()""" |
af008743 SS |
45 | # TODO: decide if we only want homepages for active users, we can |
46 | # then use the @get_active_user decorator and also simplify the | |
47 | # template html. | |
48 | user = User.query.filter_by(username=request.matchdict['user']).first() | |
7acdbfd3 | 49 | if not user: |
de12b4e7 | 50 | return render_404(request) |
7a3d00ec | 51 | elif user.status != u'active': |
990d3b69 CAW |
52 | return render_to_response( |
53 | request, | |
54 | 'mediagoblin/user_pages/user.html', | |
55 | {'user': user}) | |
9a16e16f | 56 | |
2fb36dac SS |
57 | cursor = MediaEntry.query.\ |
58 | filter_by(uploader = user.id, | |
59 | state = u'processed').sort('created', DESCENDING) | |
9a16e16f | 60 | |
1301a8ad | 61 | pagination = Pagination(page, cursor) |
ca3ca51c | 62 | media_entries = pagination() |
44e3e917 | 63 | |
ae85ed0f BK |
64 | #if no data is available, return NotFound |
65 | if media_entries == None: | |
de12b4e7 | 66 | return render_404(request) |
243c3843 | 67 | |
5949be9a CAW |
68 | user_gallery_url = request.urlgen( |
69 | 'mediagoblin.user_pages.user_gallery', | |
5a4e3ff1 | 70 | user=user.username) |
5949be9a | 71 | |
9038c9f9 CAW |
72 | return render_to_response( |
73 | request, | |
c9c24934 E |
74 | 'mediagoblin/user_pages/user.html', |
75 | {'user': user, | |
5949be9a | 76 | 'user_gallery_url': user_gallery_url, |
c9c24934 E |
77 | 'media_entries': media_entries, |
78 | 'pagination': pagination}) | |
f6249408 | 79 | |
243c3843 | 80 | |
64c2a400 | 81 | @active_user_from_url |
184f2240 | 82 | @uses_pagination |
64c2a400 | 83 | def user_gallery(request, page, url_user=None): |
184f2240 | 84 | """'Gallery' of a User()""" |
64c2a400 SS |
85 | cursor = MediaEntry.query.filter_by( |
86 | uploader=url_user.id, | |
87 | state=u'processed').order_by(MediaEntry.created.desc()) | |
af008743 | 88 | |
64c2a400 | 89 | # Paginate gallery |
184f2240 | 90 | pagination = Pagination(page, cursor) |
91 | media_entries = pagination() | |
92 | ||
93 | #if no data is available, return NotFound | |
64c2a400 | 94 | # TODO: Should we really also return 404 for empty galleries? |
184f2240 | 95 | if media_entries == None: |
de12b4e7 | 96 | return render_404(request) |
243c3843 | 97 | |
4b5f5a08 | 98 | return render_to_response( |
99 | request, | |
100 | 'mediagoblin/user_pages/gallery.html', | |
64c2a400 | 101 | {'user': url_user, |
4b5f5a08 | 102 | 'media_entries': media_entries, |
103 | 'pagination': pagination}) | |
184f2240 | 104 | |
6f59a3a3 | 105 | MEDIA_COMMENTS_PER_PAGE = 50 |
434b3221 | 106 | |
243c3843 | 107 | |
01674e10 | 108 | @get_user_media_entry |
9074ee7c | 109 | @uses_pagination |
6f59a3a3 | 110 | def media_home(request, media, page, **kwargs): |
9074ee7c JW |
111 | """ |
112 | 'Homepage' of a MediaEntry() | |
113 | """ | |
af008743 | 114 | if request.matchdict.get('comment', None): |
af2fcba5 | 115 | pagination = Pagination( |
7c378f2c CAW |
116 | page, media.get_comments( |
117 | mg_globals.app_config['comments_ascending']), | |
118 | MEDIA_COMMENTS_PER_PAGE, | |
af2fcba5 JW |
119 | ObjectId(request.matchdict.get('comment'))) |
120 | else: | |
121 | pagination = Pagination( | |
7c378f2c CAW |
122 | page, media.get_comments( |
123 | mg_globals.app_config['comments_ascending']), | |
124 | MEDIA_COMMENTS_PER_PAGE) | |
9074ee7c | 125 | |
6f59a3a3 | 126 | comments = pagination() |
9074ee7c | 127 | |
111a609d | 128 | comment_form = user_forms.MediaCommentForm(request.form) |
9074ee7c | 129 | |
5f8b4ae8 | 130 | media_template_name = media.media_manager['display_template'] |
93bdab9d | 131 | |
9038c9f9 CAW |
132 | return render_to_response( |
133 | request, | |
93bdab9d | 134 | media_template_name, |
9074ee7c JW |
135 | {'media': media, |
136 | 'comments': comments, | |
137 | 'pagination': pagination, | |
3a8c3a38 JW |
138 | 'comment_form': comment_form, |
139 | 'app_config': mg_globals.app_config}) | |
9074ee7c | 140 | |
95e6da02 | 141 | |
95e12bf2 | 142 | @get_user_media_entry |
9074ee7c | 143 | @require_active_login |
95e12bf2 | 144 | def media_post_comment(request, media): |
9074ee7c JW |
145 | """ |
146 | recieves POST from a MediaEntry() comment form, saves the comment. | |
147 | """ | |
95e12bf2 CAW |
148 | assert request.method == 'POST' |
149 | ||
9074ee7c | 150 | comment = request.db.MediaComment() |
8efcd405 E |
151 | comment.media_entry = media.id |
152 | comment.author = request.user.id | |
111a609d | 153 | comment.content = unicode(request.form['comment_content']) |
9074ee7c | 154 | |
8efcd405 | 155 | if not comment.content.strip(): |
7298ffa1 AW |
156 | messages.add_message( |
157 | request, | |
158 | messages.ERROR, | |
eae7d058 | 159 | _("Oops, your comment was empty.")) |
7298ffa1 AW |
160 | else: |
161 | comment.save() | |
b5d3aec6 | 162 | |
7298ffa1 AW |
163 | messages.add_message( |
164 | request, messages.SUCCESS, | |
eae7d058 | 165 | _('Your comment has been posted!')) |
52359e91 | 166 | |
252eaf21 DM |
167 | media_uploader = media.get_uploader |
168 | #don't send email if you comment on your own post | |
169 | if (comment.author != media_uploader and | |
00722c99 | 170 | media_uploader.wants_comment_notification): |
252eaf21 DM |
171 | send_comment_email(media_uploader, comment, media, request) |
172 | ||
950124e6 | 173 | return redirect(request, location=media.url_for_self(request.urlgen)) |
00c39256 | 174 | |
95e6da02 | 175 | |
be5be115 AW |
176 | @get_user_media_entry |
177 | @require_active_login | |
178 | def media_collect(request, media): | |
f6bc0336 | 179 | """Add media to collection submission""" |
be5be115 | 180 | |
111a609d | 181 | form = user_forms.MediaCollectForm(request.form) |
f6bc0336 | 182 | # A user's own collections: |
2fb36dac SS |
183 | form.collection.query = Collection.query.filter_by( |
184 | creator = request.user.id).order_by(Collection.title) | |
f6bc0336 SS |
185 | |
186 | if request.method != 'POST' or not form.validate(): | |
187 | # No POST submission, or invalid form | |
188 | if not form.validate(): | |
189 | messages.add_message(request, messages.ERROR, | |
190 | _('Please check your entries and try again.')) | |
be5be115 | 191 | |
f6bc0336 SS |
192 | return render_to_response( |
193 | request, | |
194 | 'mediagoblin/user_pages/media_collect.html', | |
195 | {'media': media, | |
196 | 'form': form}) | |
197 | ||
198 | # If we are here, method=POST and the form is valid, submit things. | |
199 | # If the user is adding a new collection, use that: | |
200 | if request.form['collection_title']: | |
201 | # Make sure this user isn't duplicating an existing collection | |
202 | existing_collection = Collection.query.filter_by( | |
203 | creator=request.user.id, | |
204 | title=request.form['collection_title']).first() | |
205 | if existing_collection: | |
206 | messages.add_message(request, messages.ERROR, | |
207 | _('You already have a collection called "%s"!' | |
208 | % collection.title)) | |
be5be115 | 209 | return redirect(request, "mediagoblin.user_pages.media_home", |
f6bc0336 | 210 | user=request.user.username, |
be5be115 | 211 | media=media.id) |
be5be115 | 212 | |
f6bc0336 SS |
213 | collection = Collection() |
214 | collection.title = request.form['collection_title'] | |
215 | collection.description = request.form.get('collection_description') | |
216 | collection.creator = request.user.id | |
217 | collection.generate_slug() | |
218 | collection.save(validate=True) | |
be5be115 | 219 | |
f6bc0336 SS |
220 | # Otherwise, use the collection selected from the drop-down |
221 | else: | |
222 | collection = Collection.query.filter_by( | |
223 | id=request.form.get('collection')).first() | |
be5be115 | 224 | |
f6bc0336 SS |
225 | # Make sure the user actually selected a collection |
226 | if not collection: | |
227 | messages.add_message( | |
228 | request, messages.ERROR, | |
229 | _('You have to select or add a collection')) | |
230 | ||
231 | # Check whether media already exists in collection | |
232 | elif CollectionItem.query.filter_by( | |
233 | media_entry=media.id, | |
234 | collection=collection.id).first(): | |
235 | messages.add_message(request, messages.ERROR, | |
236 | _('"%s" already in collection "%s"' | |
237 | % (media.title, collection.title))) | |
238 | else: # Add item to collection | |
239 | collection_item = request.db.CollectionItem() | |
240 | collection_item.collection = collection.id | |
241 | collection_item.media_entry = media.id | |
242 | collection_item.author = request.user.id | |
243 | collection_item.note = request.form['note'] | |
244 | collection_item.save(validate=True) | |
245 | ||
246 | collection.items = collection.items + 1 | |
247 | collection.save(validate=True) | |
248 | ||
249 | media.collected = media.collected + 1 | |
250 | media.save() | |
251 | ||
252 | messages.add_message(request, messages.SUCCESS, | |
253 | _('"%s" added to collection "%s"' | |
254 | % (media.title, collection.title))) | |
255 | ||
256 | return redirect(request, "mediagoblin.user_pages.media_home", | |
257 | user=media.get_uploader.username, | |
258 | media=media.id) | |
259 | ||
260 | ||
261 | #TODO: Why does @user_may_delete_media not implicate @require_active_login? | |
502073f2 JW |
262 | @get_user_media_entry |
263 | @require_active_login | |
264 | @user_may_delete_media | |
265 | def media_confirm_delete(request, media): | |
266 | ||
111a609d | 267 | form = user_forms.ConfirmDeleteForm(request.form) |
502073f2 JW |
268 | |
269 | if request.method == 'POST' and form.validate(): | |
8daef28d | 270 | if form.confirm.data is True: |
05751758 | 271 | username = media.get_uploader.username |
502073f2 | 272 | |
a0a7f87f BS |
273 | # Delete all the associated comments |
274 | for comment in media.get_comments(): | |
275 | comment.delete() | |
276 | ||
502073f2 | 277 | # Delete all files on the public storage |
fb2fbe2c JAN |
278 | try: |
279 | delete_media_files(media) | |
280 | except OSError, error: | |
281 | _log.error('No such files from the user "{1}"' | |
282 | ' to delete: {0}'.format(str(error), username)) | |
283 | messages.add_message(request, messages.ERROR, | |
284 | _('Some of the files with this entry seem' | |
285 | ' to be missing. Deleting anyway.')) | |
502073f2 JW |
286 | |
287 | media.delete() | |
ea33f636 E |
288 | messages.add_message( |
289 | request, messages.SUCCESS, _('You deleted the media.')) | |
502073f2 JW |
290 | |
291 | return redirect(request, "mediagoblin.user_pages.user_home", | |
292 | user=username) | |
293 | else: | |
d0ba62e2 PUS |
294 | messages.add_message( |
295 | request, messages.ERROR, | |
56bfd91a | 296 | _("The media was not deleted because you didn't check that you were sure.")) |
950124e6 SS |
297 | return redirect(request, |
298 | location=media.url_for_self(request.urlgen)) | |
502073f2 | 299 | |
bec591d8 | 300 | if ((request.user.is_admin and |
5c2b8486 | 301 | request.user.id != media.uploader)): |
7a4c0126 CAW |
302 | messages.add_message( |
303 | request, messages.WARNING, | |
304 | _("You are about to delete another user's media. " | |
305 | "Proceed with caution.")) | |
306 | ||
502073f2 JW |
307 | return render_to_response( |
308 | request, | |
309 | 'mediagoblin/user_pages/media_confirm_delete.html', | |
310 | {'media': media, | |
311 | 'form': form}) | |
312 | ||
313 | ||
e2ae0f59 | 314 | @active_user_from_url |
be5be115 | 315 | @uses_pagination |
e2ae0f59 | 316 | def user_collection(request, page, url_user=None): |
be5be115 | 317 | """A User-defined Collection""" |
e2ae0f59 SS |
318 | collection = Collection.query.filter_by( |
319 | get_creator=url_user, | |
320 | slug=request.matchdict['collection']).first() | |
be5be115 | 321 | |
e2ae0f59 | 322 | cursor = collection.get_collection_items() |
be5be115 AW |
323 | |
324 | pagination = Pagination(page, cursor) | |
325 | collection_items = pagination() | |
326 | ||
e2ae0f59 SS |
327 | # if no data is available, return NotFound |
328 | # TODO: Should an empty collection really also return 404? | |
be5be115 AW |
329 | if collection_items == None: |
330 | return render_404(request) | |
331 | ||
332 | return render_to_response( | |
333 | request, | |
334 | 'mediagoblin/user_pages/collection.html', | |
e2ae0f59 | 335 | {'user': url_user, |
be5be115 AW |
336 | 'collection': collection, |
337 | 'collection_items': collection_items, | |
338 | 'pagination': pagination}) | |
339 | ||
340 | ||
341 | @get_user_collection_item | |
342 | @require_active_login | |
343 | @user_may_alter_collection | |
344 | def collection_item_confirm_remove(request, collection_item): | |
345 | ||
111a609d | 346 | form = user_forms.ConfirmCollectionItemRemoveForm(request.form) |
be5be115 AW |
347 | |
348 | if request.method == 'POST' and form.validate(): | |
349 | username = collection_item.in_collection.get_creator.username | |
350 | collection = collection_item.in_collection | |
351 | ||
352 | if form.confirm.data is True: | |
353 | entry = collection_item.get_media_entry | |
354 | entry.collected = entry.collected - 1 | |
355 | entry.save() | |
356 | ||
357 | collection_item.delete() | |
6d1e55b2 | 358 | collection.items = collection.items - 1 |
be5be115 AW |
359 | collection.save() |
360 | ||
361 | messages.add_message( | |
362 | request, messages.SUCCESS, _('You deleted the item from the collection.')) | |
363 | else: | |
364 | messages.add_message( | |
365 | request, messages.ERROR, | |
366 | _("The item was not removed because you didn't check that you were sure.")) | |
367 | ||
368 | return redirect(request, "mediagoblin.user_pages.user_collection", | |
369 | user=username, | |
370 | collection=collection.slug) | |
371 | ||
372 | if ((request.user.is_admin and | |
5c2b8486 | 373 | request.user.id != collection_item.in_collection.creator)): |
be5be115 AW |
374 | messages.add_message( |
375 | request, messages.WARNING, | |
376 | _("You are about to delete an item from another user's collection. " | |
377 | "Proceed with caution.")) | |
378 | ||
379 | return render_to_response( | |
380 | request, | |
381 | 'mediagoblin/user_pages/collection_item_confirm_remove.html', | |
382 | {'collection_item': collection_item, | |
383 | 'form': form}) | |
384 | ||
385 | ||
386 | @get_user_collection | |
387 | @require_active_login | |
388 | @user_may_alter_collection | |
389 | def collection_confirm_delete(request, collection): | |
390 | ||
111a609d | 391 | form = user_forms.ConfirmDeleteForm(request.form) |
be5be115 AW |
392 | |
393 | if request.method == 'POST' and form.validate(): | |
394 | ||
395 | username = collection.get_creator.username | |
396 | ||
397 | if form.confirm.data is True: | |
398 | collection_title = collection.title | |
399 | ||
400 | # Delete all the associated collection items | |
401 | for item in collection.get_collection_items(): | |
402 | entry = item.get_media_entry | |
403 | entry.collected = entry.collected - 1 | |
404 | entry.save() | |
405 | item.delete() | |
406 | ||
407 | collection.delete() | |
408 | messages.add_message( | |
409 | request, messages.SUCCESS, _('You deleted the collection "%s"' % collection_title)) | |
410 | ||
411 | return redirect(request, "mediagoblin.user_pages.user_home", | |
412 | user=username) | |
413 | else: | |
414 | messages.add_message( | |
415 | request, messages.ERROR, | |
416 | _("The collection was not deleted because you didn't check that you were sure.")) | |
417 | ||
418 | return redirect(request, "mediagoblin.user_pages.user_collection", | |
419 | user=username, | |
420 | collection=collection.slug) | |
421 | ||
422 | if ((request.user.is_admin and | |
5c2b8486 | 423 | request.user.id != collection.creator)): |
be5be115 AW |
424 | messages.add_message( |
425 | request, messages.WARNING, | |
426 | _("You are about to delete another user's collection. " | |
427 | "Proceed with caution.")) | |
428 | ||
429 | return render_to_response( | |
430 | request, | |
431 | 'mediagoblin/user_pages/collection_confirm_delete.html', | |
432 | {'collection': collection, | |
433 | 'form': form}) | |
434 | ||
435 | ||
a5303e47 | 436 | ATOM_DEFAULT_NR_OF_UPDATED_ITEMS = 15 |
00c39256 | 437 | |
243c3843 | 438 | |
00c39256 BK |
439 | def atom_feed(request): |
440 | """ | |
441 | generates the atom feed with the newest images | |
442 | """ | |
2fb36dac SS |
443 | user = User.query.filter_by( |
444 | username = request.matchdict['user'], | |
445 | status = u'active').first() | |
00c39256 | 446 | if not user: |
de12b4e7 | 447 | return render_404(request) |
00c39256 | 448 | |
2fb36dac SS |
449 | cursor = MediaEntry.query.filter_by( |
450 | uploader = user.id, | |
451 | state = u'processed').\ | |
452 | sort('created', DESCENDING).\ | |
453 | limit(ATOM_DEFAULT_NR_OF_UPDATED_ITEMS) | |
00c39256 | 454 | |
1df68a35 MA |
455 | """ |
456 | ATOM feed id is a tag URI (see http://en.wikipedia.org/wiki/Tag_URI) | |
457 | """ | |
5b1a7bae MA |
458 | atomlinks = [{ |
459 | 'href': request.urlgen( | |
460 | 'mediagoblin.user_pages.user_home', | |
64712915 | 461 | qualified=True, user=request.matchdict['user']), |
5b1a7bae MA |
462 | 'rel': 'alternate', |
463 | 'type': 'text/html' | |
64712915 JW |
464 | }] |
465 | ||
bb025ebd MA |
466 | if mg_globals.app_config["push_urls"]: |
467 | for push_url in mg_globals.app_config["push_urls"]: | |
468 | atomlinks.append({ | |
469 | 'rel': 'hub', | |
470 | 'href': push_url}) | |
5b1a7bae | 471 | |
1df68a35 MA |
472 | feed = AtomFeed( |
473 | "MediaGoblin: Feed for user '%s'" % request.matchdict['user'], | |
00c39256 | 474 | feed_url=request.url, |
64712915 JW |
475 | id='tag:{host},{year}:gallery.user-{user}'.format( |
476 | host=request.host, | |
477 | year=datetime.datetime.today().strftime('%Y'), | |
478 | user=request.matchdict['user']), | |
5b1a7bae MA |
479 | links=atomlinks) |
480 | ||
00c39256 BK |
481 | for entry in cursor: |
482 | feed.add(entry.get('title'), | |
1e72e075 | 483 | entry.description_html, |
64712915 | 484 | id=entry.url_for_self(request.urlgen, qualified=True), |
00c39256 | 485 | content_type='html', |
1df68a35 MA |
486 | author={ |
487 | 'name': entry.get_uploader.username, | |
488 | 'uri': request.urlgen( | |
489 | 'mediagoblin.user_pages.user_home', | |
490 | qualified=True, user=entry.get_uploader.username)}, | |
00c39256 | 491 | updated=entry.get('created'), |
1df68a35 MA |
492 | links=[{ |
493 | 'href': entry.url_for_self( | |
494 | request.urlgen, | |
be5be115 AW |
495 | qualified=True), |
496 | 'rel': 'alternate', | |
497 | 'type': 'text/html'}]) | |
498 | ||
499 | return feed.get_response() | |
500 | ||
6d1e55b2 | 501 | |
be5be115 AW |
502 | def collection_atom_feed(request): |
503 | """ | |
504 | generates the atom feed with the newest images from a collection | |
505 | """ | |
2fb36dac SS |
506 | user = User.query.filter_by( |
507 | username = request.matchdict['user'], | |
508 | status = u'active').first() | |
be5be115 AW |
509 | if not user: |
510 | return render_404(request) | |
511 | ||
af008743 SS |
512 | collection = Collection.query.filter_by( |
513 | creator=user.id, | |
514 | slug=request.matchdict['collection']).first() | |
be5be115 | 515 | |
af008743 SS |
516 | cursor = CollectionItem.query.filter_by( |
517 | collection=collection.id) \ | |
518 | .sort(CollectionItem.added.desc()) \ | |
be5be115 AW |
519 | .limit(ATOM_DEFAULT_NR_OF_UPDATED_ITEMS) |
520 | ||
521 | """ | |
522 | ATOM feed id is a tag URI (see http://en.wikipedia.org/wiki/Tag_URI) | |
523 | """ | |
524 | atomlinks = [{ | |
525 | 'href': request.urlgen( | |
526 | 'mediagoblin.user_pages.user_collection', | |
527 | qualified=True, user=request.matchdict['user'], collection=collection.slug), | |
528 | 'rel': 'alternate', | |
529 | 'type': 'text/html' | |
530 | }] | |
531 | ||
532 | if mg_globals.app_config["push_urls"]: | |
533 | for push_url in mg_globals.app_config["push_urls"]: | |
534 | atomlinks.append({ | |
535 | 'rel': 'hub', | |
536 | 'href': push_url}) | |
537 | ||
538 | feed = AtomFeed( | |
539 | "MediaGoblin: Feed for %s's collection %s" % (request.matchdict['user'], collection.title), | |
540 | feed_url=request.url, | |
541 | id='tag:{host},{year}:collection.user-{user}.title-{title}'.format( | |
542 | host=request.host, | |
543 | year=datetime.datetime.today().strftime('%Y'), | |
544 | user=request.matchdict['user'], | |
545 | title=collection.title), | |
546 | links=atomlinks) | |
547 | ||
548 | for item in cursor: | |
549 | entry = item.get_media_entry | |
550 | feed.add(entry.get('title'), | |
551 | item.note_html, | |
552 | id=entry.url_for_self(request.urlgen, qualified=True), | |
553 | content_type='html', | |
554 | author={ | |
555 | 'name': entry.get_uploader.username, | |
556 | 'uri': request.urlgen( | |
557 | 'mediagoblin.user_pages.user_home', | |
558 | qualified=True, user=entry.get_uploader.username)}, | |
559 | updated=item.get('added'), | |
560 | links=[{ | |
561 | 'href': entry.url_for_self( | |
562 | request.urlgen, | |
1df68a35 MA |
563 | qualified=True), |
564 | 'rel': 'alternate', | |
565 | 'type': 'text/html'}]) | |
00c39256 | 566 | |
9074ee7c | 567 | return feed.get_response() |
01c75c7e CAW |
568 | |
569 | ||
570 | @require_active_login | |
571 | def processing_panel(request): | |
572 | """ | |
573 | Show to the user what media is still in conversion/processing... | |
574 | and what failed, and why! | |
575 | """ | |
af008743 SS |
576 | user = User.query.filter_by(username=request.matchdict['user']).first() |
577 | # TODO: XXX: Should this be a decorator? | |
01c75c7e CAW |
578 | # |
579 | # Make sure we have permission to access this user's panel. Only | |
580 | # admins and this user herself should be able to do so. | |
dfc23dd1 | 581 | if not (user.id == request.user.id or request.user.is_admin): |
af008743 | 582 | # No? Simply redirect to this user's homepage. |
01c75c7e CAW |
583 | return redirect( |
584 | request, 'mediagoblin.user_pages.user_home', | |
af008743 | 585 | user=user.username) |
01c75c7e CAW |
586 | |
587 | # Get media entries which are in-processing | |
af008743 | 588 | processing_entries = MediaEntry.query.\ |
2fb36dac SS |
589 | filter_by(uploader = user.id, |
590 | state = u'processing').\ | |
af008743 | 591 | order_by(MediaEntry.created.desc()) |
01c75c7e CAW |
592 | |
593 | # Get media entries which have failed to process | |
af008743 | 594 | failed_entries = MediaEntry.query.\ |
2fb36dac SS |
595 | filter_by(uploader = user.id, |
596 | state = u'failed').\ | |
af008743 SS |
597 | order_by(MediaEntry.created.desc()) |
598 | ||
599 | processed_entries = MediaEntry.query.\ | |
2fb36dac SS |
600 | filter_by(uploader = user.id, |
601 | state = u'processed').\ | |
af008743 SS |
602 | order_by(MediaEntry.created.desc()).\ |
603 | limit(10) | |
64712915 | 604 | |
01c75c7e CAW |
605 | # Render to response |
606 | return render_to_response( | |
607 | request, | |
608 | 'mediagoblin/user_pages/processing_panel.html', | |
609 | {'user': user, | |
610 | 'processing_entries': processing_entries, | |
64712915 JW |
611 | 'failed_entries': failed_entries, |
612 | 'processed_entries': processed_entries}) |