Created
December 4, 2015 17:15
-
-
Save DrMartiner/bc04ba7b54550d84b723 to your computer and use it in GitHub Desktop.
dashboard's diagram for django-admin-tools
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from django.core.urlresolvers import reverse | |
from django.utils.translation import ugettext_lazy as _ | |
from admin_tools.dashboard import modules | |
from admin_tools.dashboard import Dashboard | |
from admin_tools.menu import Menu | |
from admin_tools.menu import items | |
from project.dashboard_modules import WorkedTaskDashboardModuleChart | |
class CustomIndexDashboard(Dashboard): | |
def init_with_context(self, context): | |
self.children.append(modules.AppList( | |
_('Dashboard Stats Settings'), | |
models=('admin_tools_stats.*',), | |
)) | |
self.children.append(WorkedTaskDashboardModuleChart()) | |
self.children.append(modules.RecentActions(_('Recent Actions'), 10)) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from datetime import datetime | |
from datetime import timedelta | |
from operator import itemgetter | |
from graphos.renderers import morris | |
from admin_tools.dashboard.modules import DashboardModule | |
from graphos.sources.simple import SimpleDataSource | |
from apps.salary.models import Milestone | |
from apps.salary.models import Dollar | |
from apps.salary.models import Task | |
class BaseMorrisDashboardModuleChart(DashboardModule): | |
title = '' | |
template = 'admin/charts_modules/morris.html' | |
chart_size = dict(width=465, height=200) | |
headers = [] | |
chart_class = morris.BarChart | |
css_classes = ['chart-module'] | |
def is_empty(self): | |
return False | |
def init_with_context(self, context): | |
data_source = self.get_data_source() | |
context['chart'] = self.chart_class(data_source, | |
options={'title': self.title}, | |
**self.chart_size) | |
def get_data_source(self): | |
raise NotImplemented | |
class WorkedTaskDashboardModuleChart(BaseMorrisDashboardModuleChart): | |
title = u'Отработанные часы' | |
days = 14 | |
headers = [u'День', u'Часы'] | |
chart_class = morris.BarChart | |
def get_data_source(self): | |
today = datetime.today() | |
current_date = datetime(year=today.year, month=today.month, day=today.day) | |
data = [self.headers] | |
for i in reversed(range(0, self.days)): | |
end_date = current_date + timedelta(days=1) | |
hours = 0. | |
for task in Task.objects.filter(work_begin__range=(current_date, end_date)): | |
hours += float(task.work_time) | |
data.append([current_date.strftime('%d.%m').lower(), hours]) | |
current_date -= timedelta(days=1) | |
data_source = SimpleDataSource(data=data) | |
return data_source | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment