Skip to content

Commit

Permalink
Merge pull request #4 from nyashaChiza/dashboard
Browse files Browse the repository at this point in the history
Dashboard
  • Loading branch information
nyashaChiza authored Jun 14, 2024
2 parents 81fa35b + 94a2753 commit 07a566c
Show file tree
Hide file tree
Showing 926 changed files with 374,416 additions and 61,772 deletions.
Binary file modified .DS_Store
Binary file not shown.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"python.analysis.autoImportCompletions": true,
"python.analysis.typeCheckingMode": "basic"
"python.analysis.typeCheckingMode": "basic",
"taipyStudio.gUI.elementsFilePaths": []
}
Empty file added dashboard/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions dashboard/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions dashboard/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class DashboardConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'dashboard'
1 change: 1 addition & 0 deletions dashboard/helpers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .dashboard_data import *
23 changes: 23 additions & 0 deletions dashboard/helpers/dashboard_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from transactions.models import Transaction
from stock.models import Gas
from datetime import datetime

class DashboardData:
def __init__(self, date: datetime):
self.date = date

def get_sales_data(self):

return {"current_month_total_sales": 678, "total_sales": 1000, "last_month_total_sales": 679, "week_total_sales": 67.45 , "total_sales_today":14.7}

def get_stock_data(self):

return {"current_month_total_sales_quantity": 340.3,"week_total_sales_quantity":29.4, "total_sales_quantity": 340.3,"last_month_total_sales_quantity": 340.3, "current_available_gas_quantity":230, "total_gas_quantity_sold":1220, "total_requisitions":68 }

def get_sales_plot_data(self):

return {"monthly_average":345, "weekly_average":89.3, "daily_average":23.4, "plot_data":[]}

def get_stock_sales_table_data(self):

return Transaction.objects.filter().all()
Empty file.
3 changes: 3 additions & 0 deletions dashboard/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
1 change: 1 addition & 0 deletions dashboard/templatetags/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import custom_tags # noqa: F401
22 changes: 22 additions & 0 deletions dashboard/templatetags/custom_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from django import template
from django.conf import settings
from django.contrib.auth.models import Group


register = template.Library()

@register.filter
def format_amount(value):
"""
Formats a number with thousands separators and two decimal places.
"""
try:
return "{:,.2f}".format(float(value))
except Exception as e:
settings.LOGGER.error(e)
return 0.00

@register.filter
def has_role(user, role):
group = Group.objects.filter(name=role).first()
return group in user.groups.all()
3 changes: 3 additions & 0 deletions dashboard/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
7 changes: 7 additions & 0 deletions dashboard/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.urls import path
from dashboard.views import DashboardView


urlpatterns = [
path('', DashboardView.as_view(), name='dashboard'),
]
12 changes: 12 additions & 0 deletions dashboard/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.views.generic import TemplateView
from dashboard.helpers import DashboardData
from datetime import datetime

class DashboardView(TemplateView):
template_name = 'dashboard/index.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)

context['dashboard_data'] = DashboardData(datetime.now())
return context

4 changes: 3 additions & 1 deletion gds/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = config('DEBUG', cast=bool)

ALLOWED_HOSTS = ['127.0.0.1']
ALLOWED_HOSTS = ['*']


# Application definition
Expand All @@ -30,6 +30,7 @@
#apps
'stock',
'transactions',
'dashboard',

#3rd part apps
'allauth',
Expand Down Expand Up @@ -169,3 +170,4 @@
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

1 change: 1 addition & 0 deletions gds/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
urlpatterns = [
path('admin/', admin.site.urls),
path('__debug__/', include("debug_toolbar.urls")),
path('', include('dashboard.urls')),
path('accounts/', include('allauth.urls')),
path('stock/', include('stock.urls')),
path('transactions/', include('transactions.urls')),
Expand Down
Binary file added static/.DS_Store
Binary file not shown.
Loading

0 comments on commit 07a566c

Please sign in to comment.