Package: django-geckoboard
Geckoboardis a hosted, real-time status board serving up indicators
from web analytics, CRM, support, infrastructure, project management,
sales, etc.  It can be connected to virtually any source of quantitative
data.  ThisDjangoapplication provides view decorators to help create
custom widgets.InstallationTo install django-geckoboard, simply place thedjango_geckoboardpackage somewhere on the Python path.  You do not need to add it to theINSTALLED_APPSlist, unless you want to run the tests.Limiting accessIf you want to protect the data you send to Geckoboard from access by
others, you can use an API key shared by Geckoboard and your widget
views.  SetGECKOBOARD_API_KEYin the projectsettings.pyfile:GECKOBOARD_API_KEY = 'XXXXXXXXX'If you do not set an API key, anyone will be able to view the data by
visiting the widget URL.EncryptionGeckoboard encryption allows encrypting data before it is sent to Geckoboard’s
servers. After entering the password used to encrypt the data when the Geckoboard
is loaded, the data will be decrypted in the browser.To use encryption, first set a password in the projectsettings.pyfile:GECKOBOARD_PASSWORD = 'XXXXXXXXX'Next, enable encryption for each widget using the decorator arguments:@number_widget(encrypted=True)
    def user_count(request):
        return User.objects.count()Creating custom widgetsThe available custom widgets are described in the Geckoboard support
section, underGeckoboard API.  From the perspective of a Django
project, a custom widget is just a view.  The django-geckoboard
application provides view decorators that render the correct response
for the different widgets.Let’s say you want to add a widget to your dashboard that shows the
number of number of comments posted today.  First create a view, using a
django-geckoboard decorator:from datetime import date, time, datetime
from django.contrib.comments.models import Comment
from django_geckoboard.decorators import number_widget

@number_widget
def comment_count(request):
    midnight = datetime.combine(date.today(), time.min)
    return Comment.objects.filter(submit_date__gte=midnight).count()You can also specify the output format of the widget as either JSON or XML:@number_widget(format='json')
def comment_count(request):
     midnight = datatime.combine(date.today(), time.min)
     return Comment.objects.filter(submit_data__get=midnight).count()If your widget has optional settings, you can pass them in the decorator
definition:@number_widget(absolute='true')
def comment_count(request):
    midnight = datetime.combine(date.today(), time.min)
    return Comment.objects.filter(submit_date__gte=midnight).count()Then use a URLconf module to map a URL to the view:from django.conf.urls.defaults import *

urlpatterns = patterns('YOUR_VIEW_MODULE',
    ...
    (r'^geckoboard/comment_count/$', 'comment_count'),
)This is all the Django code you need to display the comment count on
your dashboard. When you create a custom widget in Geckoboard, enter the
following information:EncryptionEnable if the field is encrypted (see instructions above).URL data feedThe view URL.  In the example above this would be something likehttp://HOSTNAME/geckoboard/comment_count/.API keyThe content of theGECKOBOARD_API_KEYsetting, if you have set
it.Widget typeCustomFeed formatEitherXMLorJSON.  If you don’t specify a format the decorators will
automatically detect and output the correct format or default to XML
if this is not enabled (by default the format isn’t appended by
Geckoboard as a parameter any more)Request typeEitherGETorPOST.  The view decorators accept both.The following decorators are available from thedjango_geckoboard.decoratorsmodule:number_widgetRender aNumber & Secondary Statwidget.The decorated view must return a tuple(current, [previous],
[prefix])where thecurrentparameter is the current value, optionalpreviousparameter is the previous value of the measured quantity and
the optional parameterprefixis the prefix used in Geckoboard widget.
If there is only one parameter you do not need to return it in a tuple.
For example, to render a widget that shows the number of users and the
difference from last week:from django_geckoboard.decorators import number_widget
from datetime import datetime, timedelta
from django.contrib.auth.models import User

