Package: django-dashboard-app
Django Dashboard AppA reusable Django app for displaying a dashboard with a fluid grid of widgets.Let’s say you control 20 different web apps and you want to have a dashboard
that shows the user count of each app as a graph. The graphs should be updated
every minute so that you can see immediately when a sudden spike of new user
signups happens.There are two ways:Your apps provide an API endpoint for your dashboard so that the dashboard
can poll that endpoint every minute and get the current user count.Your dashboard provides an endpoint that can be called by your apps whenever
a new user signs up.Ultimately, both methods should be possible with this app. Currently only the
first way is implemented.The dashboard itself will consist of many plugins. Each plugin is a reusable
Django app of it’s own. This allows you to write any kind of plugin for any
kind of service.Note: A while ago I already createdhttps://github.com/bitmazk/django-metrics-dashboardto solve this exact problem
but I wanted to have socket.io support, which was a bad idea. It didn’t really
work out nicely and kept crashing so that I abandoned the project in the end.
This is my second try, this time I’m using old-school polling once per minute
via AJAX.InstallationTo get the latest stable release from PyPipipinstalldjango-dashboard-appTo get the latest commit from GitHubpipinstall-egit+git://github.com/bitmazk/django-dashboard-app.git#egg=dashboard_appTODO: Describe further installation steps (edit / remove the examples below):Adddashboard_appanddjango.contrib.humanizeto yourINSTALLED_APPS:INSTALLED_APPS=(...,'django.contrib.humanize','dashboard_app',)Add thedashboard_appURLs to yoururls.pyurlpatterns=patterns('',...url(r'^dashboard/',include('dashboard_app.urls')),)Don’t forget to migrate your database./manage.pymigratedashboard_appUsageWhen you first visit the main URL for your dashboard, you will see an error
widget saying “No widgets found”. This means we need to teach Django which
widgets to display.In your Django project-app-folder (assuming Django >1.5 project layout) create
adashboard_widgets.pyfile (you can put that file into any app folder that
is part ofINSTALLED_APPS).Add the following code to that file:"""Widgets for the ACME project."""fromdashboard_app.dashboard_widgetsimportDummyWidgetfromdashboard_app.widget_poolimportdashboard_widget_pooldashboard_widget_pool.register_widget(DummyWidget,position=1)When you call your main dashboard URL now, you should see the dummy widget
displaying the current date and time. The last update time resembles the time
when the widget did write data to the database last time. Since this widget
never writes any data, this time will always be the time when you first loaded
the widget under this name.Build Your WidgetFirst you need to decide where your widget code should live. If you are very
sure that your widgets will always be bound to the project and never be
released as open source or re-used in other projects of yours, you can
implement your widgets in thedashboard_widgets.pyfile that you have
created in your Django project-app already.If you think that your widget will be usefull for many projects, you should
create it as a reusable app and therefore create a new app-folder. Let’s
assume that your project is calledACMEand you want to create a widget
to display the current user count. First create the following files:-- dashboard_acme_users
---- __init__.py
---- models.py
---- dashboard_widgets.pyYour widget apps should always be named likedashboard_yourthingso that
it is easier to find them all on Google/Github. The__init__.pyfile will
turn the app into a Python module and themodels.pyfile is needed to turn
the module into a potential Django app that can be discovered by theINSTALLED_APPSsetting. Thedashboard_widgets.pyfile is the file
where you will implement your custom widget.Put the following code into that file:"""Widgets for the dashboard_acme_users app."""fromdashboard_app.widget_baseimportDashboardWidgetBasefromdjango.contrib.auth.modelsimportUserclassUserCountWidget(DashboardWidgetBase):"""Displays the total amount of users currently in the database."""template_name='dashboard_acme_users/widgets/user_count.html'defget_context_data(self):ctx=super(UserCountWidget,self).get_context_data()count=User.objects.all().count()ctx.update({'value':count,})returnctxYou basically just have to decide on a nice widget name (here:UserCountWidget) and a template name. We suggest to put the widgets into
a subfolder calledyour_app_name/widgetsand name the template after the
widget’s class name (here:user_count.html).Now you want to display something. In our case it is the current user count.
Therefore we must override theget_context_datamethod and return the
current user count.Now you need to register your new widget in thedashboard_widgets.pyfile
that you used earlier to register the DummyWidget:"""Widgets for the ACME project."""fromdashboard_app.dashboard_widgetsimportDummyWidgetfromdashboard_app.widget_poolimportdashboard_widget_poolfromdashboard_acme_usersimportdashboard_widgetsaswidgetsdashboard_widget_pool.register_widget(DummyWidget,position=1)dashboard_widget_pool.register_widget(widgets.UserCountWidget,position=2)When you visit your main dashboard URL you should see two widgets now.TODO: Describe how to save widget data to the database and render chartsContributeIf you want to contribute to this project, please perform the following steps# Fork this repository
# Clone your forkmkvirtualenv-ppython2.7django-dashboard-appmakedevelopgitco-bfeature_branchmaster# Implement your feature and testsgitadd.&&gitcommitgitpush-uoriginfeature_branch# Send us a pull request for your feature branch