You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
258 lines
9.0 KiB
258 lines
9.0 KiB
|
|
|
|
import json
|
|
import random
|
|
from functools import lru_cache
|
|
|
|
from django.contrib.humanize.templatetags.humanize import intcomma
|
|
from django.utils.safestring import mark_safe
|
|
from django.utils.translation import gettext_lazy as _
|
|
from django.views.generic import RedirectView, TemplateView
|
|
|
|
# Import Filer admin classes
|
|
from filer.admin.fileadmin import FileAdmin
|
|
from filer.admin.folderadmin import FolderAdmin
|
|
from filer.admin.imageadmin import ImageAdmin
|
|
from filer.models import File, Folder, Image
|
|
|
|
def dashboard_callback(request, context):
|
|
context.update(random_data())
|
|
return context
|
|
|
|
import json
|
|
import random
|
|
from functools import lru_cache
|
|
|
|
from django.contrib.humanize.templatetags.humanize import intcomma
|
|
from django.utils.safestring import mark_safe
|
|
from django.utils.translation import gettext_lazy as _
|
|
from django.views.generic import RedirectView, TemplateView
|
|
from unfold.views import UnfoldModelAdminViewMixin
|
|
|
|
|
|
from unfold.sites import UnfoldAdminSite
|
|
from django import forms
|
|
from django.conf import settings
|
|
from unfold.forms import AuthenticationForm
|
|
|
|
|
|
class LoginForm(AuthenticationForm):
|
|
password = forms.CharField(widget=forms.PasswordInput(render_value=True))
|
|
|
|
def __init__(self, request=None, *args, **kwargs):
|
|
super().__init__(request, *args, **kwargs)
|
|
# Change the label of the username field to "Email"
|
|
self.fields["username"].label = "Email"
|
|
|
|
|
|
|
|
class FormulaAdminSite(UnfoldAdminSite):
|
|
login_form = LoginForm
|
|
|
|
|
|
project_admin_site = FormulaAdminSite()
|
|
|
|
# # Register Filer models with the admin site
|
|
# project_admin_site.register(Folder, FolderAdmin)
|
|
# project_admin_site.register(File, FileAdmin)
|
|
# project_admin_site.register(Image, ImageAdmin)
|
|
|
|
|
|
class HomeView(RedirectView):
|
|
pattern_name = "admin:index"
|
|
|
|
|
|
def variables(request):
|
|
return {"plausible_domain": settings.PLAUSIBLE_DOMAIN}
|
|
|
|
# class MyClassBasedView(UnfoldModelAdminViewMixin, TemplateView):
|
|
# title = "Custom Title" # required: custom page header title
|
|
# # required: tuple of permissions
|
|
# permission_required = (
|
|
# "formula.view_driver",
|
|
# "formula.add_driver",
|
|
# "formula.change_driver",
|
|
# "formula.delete_driver",
|
|
# )
|
|
# template_name = "formula/driver_custom_page.html"
|
|
|
|
|
|
def dashboard_callback(request, context):
|
|
context.update(random_data())
|
|
return context
|
|
|
|
|
|
@lru_cache
|
|
def random_data():
|
|
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)]
|
|
|
|
return {
|
|
"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": f"${intcomma(f'{random.uniform(1000, 9999):.02f}')}",
|
|
"footer": mark_safe(
|
|
f'<strong class="text-green-700 font-semibold dark:text-green-400">+{intcomma(f"{random.uniform(1, 9):.02f}")}%</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": f"${intcomma(f'{random.uniform(1000, 9999):.02f}')}",
|
|
"footer": mark_safe(
|
|
f'<strong class="text-green-700 font-semibold dark:text-green-400">+{intcomma(f"{random.uniform(1, 9):.02f}")}%</strong> progress from last week'
|
|
),
|
|
},
|
|
{
|
|
"title": "Product C Performance",
|
|
"metric": f"${intcomma(f'{random.uniform(1000, 9999):.02f}')}",
|
|
"footer": mark_safe(
|
|
f'<strong class="text-green-700 font-semibold dark:text-green-400">+{intcomma(f"{random.uniform(1, 9):.02f}")}%</strong> progress from last week'
|
|
),
|
|
},
|
|
],
|
|
"progress": [
|
|
{
|
|
"title": "🦆 Social marketing e-book",
|
|
"description": f"${intcomma(f'{random.uniform(1000, 9999):.02f}')}",
|
|
"value": random.randint(10, 90),
|
|
},
|
|
{
|
|
"title": "🦍 Freelancing tasks",
|
|
"description": f"${intcomma(f'{random.uniform(1000, 9999):.02f}')}",
|
|
"value": random.randint(10, 90),
|
|
},
|
|
{
|
|
"title": "🐋 Development coaching",
|
|
"description": f"${intcomma(f'{random.uniform(1000, 9999):.02f}')}",
|
|
"value": random.randint(10, 90),
|
|
},
|
|
{
|
|
"title": "🦑 Product consulting",
|
|
"description": f"${intcomma(f'{random.uniform(1000, 9999):.02f}')}",
|
|
"value": random.randint(10, 90),
|
|
},
|
|
{
|
|
"title": "🐨 Other income",
|
|
"description": f"${intcomma(f'{random.uniform(1000, 9999):.02f}')}",
|
|
"value": random.randint(10, 90),
|
|
},
|
|
{
|
|
"title": "🐶 Course sales",
|
|
"description": f"${intcomma(f'{random.uniform(1000, 9999):.02f}')}",
|
|
"value": random.randint(10, 90),
|
|
},
|
|
{
|
|
"title": "🐻❄️ Ads revenue",
|
|
"description": f"${intcomma(f'{random.uniform(1000, 9999):.02f}')}",
|
|
"value": random.randint(10, 90),
|
|
},
|
|
{
|
|
"title": "🦩 Customer Retention Rate",
|
|
"description": f"${intcomma(f'{random.uniform(1000, 9999):.02f}')}",
|
|
"value": random.randint(10, 90),
|
|
},
|
|
{
|
|
"title": "🦊 Marketing ROI",
|
|
"description": f"${intcomma(f'{random.uniform(1000, 9999):.02f}')}",
|
|
"value": random.randint(10, 90),
|
|
},
|
|
{
|
|
"title": "🦁 Affiliate partnerships",
|
|
"description": f"${intcomma(f'{random.uniform(1000, 9999):.02f}')}",
|
|
"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,
|
|
"borderColor": "var(--color-primary-500)",
|
|
},
|
|
{
|
|
"label": "Example 2",
|
|
"data": positive,
|
|
"backgroundColor": "var(--color-primary-700)",
|
|
},
|
|
{
|
|
"label": "Example 3",
|
|
"data": negative,
|
|
"backgroundColor": "var(--color-primary-300)",
|
|
},
|
|
],
|
|
}
|
|
),
|
|
"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": "var(--color-primary-700)",
|
|
}
|
|
],
|
|
}
|
|
),
|
|
},
|
|
{
|
|
"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": "var(--color-primary-300)",
|
|
}
|
|
],
|
|
}
|
|
),
|
|
},
|
|
],
|
|
}
|