Return code 403 when accessing admin pages
[mediagoblin.git] / mediagoblin / admin / views.py
1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
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
17 from mediagoblin.db.util import DESCENDING
18 from mediagoblin.decorators import require_active_login
19 from mediagoblin.tools.response import (render_to_response, render_403,
20 render_404)
21
22 @require_active_login
23 def admin_processing_panel(request):
24 '''
25 Show the global processing panel for this instance
26 '''
27 # TODO: Why not a "require_admin_login" decorator throwing a 403 exception?
28 if not request.user.is_admin:
29 return render_403(request)
30
31 processing_entries = request.db.MediaEntry.find(
32 {'state': u'processing'}).sort('created', DESCENDING)
33
34 # Get media entries which have failed to process
35 failed_entries = request.db.MediaEntry.find(
36 {'state': u'failed'}).sort('created', DESCENDING)
37
38 processed_entries = request.db.MediaEntry.find(
39 {'state': u'processed'}).sort('created', DESCENDING).limit(10)
40
41 # Render to response
42 return render_to_response(
43 request,
44 'mediagoblin/admin/panel.html',
45 {'processing_entries': processing_entries,
46 'failed_entries': failed_entries,
47 'processed_entries': processed_entries})