@number_widget
def user_count(request):
    last_week = datetime.now() - timedelta(weeks=1)
    users = User.objects
    last_week_users = users.filter(date_joined__lt=last_week)
    return (users.count(), last_week_users.count())

@number_widget
def users_count_with_prefix(request):
    last_week = datetime.now() - timedelta(weeks=1)
    users = User.objects
    last_week_users = users.filter(date_joined__lt=last_week)
    return (users.count(), last_week_users.count(), '$')rag_widgetRender aRAG Column & NumbersorRAG Numberswidget.The decorated view must return a tuple with three tuples(value,
[text]).  Thevalueparameters are the numbers shown in red, amber
and green (in that order).  The optionaltextparameters will be
displayed next to the respective values in the dashboard.For example, to render a widget that shows the number of comments that
were approved or deleted by moderators in the last 24 hours:from django_geckoboard.decorators import rag_widget
from datetime import datetime, timedelta
from django.contrib.comments.models import Comment, CommentFlag

@rag_widget
def comments(request):
    start_time = datetime.now() - timedelta(hours=24)
    comments = Comment.objects.filter(submit_date__gt=start_time)
    total_count = comments.count()
    approved_count = comments.filter(
            flags__flag=CommentFlag.MODERATOR_APPROVAL).count()
    deleted_count = Comment.objects.filter(
            flags__flag=CommentFlag.MODERATOR_DELETION).count()
    pending_count = total_count - approved_count - deleted_count
    return (
        (deleted_count, "Deleted comments"),
        (pending_count, "Pending comments"),
        (approved_count, "Approved comments"),
    )text_widgetRender aTextwidget.The decorated view must return a list of tuples(message, [type]).
Themessageparameters are strings that will be shown in the widget.
Thetypeparameters are optional and tell Geckoboard how to annotate
the messages.  UseTEXT_INFOfor informational messages,TEXT_WARNfor for warnings andTEXT_NONEfor plain text (the
default).  If there is only one plain message, you can just return it
without enclosing it in a list and tuple.For example, to render a widget showing the latest Geckoboard twitter
updates, using Mike Verdone’sTwitter library:from django_geckoboard.decorators import text_widget, TEXT_NONE
import twitter

@text_widget
def twitter_status(request):
    twitter = twitter.Api()
    updates = twitter.GetUserTimeline('geckoboard')
    return [(u.text, TEXT_NONE) for u in updates]pie_chartRender aPie chartwidget.The decorated view must return an iterable over tuples(value, label,
[color]).  The optionalcolorparameter is a string'RRGGBB[TT]'representing red, green, blue and optionally transparency.For example, to render a widget showing the number of normal, staff and
superusers:from django_geckoboard.decorators import pie_chart
from django.contrib.auth.models import User

@pie_chart
def user_types(request):
    users = User.objects.filter(is_active=True)
    total_count = users.count()
    superuser_count = users.filter(is_superuser=True).count()
    staff_count = users.filter(is_staff=True,
                               is_superuser=False).count()
    normal_count = total_count = superuser_count - staff_count
    return [
        (normal_count,    "Normal users", "ff8800"),
        (staff_count,     "Staff",        "00ff88"),
        (superuser_count, "Superusers",   "8800ff"),
    ]line_chartRender aLine chartwidget.The decorated view must return a tuple(values, x_axis, y_axis,
[color]).  Thevaluesparameter is a list of data points.  Thex-axisparameter is a label string or a list of strings, that will be
placed on the X-axis.  They-axisparameter works similarly for the
Y-axis.  If there are more than one axis label, they are placed evenly
along the axis.  The optionalcolorparameter is a string'RRGGBB[TT]'representing red, green, blue and optionally
transparency.For example, to render a widget showing the number of comments per day
over the last four weeks (including today):from django_geckoboard.decorators import line_chart
from datetime import date, timedelta
from django.contrib.comments.models import Comment

