I just added the attribution for the clipboard image to the code.
[mediagoblin: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 werkzeug.exceptions import Forbidden
18
19 from mediagoblin.db.models import (MediaEntry, User, MediaComment, \
20                                    CommentReport, ReportBase, Privilege)
21 from mediagoblin.decorators import require_admin_login
22 from mediagoblin.tools.response import render_to_response
23
24 @require_admin_login
25 def admin_media_processing_panel(request):
26     '''
27     Show the global media processing panel for this instance
28     '''
29     processing_entries = MediaEntry.query.filter_by(state = u'processing').\
30         order_by(MediaEntry.created.desc())
31
32     # Get media entries which have failed to process
33     failed_entries = MediaEntry.query.filter_by(state = u'failed').\
34         order_by(MediaEntry.created.desc())
35
36     processed_entries = MediaEntry.query.filter_by(state = u'processed').\
37         order_by(MediaEntry.created.desc()).limit(10)
38
39     # Render to response
40     return render_to_response(
41         request,
42         'mediagoblin/admin/media_panel.html',
43         {'processing_entries': processing_entries,
44          'failed_entries': failed_entries,
45          'processed_entries': processed_entries})
46
47 @require_admin_login
48 def admin_users_panel(request):
49     '''
50     Show the global panel for monitoring users in this instance
51     '''
52     user_list = User.query
53
54     return render_to_response(
55         request,
56         'mediagoblin/admin/user_panel.html',
57         {'user_list': user_list})
58
59 @require_admin_login
60 def admin_users_detail(request):
61     '''
62     Shows details about a particular user.
63     '''
64     user = User.query.filter_by(username=request.matchdict['user']).first()
65     privileges = Privilege.query
66     active_reports = user.reports_filed_on.filter(
67         ReportBase.resolved==None).limit(5)
68     closed_reports = user.reports_filed_on.filter(
69         ReportBase.resolved!=None).all()
70
71     return render_to_response(
72         request,
73         'mediagoblin/admin/user.html',
74         {'user':user,
75          'privileges':privileges,
76          'reports':active_reports})
77
78 @require_admin_login
79 def admin_reports_panel(request):
80     '''
81     Show the global panel for monitoring reports filed against comments or 
82         media entries for this instance.
83     '''
84     report_list = ReportBase.query.filter(
85         ReportBase.resolved==None).order_by(
86         ReportBase.created.desc()).limit(10)
87     closed_report_list = ReportBase.query.filter(
88         ReportBase.resolved!=None).order_by(
89         ReportBase.created.desc()).limit(10)
90
91     # Render to response
92     return render_to_response(
93         request,
94         'mediagoblin/admin/report_panel.html',
95         {'report_list':report_list,
96          'closed_report_list':closed_report_list})
97
98 @require_admin_login
99 def admin_reports_detail(request):
100     report = ReportBase.query.get(request.matchdict['report_id'])
101     if report.discriminator == 'comment_report':
102         comment = MediaComment.query.get(report.comment_id)
103         media_entry = None
104     elif report.discriminator == 'media_report':
105         media_entry = MediaEntry.query.get(report.media_entry_id)
106         comment = None
107
108     return render_to_response(
109         request,
110         'mediagoblin/admin/report.html',
111         {'report':report,
112          'media_entry':media_entry,
113          'comment':comment})
114     
115