1
|
|
|
# coding: utf-8 |
2
|
|
|
# Copyright 2013 Mathias WOLFF |
3
|
|
|
# This file is part of pyfreebilling. |
4
|
|
|
# |
5
|
|
|
# pyfreebilling is free software: you can redistribute it and/or modify |
6
|
|
|
# it under the terms of the GNU General Public License as published by |
7
|
|
|
# the Free Software Foundation, either version 3 of the License, or |
8
|
|
|
# (at your option) any later version. |
9
|
|
|
# |
10
|
|
|
# pyfreebilling is distributed in the hope that it will be useful, |
11
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13
|
|
|
# GNU General Public License for more details. |
14
|
|
|
# |
15
|
|
|
# You should have received a copy of the GNU General Public License |
16
|
|
|
# along with pyfreebilling. If not, see <http://www.gnu.org/licenses/> |
17
|
|
|
|
18
|
|
|
from django import template |
19
|
|
|
import datetime |
20
|
|
|
from django.db.models import Sum |
21
|
|
|
|
22
|
|
|
from ..utils import time_series |
23
|
|
|
from ..models import Company, DimCustomerDestination, DimCustomerHangupcause |
24
|
|
|
|
25
|
|
|
register = template.Library() |
26
|
|
|
|
27
|
|
|
@register.inclusion_tag('snippets/general_stats.html') |
28
|
|
|
def companies_list(): |
29
|
|
|
company_list = Company.objects.filter(customer_enabled=True) |
30
|
|
|
return {'companies' : company_list} |
31
|
|
|
|
32
|
|
|
|
33
|
|
View Code Duplication |
@register.inclusion_tag('snippets/dashboard.html') |
|
|
|
|
34
|
|
|
def total_stats(): |
35
|
|
|
qs_d = DimCustomerDestination.objects.all() |
36
|
|
|
qs_h = DimCustomerHangupcause.objects.all() |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
today = datetime.date.today() |
40
|
|
|
firstday = today - datetime.timedelta(days=30) |
41
|
|
|
|
42
|
|
|
ts_total_calls = time_series(qs_h, 'date__date', [firstday, today], func=Sum('total_calls')) |
43
|
|
|
ts_success_calls = time_series(qs_d, 'date__date', [firstday, today], func=Sum('success_calls')) |
44
|
|
|
ts_total_duration = time_series(qs_d, 'date__date', [firstday, today], func=Sum('total_duration')) |
45
|
|
|
ts_total_sell = time_series(qs_d, 'date__date', [firstday, today], func=Sum('total_sell')) |
46
|
|
|
ts_total_cost = time_series(qs_d, 'date__date', [firstday, today], func=Sum('total_cost')) |
47
|
|
|
return locals() |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
def get_num_user_orders(parser, token): |
51
|
|
|
try: |
52
|
|
|
tag_name, user = token.split_contents() |
53
|
|
|
return NumUserOrdersNode(user) |
54
|
|
|
except IndexError: |
55
|
|
|
raise template.TemplateSyntaxError( |
56
|
|
|
"%r tag requires a user as it's first argument" % tag_name) |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
class NumUserOrdersNode(template.Node): |
60
|
|
|
def __init__(self, user): |
61
|
|
|
self.user = template.Variable(user) |
62
|
|
|
|
63
|
|
|
def render(self, context): |
64
|
|
|
return Order.objects.filter(user=self.user.resolve(context)).count() |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
register.tag('num_orders', get_num_user_orders) |