@line_chart
def comment_trend(request):
    since = date.today() - timedelta(days=29)
    days = dict((since + timedelta(days=d), 0)
            for d in range(0, 29))
    comments = Comment.objects.filter(submit_date__gte=since)
    for comment in comments:
        days[comment.submit_date.date()] += 1
    return (
        days.values(),
        [days[i] for i in range(0, 29, 7)],
        "Comments",
    )geck_o_meterRender aGeck-O-Meterwidget.The decorated view must return a tuple(value, min, max).  Thevalueparameter represents the current value.  Theminandmaxparameters
represent the minimum and maximum value respectively.  They are either a
value, or a tuple(value, text).  If used, thetextparameter will
be displayed next to the minimum or maximum value.For example, to render a widget showing the number of users that have
logged in in the last 24 hours:from django_geckoboard.decorators import geck_o_meter
from datetime import datetime, timedelta
from django.contrib.auth.models import User

@geck_o_meter
def login_count(request):
    since = datetime.now() - timedelta(hours=24)
    users = User.objects.filter(is_active=True)
    total_count = users.count()
    logged_in_count = users.filter(last_login__gt=since).count()
    return (logged_in_count, 0, total_count)funnelRender aFunnelwidget.The decorated view must return a dictionary with at least anitemskey.  To render a funnel showing the breakdown of authenticated users
vs. anonymous users:from django_geckoboard.decorators import funnel
from django.contrib.auth.models import User

@funnel
def user_breakdown(request):
    all_users = User.objects
    active_users =all_users.filter(is_active=True)
    staff_users = all_users.filter(is_staff=True)
    super_users = all_users.filter(is_superuser=True)
    return {
        "items": [
            (all_users.count(), 'All users'),
            (active_users.count(), 'Active users'),
            (staff_users.count(), 'Staff users'),
            (super_users.count(), 'Super users'),
        ],
        "type": "standard",   # default, 'reverse' changes direction
                              # of the colors.
        "percentage": "show", # default, 'hide' hides the percentage
                              # values.
        "sort": False,        # default, `True` orders the values
                              # descending.
    }bulletRender aBulletwidget.The decorated view must return a dictionary with at least keyslabel,axis_points,currentandcomparative. To render Geckoboard’s own example
athttp://support.geckoboard.com/entries/274940-custom-chart-widget-type-definitions:from django_geckoboard.decorators import bullet

@bullet
def geckoboard_bullet_example(request):
    return = {
        'label': 'Revenue 2011 YTD',
        'axis_points': [0, 200, 400, 600, 800, 1000],
        'current': 500,
        'comparative': 600,
        'sublabel': 'U.S. $ in thousands',
        'red': [0, 400],
        'amber': [401, 700],
        'green': [701, 1000],
        'projected': [100, 900],
        'auto_scale': False,
    }ChangelogVersion 2.0.0Add support for Python 3.4 and 4.5 and drop support for Python < 2.7;
add support for Django 1.9 and drop support for Django < 1.8
(Matt Terry)Version 1.2.8Use json package directly (Max Lynch)Version 1.2.7Add support for encryption (Jeremy A. Johnson)Allow setting output format in widget decorator (Rob Hudson)Version 1.2.6Allow number widget to return list of dicts (Arthur Furlan)Version 1.2.5Add support for the “prefix” parameter (Arthur Furlan)Version 1.2.4Add “Content-Type” header (Arthur Furlan)Version 1.2.3Fix KeyError bug in auto-scaling code (Ben Belchak)Version 1.2.2Fix comparative bar on bullet graphs (Rod Begbie)Version 1.2.1Fix unicode handling (Éric St-Jean)Version 1.2.0Addbulletwidget decorator (Hedley Roos)Version 1.1.0Addfunnelwidget decorator (Simon de Haan)Version 1.0.0No changes from 0.2.1Version 0.2.1Fix API key detectionVersion 0.2.0Rename widget decoratorsVersion 0.1.0First release, split off fromdjango-analytical.