aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/admin/views.py
diff options
context:
space:
mode:
authortilly-Q <nattilypigeonfowl@gmail.com>2013-06-27 14:13:42 -0700
committertilly-Q <nattilypigeonfowl@gmail.com>2013-06-27 14:13:42 -0700
commit9b8ef022ef874304fb3d5aead612ec3b8fb23e9a (patch)
tree72ffe12bae2f975aa19c1cbe4e721bd0b22d5058 /mediagoblin/admin/views.py
parent30a9fe7c1cf128fdf413797a2b2edac2d5439bc2 (diff)
downloadmediagoblin-9b8ef022ef874304fb3d5aead612ec3b8fb23e9a.tar.lz
mediagoblin-9b8ef022ef874304fb3d5aead612ec3b8fb23e9a.tar.xz
mediagoblin-9b8ef022ef874304fb3d5aead612ec3b8fb23e9a.zip
In this commit, I have made a few changes and tightened up some of my models
code. I added in two major pieces of functionality: table foundations and a decorator to confirm whether or not a user is a member of a certain group. Table Foundations are default rows that should be present in a given table as soon as the database is initialized. For example, I am using these to populate the core__groups table with all of the necessary groups ('moderator', 'com- menter', etc). Right now, this is achieved by adding a dictionary of parameters (with the parameters as lists) to the constant FOUNDATIONS in mediagoblin.db.models. The keys to this dictionary are uninstantiated classes. The classes which require foundations also have must have a constructor so that the list of parameters can be passed appropriately like so: Model(*parameters) In order to implement these foundations, I added the method populate_table_fou- -ndations to MigrationManager in mediagoblin.db.migration_tools. The decorator, called user_in_group, accepts as a parameter a unicode string, and then decides whether to redirect to 403 or let the user access the page. The identifier is the Group.group_name string, because I believe that will allow for the most readable code. I also added in the simple decorator require_admin_login. In terms of tightening up my code, I made many minor changes to my use of white space and made a few small documentation additions. I removed a vestigial class (ReportForm) from mediagoblin.user_pages.forms. I moved all of my migrations in- to one registered Migration. Setting up Foundations ============================== --\ mediagoblin/db/migration_tools.py --| created: MigrationManager.populate_table_foundations --| modified: MigrationManager.init_or_migrate to run | self.populate_table_foundations on init --\ mediagoblin/db/models.py --| created: FOUNDATIONS ----| created: group_foundations Working With Permissions ============================== --\ mediagoblin/decorators.py --| created: user_in_group --| created: require_admin_login --\ mediagoblin/user_pages/views.py --| modified: added decorator user_in_group to file_a_report --\ mediagoblin/admin/views.py --| modified: added decorator require_admin_login to all views functions General Code Tidying ============================= --/ mediagoblin/admin/views.py --/ mediagoblin/user_pages/forms.py --/ mediagoblin/db/models.py --/ mediagoblin/user_pages/lib.py --/ mediagoblin/user_pages/views.py --/ mediagoblin/db/migrations.py
Diffstat (limited to 'mediagoblin/admin/views.py')
-rw-r--r--mediagoblin/admin/views.py35
1 files changed, 14 insertions, 21 deletions
diff --git a/mediagoblin/admin/views.py b/mediagoblin/admin/views.py
index faa8603a..7a4dfbd4 100644
--- a/mediagoblin/admin/views.py
+++ b/mediagoblin/admin/views.py
@@ -17,18 +17,14 @@
from werkzeug.exceptions import Forbidden
from mediagoblin.db.models import MediaEntry, User, MediaComment, CommentReport, ReportBase
-from mediagoblin.decorators import require_active_login
+from mediagoblin.decorators import require_admin_login
from mediagoblin.tools.response import render_to_response
-@require_active_login
+@require_admin_login
def admin_processing_panel(request):
'''
- Show the global processing panel for this instance
+ Show the global media processing panel for this instance
'''
- # TODO: Why not a "require_admin_login" decorator throwing a 403 exception?
- if not request.user.is_admin:
- raise Forbidden()
-
processing_entries = MediaEntry.query.filter_by(state = u'processing').\
order_by(MediaEntry.created.desc())
@@ -47,15 +43,11 @@ def admin_processing_panel(request):
'failed_entries': failed_entries,
'processed_entries': processed_entries})
-@require_active_login
+@require_admin_login
def admin_users_panel(request):
'''
- Show the global processing panel for this instance
+ Show the global panel for monitoring users in this instance
'''
- # TODO: Why not a "require_admin_login" decorator throwing a 403 exception?
- if not request.user.is_admin:
- raise Forbidden()
-
user_list = User.query
# Render to response
@@ -64,17 +56,18 @@ def admin_users_panel(request):
'mediagoblin/admin/user.html',
{'user_list': user_list})
-@require_active_login
+@require_admin_login
def admin_reports_panel(request):
'''
- Show the global processing panel for this instance
+ Show the global panel for monitoring reports filed against comments or
+ media entries for this instance.
'''
- # TODO: Why not a "require_admin_login" decorator throwing a 403 exception?
- if not request.user.is_admin:
- raise Forbidden()
-
- report_list = ReportBase.query.filter(ReportBase.resolved==None).order_by(ReportBase.created.desc()).limit(10)
- closed_report_list = ReportBase.query.filter(ReportBase.resolved!=None).order_by(ReportBase.created.desc()).limit(10)
+ report_list = ReportBase.query.filter(
+ ReportBase.resolved==None).order_by(
+ ReportBase.created.desc()).limit(10)
+ closed_report_list = ReportBase.query.filter(
+ ReportBase.resolved!=None).order_by(
+ ReportBase.created.desc()).limit(10)
# Render to response
return render_to_response(