diff --git a/InvenTree/InvenTree/static/script/inventree/inventree.js b/InvenTree/InvenTree/static/script/inventree/inventree.js index 90dbacbe35..04539c6d96 100644 --- a/InvenTree/InvenTree/static/script/inventree/inventree.js +++ b/InvenTree/InvenTree/static/script/inventree/inventree.js @@ -41,6 +41,13 @@ function inventreeDocReady() { modal.modal('show'); }); + + // Callback to launch the 'Database Stats' window + $('#launch-stats').click(function() { + launchModalForm("/stats/", { + no_post: true, + }); + }); } function isFileTransfer(transfer) { diff --git a/InvenTree/InvenTree/urls.py b/InvenTree/InvenTree/urls.py index 31b498ea2b..4b18916828 100644 --- a/InvenTree/InvenTree/urls.py +++ b/InvenTree/InvenTree/urls.py @@ -33,7 +33,8 @@ from django.conf.urls.static import static from django.views.generic.base import RedirectView from rest_framework.documentation import include_docs_urls -from .views import IndexView, SearchView, SettingsView, EditUserView, SetPasswordView +from .views import IndexView, SearchView, DatabaseStatsView +from .views import SettingsView, EditUserView, SetPasswordView from .views import InfoView from users.urls import user_urls @@ -97,6 +98,7 @@ urlpatterns = [ url(r'^index/', IndexView.as_view(), name='index'), url(r'^search/', SearchView.as_view(), name='search'), + url(r'^stats/', DatabaseStatsView.as_view(), name='stats'), url(r'^api/', include(apipatterns)), url(r'^api-doc/', include_docs_urls(title='InvenTree API')), diff --git a/InvenTree/InvenTree/views.py b/InvenTree/InvenTree/views.py index 95ad33cba1..5121b1bad9 100644 --- a/InvenTree/InvenTree/views.py +++ b/InvenTree/InvenTree/views.py @@ -8,6 +8,7 @@ as JSON objects and passing them to modal forms (using jQuery / bootstrap). # -*- coding: utf-8 -*- from __future__ import unicode_literals +from django.utils.translation import gettext_lazy as _ from django.template.loader import render_to_string from django.http import JsonResponse, HttpResponseRedirect @@ -15,7 +16,8 @@ from django.views import View from django.views.generic import UpdateView, CreateView from django.views.generic.base import TemplateView -from part.models import Part +from part.models import Part, PartCategory +from stock.models import StockLocation, StockItem from common.models import InvenTreeSetting from .forms import DeleteForm, EditUserForm, SetPasswordForm @@ -537,3 +539,33 @@ class SettingsView(TemplateView): ctx['settings'] = InvenTreeSetting.objects.all().order_by('key') return ctx + + +class DatabaseStatsView(AjaxView): + """ View for displaying database statistics """ + + ajax_template_name = "stats.html" + ajax_form_title = _("Database Statistics") + + def get_context_data(self, **kwargs): + + ctx = {} + + # Part stats + ctx['part_count'] = Part.objects.count() + ctx['part_cat_count'] = PartCategory.objects.count() + + # Stock stats + ctx['stock_item_count'] = StockItem.objects.count() + ctx['stock_loc_count'] = StockLocation.objects.count() + + """ + TODO: Other ideas for database metrics + + - "Popular" parts (used to make other parts?) + - Most ordered part + - Most sold part + - etc etc etc + """ + + return ctx diff --git a/InvenTree/templates/navbar.html b/InvenTree/templates/navbar.html index 2118bd2197..691b73f982 100644 --- a/InvenTree/templates/navbar.html +++ b/InvenTree/templates/navbar.html @@ -1,4 +1,5 @@ {% load static %} +{% load i18n %}