/
views.py
159 lines (151 loc) · 5.72 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import json
import random
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
from django.views.generic import RedirectView
class HomeView(RedirectView):
pattern_name = "admin:index"
def dashboard_callback(request, context):
WEEKDAYS = [
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat",
"Sun",
]
positive = [[1, random.randrange(8, 28)] for i in range(1, 28)]
negative = [[-1, -random.randrange(8, 28)] for i in range(1, 28)]
average = [r[1] - random.randint(3, 5) for r in positive]
performance_positive = [[1, random.randrange(8, 28)] for i in range(1, 28)]
performance_negative = [[-1, -random.randrange(8, 28)] for i in range(1, 28)]
context.update(
{
"navigation": [
{"title": _("Dashboard"), "link": "/", "active": True},
{"title": _("Analytics"), "link": "#"},
{"title": _("Settings"), "link": "#"},
],
"filters": [
{"title": _("All"), "link": "#", "active": True},
{
"title": _("New"),
"link": "#",
},
],
"kpi": [
{
"title": "Product A Performance",
"metric": "$1,234.56",
"footer": mark_safe(
'<strong class="text-green-600 font-medium">+3.14%</strong> progress from last week'
),
"chart": json.dumps(
{
"labels": [WEEKDAYS[day % 7] for day in range(1, 28)],
"datasets": [{"data": average, "borderColor": "#9333ea"}],
}
),
},
{
"title": "Product B Performance",
"metric": "$1,234.56",
"footer": mark_safe(
'<strong class="text-green-600 font-medium">+3.14%</strong> progress from last week'
),
},
{
"title": "Product C Performance",
"metric": "$1,234.56",
"footer": mark_safe(
'<strong class="text-green-600 font-medium">+3.14%</strong> progress from last week'
),
},
],
"progress": [
{
"title": "Social marketing e-book",
"description": " $1,234.56",
"value": random.randint(10, 90),
},
{
"title": "Freelancing tasks",
"description": " $1,234.56",
"value": random.randint(10, 90),
},
{
"title": "Development coaching",
"description": " $1,234.56",
"value": random.randint(10, 90),
},
{
"title": "Product consulting",
"description": " $1,234.56",
"value": random.randint(10, 90),
},
{
"title": "Other income",
"description": " $1,234.56",
"value": random.randint(10, 90),
},
],
"chart": json.dumps(
{
"labels": [WEEKDAYS[day % 7] for day in range(1, 28)],
"datasets": [
{
"label": "Example 1",
"type": "line",
"data": average,
"backgroundColor": "#f0abfc",
"borderColor": "#f0abfc",
},
{
"label": "Example 2",
"data": positive,
"backgroundColor": "#9333ea",
},
{
"label": "Example 3",
"data": negative,
"backgroundColor": "#f43f5e",
},
],
}
),
"performance": [
{
"title": _("Last week revenue"),
"metric": "$1,234.56",
"footer": mark_safe(
'<strong class="text-green-600 font-medium">+3.14%</strong> progress from last week'
),
"chart": json.dumps(
{
"labels": [WEEKDAYS[day % 7] for day in range(1, 28)],
"datasets": [
{"data": performance_positive, "borderColor": "#9333ea"}
],
}
),
},
{
"title": _("Last week expenses"),
"metric": "$1,234.56",
"footer": mark_safe(
'<strong class="text-green-600 font-medium">+3.14%</strong> progress from last week'
),
"chart": json.dumps(
{
"labels": [WEEKDAYS[day % 7] for day in range(1, 28)],
"datasets": [
{"data": performance_negative, "borderColor": "#f43f5e"}
],
}
),
},
],
},
)
return context