# HG changeset patch # User Brian Neal # Date 1259533995 0 # Node ID e04d91babfcfd13e182e237e279e985bb2fd8794 # Parent 7ea842744a57cb607456b30b1440d7d6f6824105 Close #30. Create an admin dashboard to see pending content and requests for admin action. diff -r 7ea842744a57 -r e04d91babfcf gpp/core/templatetags/custom_admin_tags.py --- /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, + } diff -r 7ea842744a57 -r e04d91babfcf gpp/gcalendar/admin.py --- 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', ) diff -r 7ea842744a57 -r e04d91babfcf gpp/gcalendar/models.py --- 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 diff -r 7ea842744a57 -r e04d91babfcf gpp/templates/admin/base_site.html --- 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 %} -

{% trans 'Gremmies Portal Project Site Administration' %}

+

{% trans 'SurfGuitar101.com Site Administration' %}

{% endblock %} {% block nav-global %}{% endblock %} diff -r 7ea842744a57 -r e04d91babfcf gpp/templates/admin/custom_index.html --- /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 %} +
+{% admin_dashboard %} +{% if app_list %} + {% for app in app_list %} +
+ + + {% for model in app.models %} + + {% if model.perms.change %} + + {% else %} + + {% endif %} + + {% if model.perms.add %} + + {% else %} + + {% endif %} + + {% if model.perms.change %} + + {% else %} + + {% endif %} + + {% endfor %} +
{% blocktrans with app.name as name %}{{ name }}{% endblocktrans %}
{{ model.name }}{{ model.name }}{% trans 'Add' %} {% trans 'Change' %} 
+
+ {% endfor %} +{% else %} +

{% trans "You don't have permission to edit anything." %}

+{% endif %} +
+{% endblock %} diff -r 7ea842744a57 -r e04d91babfcf gpp/templates/core/admin_dashboard.html --- /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 @@ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Admin Dashboard
Flagged Posts{{ flagged_posts }}
Flagged Comments{{ flagged_comments }}
Flagged Profiles{{ flagged_profiles }}
Calendar Requests{{ event_requests }}
New Stories{{ new_stories }}
New Downloads{{ new_downloads }}
New Links{{ new_links }}
+
diff -r 7ea842744a57 -r e04d91babfcf gpp/urls.py --- 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 = {