Merge pull request #632 from SchrodingersGat/database-stats

Database stats
This commit is contained in:
Oliver 2020-02-02 22:18:32 +11:00 committed by GitHub
commit 4b8e44bc4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 83 additions and 12 deletions

View File

@ -41,6 +41,13 @@ function inventreeDocReady() {
modal.modal('show'); modal.modal('show');
}); });
// Callback to launch the 'Database Stats' window
$('#launch-stats').click(function() {
launchModalForm("/stats/", {
no_post: true,
});
});
} }
function isFileTransfer(transfer) { function isFileTransfer(transfer) {

View File

@ -33,7 +33,8 @@ from django.conf.urls.static import static
from django.views.generic.base import RedirectView from django.views.generic.base import RedirectView
from rest_framework.documentation import include_docs_urls 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 .views import InfoView
from users.urls import user_urls from users.urls import user_urls
@ -97,6 +98,7 @@ urlpatterns = [
url(r'^index/', IndexView.as_view(), name='index'), url(r'^index/', IndexView.as_view(), name='index'),
url(r'^search/', SearchView.as_view(), name='search'), url(r'^search/', SearchView.as_view(), name='search'),
url(r'^stats/', DatabaseStatsView.as_view(), name='stats'),
url(r'^api/', include(apipatterns)), url(r'^api/', include(apipatterns)),
url(r'^api-doc/', include_docs_urls(title='InvenTree API')), url(r'^api-doc/', include_docs_urls(title='InvenTree API')),

View File

@ -8,6 +8,7 @@ as JSON objects and passing them to modal forms (using jQuery / bootstrap).
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.utils.translation import gettext_lazy as _
from django.template.loader import render_to_string from django.template.loader import render_to_string
from django.http import JsonResponse, HttpResponseRedirect 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 import UpdateView, CreateView
from django.views.generic.base import TemplateView 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 common.models import InvenTreeSetting
from .forms import DeleteForm, EditUserForm, SetPasswordForm from .forms import DeleteForm, EditUserForm, SetPasswordForm
@ -537,3 +539,33 @@ class SettingsView(TemplateView):
ctx['settings'] = InvenTreeSetting.objects.all().order_by('key') ctx['settings'] = InvenTreeSetting.objects.all().order_by('key')
return ctx 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

View File

@ -1,4 +1,5 @@
{% load static %} {% load static %}
{% load i18n %}
<nav class="navbar navbar-default navbar-fixed-top"> <nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid"> <div class="container-fluid">
@ -6,11 +7,11 @@
<a class="navbar-brand" id='logo' href="{% url 'index' %}" style="padding-top: 7px; padding-bottom: 5px;"><img src="{% static 'img/inventree.png' %}" width="40" height="40" style="display:block; margin: auto;"/></a> <a class="navbar-brand" id='logo' href="{% url 'index' %}" style="padding-top: 7px; padding-bottom: 5px;"><img src="{% static 'img/inventree.png' %}" width="40" height="40" style="display:block; margin: auto;"/></a>
</div> </div>
<ul class="nav navbar-nav"> <ul class="nav navbar-nav">
<li><a href="{% url 'part-index' %}">Parts</a></li> <li><a href="{% url 'part-index' %}">{% trans "Parts" %}</a></li>
<li><a href="{% url 'stock-index' %}">Stock</a></li> <li><a href="{% url 'stock-index' %}">{% trans "Stock" %}</a></li>
<li><a href="{% url 'build-index' %}">Build</a></li> <li><a href="{% url 'build-index' %}">{% trans "Build" %}</a></li>
<li><a href="{% url 'company-index' %}">Suppliers</a></li> <li><a href="{% url 'company-index' %}">{% trans "Suppliers" %}</a></li>
<li><a href="{% url 'purchase-order-index' %}">Orders</a></li> <li><a href="{% url 'purchase-order-index' %}">{% trans "Orders" %}</a></li>
</ul> </ul>
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
{% include "search_form.html" %} {% include "search_form.html" %}
@ -19,16 +20,17 @@
<ul class='dropdown-menu'> <ul class='dropdown-menu'>
{% if user.is_authenticated %} {% if user.is_authenticated %}
{% if user.is_staff %} {% if user.is_staff %}
<li><a href="/admin/"><span class="glyphicon glyphicon-edit"></span> Admin</a></li> <li><a href="/admin/"><span class="glyphicon glyphicon-edit"></span> {% trans "Admin" %}</a></li>
<hr> <hr>
{% endif %} {% endif %}
<li><a href="{% url 'settings' %}"><span class="glyphicon glyphicon-cog"></span> Settings</a></li> <li><a href="{% url 'settings' %}"><span class="glyphicon glyphicon-cog"></span> {% trans "Settings" %}</a></li>
<li><a href="{% url 'logout' %}"><span class="glyphicon glyphicon-log-out"></span> Logout</a></li> <li><a href="{% url 'logout' %}"><span class="glyphicon glyphicon-log-out"></span> {% trans "Logout" %}</a></li>
{% else %} {% else %}
<li><a href="{% url 'login' %}"><span class="glyphicon glyphicon-log-in"></span> Login</a></li> <li><a href="{% url 'login' %}"><span class="glyphicon glyphicon-log-in"></span> {% trans "Login" %}</a></li>
{% endif %} {% endif %}
<hr> <hr>
<li id='launch-about'><a href='#'><span class="glyphicon glyphicon-info-sign"></span> About InvenTree</a></li> <li id='launch-about'><a href='#'><span class="glyphicon glyphicon-info-sign"></span> {% trans "About InvenTree" %}</a></li>
<li id='launch-stats'><a href='#'><span class='glyphicon glyphicon-stats'></span> {% trans "Statistics" %}</a></li>
</ul> </ul>
</li> </li>
</ul> </ul>

View File

@ -0,0 +1,28 @@
{% load static %}
{% load inventree_extras %}
{% load i18n %}
<table class='table table-striped table-condensed'>
<tr>
<td colspan='2'><b>{% trans "Parts" %}</b></td>
</tr>
<tr>
<td>{% trans "Parts" %}</td>
<td>{{ part_count }}</td>
</tr>
<tr>
<td>{% trans "Part Categories" %}</td>
<td>{{ part_cat_count }}</td>
</tr>
<tr>
<td colspan="2"><b>{% trans "Stock Items" %}</b></td>
</tr>
<tr>
<td>{% trans "Stock Items" %}</td>
<td>{{ stock_item_count }}</td>
</tr>
<tr>
<td>{% trans "Stock Locations" %}</td>
<td>{{ stock_loc_count }}</td>
</tr>
</table>