Mercurial > public > sg101
changeset 139:e04d91babfcf
Close #30. Create an admin dashboard to see pending content and requests for admin action.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 29 Nov 2009 22:33:15 +0000 (2009-11-29) |
parents | 7ea842744a57 |
children | 91a01b8b5885 |
files | gpp/core/templatetags/custom_admin_tags.py gpp/gcalendar/admin.py gpp/gcalendar/models.py gpp/templates/admin/base_site.html gpp/templates/admin/custom_index.html gpp/templates/core/admin_dashboard.html gpp/urls.py |
diffstat | 7 files changed, 126 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gpp/core/templatetags/custom_admin_tags.py Sun Nov 29 22:33:15 2009 +0000 @@ -0,0 +1,44 @@ +""" +Custom template tags for the admin. +""" +from django import template +from django.db.models import Q + +from bio.models import UserProfileFlag +from comments.models import CommentFlag +from downloads.models import Download +from forums.models import FlaggedPost +from gcalendar.models import Event +from news.models import PendingStory +from weblinks.models import Link + + +register = template.Library() + + +@register.inclusion_tag('core/admin_dashboard.html') +def admin_dashboard(): + """ + This tag is used in the admin to create a dashboard + of pending content that an admin must approve. + """ + flagged_profiles = UserProfileFlag.objects.count() + flagged_comments = CommentFlag.objects.count() + new_downloads = Download.objects.filter(is_public=False).count() + flagged_posts = FlaggedPost.objects.count() + event_requests = Event.objects.filter( + Q(status=Event.NEW) | + Q(status=Event.EDIT_REQ) | + Q(status=Event.DEL_REQ)).count() + new_stories = PendingStory.objects.count() + new_links = Link.objects.filter(is_public=False).count() + + return { + 'flagged_profiles': flagged_profiles, + 'flagged_comments': flagged_comments, + 'new_downloads': new_downloads, + 'flagged_posts': flagged_posts, + 'event_requests': event_requests, + 'new_stories': new_stories, + 'new_links': new_links, + }
--- a/gpp/gcalendar/admin.py Fri Nov 27 21:55:32 2009 +0000 +++ b/gpp/gcalendar/admin.py Sun Nov 29 22:33:15 2009 +0000 @@ -11,7 +11,7 @@ class EventAdmin(admin.ModelAdmin): list_display = ('what', 'user', 'start_date', 'where', 'date_submitted', - 'status', 'needs_approval') + 'status', 'is_approved') list_filter = ('start_date', 'status') search_fields = ('what', 'where', 'description') raw_id_fields = ('user', )
--- a/gpp/gcalendar/models.py Fri Nov 27 21:55:32 2009 +0000 +++ b/gpp/gcalendar/models.py Sun Nov 29 22:33:15 2009 +0000 @@ -94,6 +94,7 @@ self.html = site_markup(self.description) super(Event, self).save(*args, **kwargs) - def needs_approval(self): - return self.status in (self.NEW, self.EDIT_REQ, self.DEL_REQ) + def is_approved(self): + return self.status not in (self.NEW, self.EDIT_REQ, self.DEL_REQ) + is_approved.boolean = True
--- a/gpp/templates/admin/base_site.html Fri Nov 27 21:55:32 2009 +0000 +++ b/gpp/templates/admin/base_site.html Sun Nov 29 22:33:15 2009 +0000 @@ -1,10 +1,10 @@ {% extends "admin/base.html" %} {% load i18n %} -{% block title %}{{ title }} | {% trans 'GPP Site Admin' %}{% endblock %} +{% block title %}{{ title }} | {% trans 'SG101 Site Admin' %}{% endblock %} {% block branding %} -<h1 id="site-name">{% trans 'Gremmies Portal Project Site Administration' %}</h1> +<h1 id="site-name">{% trans 'SurfGuitar101.com Site Administration' %}</h1> {% endblock %} {% block nav-global %}{% endblock %}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gpp/templates/admin/custom_index.html Sun Nov 29 22:33:15 2009 +0000 @@ -0,0 +1,40 @@ +{% extends "admin/index.html" %} +{% load i18n %} +{% load custom_admin_tags %} +{% block content %} +<div id="content-main"> +{% admin_dashboard %} +{% if app_list %} + {% for app in app_list %} + <div class="module"> + <table summary="{% blocktrans with app.name as name %}Models available in the {{ name }} application.{% endblocktrans %}"> + <caption><a href="{{ app.app_url }}" class="section">{% blocktrans with app.name as name %}{{ name }}{% endblocktrans %}</a></caption> + {% for model in app.models %} + <tr> + {% if model.perms.change %} + <th scope="row"><a href="{{ model.admin_url }}">{{ model.name }}</a></th> + {% else %} + <th scope="row">{{ model.name }}</th> + {% endif %} + + {% if model.perms.add %} + <td><a href="{{ model.admin_url }}add/" class="addlink">{% trans 'Add' %}</a></td> + {% else %} + <td> </td> + {% endif %} + + {% if model.perms.change %} + <td><a href="{{ model.admin_url }}" class="changelink">{% trans 'Change' %}</a></td> + {% else %} + <td> </td> + {% endif %} + </tr> + {% endfor %} + </table> + </div> + {% endfor %} +{% else %} + <p>{% trans "You don't have permission to edit anything." %}</p> +{% endif %} +</div> +{% endblock %}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gpp/templates/core/admin_dashboard.html Sun Nov 29 22:33:15 2009 +0000 @@ -0,0 +1,33 @@ +<div class="module"> +<table summary="Admin Dashboard"> + <caption>Admin Dashboard</caption> + <tr> + <th><a href="/admin/forums/flaggedpost/">Flagged Posts</a></th> + <td>{{ flagged_posts }}</td> + </tr> + <tr> + <th><a href="/admin/comments/commentflag/">Flagged Comments</a></th> + <td>{{ flagged_comments }}</td> + </tr> + <tr> + <th><a href="/admin/bio/userprofileflag/">Flagged Profiles</a></th> + <td>{{ flagged_profiles }}</td> + </tr> + <tr> + <th><a href="/admin/gcalendar/event/">Calendar Requests</a></th> + <td>{{ event_requests }}</td> + </tr> + <tr> + <th><a href="/admin/news/pendingstory/">New Stories</a></th> + <td>{{ new_stories }}</td> + </tr> + <tr> + <th><a href="/admin/downloads/download/">New Downloads</a></th> + <td>{{ new_downloads }}</td> + </tr> + <tr> + <th><a href="/admin/weblinks/link/">New Links</a></th> + <td>{{ new_links }}</td> + </tr> +</table> +</div>
--- a/gpp/urls.py Fri Nov 27 21:55:32 2009 +0000 +++ b/gpp/urls.py Sun Nov 29 22:33:15 2009 +0000 @@ -3,6 +3,9 @@ from django.contrib import admin from news.feeds import LatestNewsFeed +# Use the default admin site, but tell it to use a custom +# index template: +admin.site.index_template = 'admin/custom_index.html' admin.autodiscover() feeds = {