python django-admin-tools的仪表板图

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python django-admin-tools的仪表板图相关的知识,希望对你有一定的参考价值。

# -*- 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
        
# -*- 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))
        

以上是关于python django-admin-tools的仪表板图的主要内容,如果未能解决你的问题,请参考以下文章

如何在 django-admin-tools 仪表板上添加自定义菜单项

django-admin-tools 和 django-grappelli 的比较

django-admin-tools 仪表板在 IE8 中不可拖动

代写python,代写python编程,python代写,python编程代写,留学生python代写

001--python全栈--基础知识--python安装

Python代写,Python作业代写,代写Python,代做Python