Merge pull request #700 from SchrodingersGat/instance-name

Instance name
This commit is contained in:
Oliver 2020-04-06 21:09:08 +10:00 committed by GitHub
commit 5956b8cdee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 133 additions and 48 deletions

View File

@ -13,6 +13,8 @@ from django.http import StreamingHttpResponse
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from .version import inventreeVersion, inventreeInstanceName
def TestIfImage(img): def TestIfImage(img):
""" Test if an image file is indeed an image """ """ Test if an image file is indeed an image """
@ -134,6 +136,8 @@ def MakeBarcode(object_type, object_id, object_url, data={}):
data['id'] = object_id data['id'] = object_id
data['url'] = object_url data['url'] = object_url
data['tool'] = 'InvenTree' data['tool'] = 'InvenTree'
data['instance'] = inventreeInstanceName()
data['version'] = inventreeVersion()
return json.dumps(data, sort_keys=True) return json.dumps(data, sort_keys=True)

View File

@ -115,18 +115,18 @@ function loadPurchaseOrderTable(table, options) {
}, },
{ {
sortable: true, sortable: true,
field: 'supplier', field: 'reference',
title: 'Supplier', title: 'Purchase Order',
formatter: function(value, row, index, field) { formatter: function(value, row, index, field) {
return imageHoverIcon(row.supplier__image) + renderLink(row.supplier__name, '/company/' + value + '/purchase-orders/'); return renderLink(value, "/order/purchase-order/" + row.pk + "/");
} }
}, },
{ {
sortable: true, sortable: true,
field: 'reference', field: 'supplier',
title: 'Reference', title: 'Supplier',
formatter: function(value, row, index, field) { formatter: function(value, row, index, field) {
return renderLink(value, "/order/purchase-order/" + row.pk + "/"); return imageHoverIcon(row.supplier__image) + renderLink(row.supplier__name, '/company/' + value + '/purchase-orders/');
} }
}, },
{ {

View File

@ -3,10 +3,16 @@ Provides information on the current InvenTree version
""" """
import subprocess import subprocess
from common.models import InvenTreeSetting
INVENTREE_SW_VERSION = "0.0.10" INVENTREE_SW_VERSION = "0.0.10"
def inventreeInstanceName():
""" Returns the InstanceName settings for the current database """
return InvenTreeSetting.get_setting("InstanceName", "")
def inventreeVersion(): def inventreeVersion():
""" Returns the InvenTree version string """ """ Returns the InvenTree version string """
return INVENTREE_SW_VERSION return INVENTREE_SW_VERSION

View File

@ -22,7 +22,7 @@ from common.models import InvenTreeSetting
from .forms import DeleteForm, EditUserForm, SetPasswordForm from .forms import DeleteForm, EditUserForm, SetPasswordForm
from .helpers import str2bool from .helpers import str2bool
from .version import inventreeVersion from .version import inventreeVersion, inventreeInstanceName
from rest_framework import views from rest_framework import views
@ -422,7 +422,8 @@ class InfoView(AjaxView):
data = { data = {
'server': 'InvenTree', 'server': 'InvenTree',
'version': inventreeVersion() 'version': inventreeVersion(),
'instance': inventreeInstanceName(),
} }
return JsonResponse(data) return JsonResponse(data)

View File

@ -10,6 +10,7 @@
<hr> <hr>
<table class='table table-striped'> <table class='table table-striped'>
<col width='25'>
<tr> <tr>
<td></td> <td></td>
<td>{% trans "Title" %}</td> <td>{% trans "Title" %}</td>

View File

@ -2,7 +2,7 @@ from django.apps import AppConfig
from django.db.utils import OperationalError, ProgrammingError from django.db.utils import OperationalError, ProgrammingError
import os import os
import uuid
import yaml import yaml
@ -10,14 +10,19 @@ class CommonConfig(AppConfig):
name = 'common' name = 'common'
def ready(self): def ready(self):
""" Will be called when the Common app is first loaded """ """ Will be called when the Common app is first loaded """
self.populate_default_settings() self.populate_default_settings()
self.add_instance_name()
def populate_default_settings(self): def populate_default_settings(self):
""" Populate the default values for InvenTree key:value pairs. """ Populate the default values for InvenTree key:value pairs.
If a setting does not exist, it will be created. If a setting does not exist, it will be created.
""" """
# Import this here, rather than at the global-level,
# otherwise it is called all the time, and we don't want that,
# as the InvenTreeSetting model may have not been instantiated yet.
from .models import InvenTreeSetting from .models import InvenTreeSetting
here = os.path.dirname(os.path.abspath(__file__)) here = os.path.dirname(os.path.abspath(__file__))
@ -46,3 +51,30 @@ class CommonConfig(AppConfig):
except (OperationalError, ProgrammingError): except (OperationalError, ProgrammingError):
# Migrations have not yet been applied - table does not exist # Migrations have not yet been applied - table does not exist
break break
def add_instance_name(self):
"""
Check if an InstanceName has been defined for this database.
If not, create a random one!
"""
# See note above
from .models import InvenTreeSetting
try:
if not InvenTreeSetting.objects.filter(key='InstanceName').exists():
val = uuid.uuid4().hex
print("No 'InstanceName' found - generating random name '{n}'".format(n=val))
name = InvenTreeSetting(
key="InstanceName",
value=val,
description="Instance name for this InvenTree database installation."
)
name.save()
except (OperationalError, ProgrammingError):
# Migrations have not yet been applied - table does not exist
pass

View File

@ -4,6 +4,9 @@
# Note: The description strings provided here will be translatable, # Note: The description strings provided here will be translatable,
# so ensure that any translations are provided as appropriate. # so ensure that any translations are provided as appropriate.
# TODO: Update the formatting here to include logical separators e.g. double-underscore
# TODO: This is so when there are enough options, we will be able to display them as a tree
- key: 'part_ipn_regex' - key: 'part_ipn_regex'
default: '' default: ''
description: 'Format string for internal part number' description: 'Format string for internal part number'

View File

@ -43,6 +43,7 @@ InvenTree | {% trans "Company" %} - {{ company.name }}
</div> </div>
<div class="col-sm-6"> <div class="col-sm-6">
<table class="table"> <table class="table">
<col width='25'>
{% if company.website %} {% if company.website %}
<tr> <tr>
<td><span class='fas fa-link'></span></td> <td><span class='fas fa-link'></span></td>

View File

@ -9,14 +9,18 @@
<hr> <hr>
<table class='table table-striped'> <table class='table table-striped'>
<tr> <col width='25'>
<td>{% trans "Customer" %}</td> <col>
<td>{% include 'yesnolabel.html' with value=company.is_customer %}</td> <tr>
</tr> <td><span class='fas fa-user-tag'></span></td>
<tr> <td>{% trans "Customer" %}</td>
<td>{% trans "Supplier" %}</td> <td>{% include 'yesnolabel.html' with value=company.is_customer %}</td>
<td>{% include 'yesnolabel.html' with value=company.is_supplier %}</td> </tr>
</tr> <tr>
<td><span class='fas fa-industry'></span></td>
<td>{% trans "Supplier" %}</td>
<td>{% include 'yesnolabel.html' with value=company.is_supplier %}</td>
</tr>
</table> </table>
{% endblock %} {% endblock %}

View File

@ -60,6 +60,7 @@ InvenTree | {{ order }}
<div class='col-sm-6'> <div class='col-sm-6'>
<h4>{% trans "Purchase Order Details" %}</h4> <h4>{% trans "Purchase Order Details" %}</h4>
<table class='table'> <table class='table'>
<col width='25'>
<tr> <tr>
<td><span class='fas fa-industry'></span></td> <td><span class='fas fa-industry'></span></td>
<td>{% trans "Supplier" %}</td> <td>{% trans "Supplier" %}</td>

View File

@ -1,7 +1,7 @@
# Generated by Django 2.2.10 on 2020-04-04 12:38 # Generated by Django 2.2.10 on 2020-04-04 12:38
from django.db import migrations from django.db import migrations
from django.db.utils import OperationalError from django.db.utils import OperationalError, ProgrammingError
from part.models import Part from part.models import Part
from stdimage.utils import render_variations from stdimage.utils import render_variations
@ -17,8 +17,9 @@ def create_thumbnails(apps, schema_editor):
# Render thumbnail for each existing Part # Render thumbnail for each existing Part
if part.image: if part.image:
part.image.render_variations() part.image.render_variations()
except OperationalError: except (OperationalError, ProgrammingError):
print("Error - could not generate Part thumbnails") # Migrations have not yet been applied - table does not exist
print("Could not generate Part thumbnails")
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -33,6 +33,7 @@
{% if category %} {% if category %}
<h3>{% trans "Category Details" %}</h3> <h3>{% trans "Category Details" %}</h3>
<table class='table table-condensed table-striped'> <table class='table table-condensed table-striped'>
<col width='25'>
<tr> <tr>
<td><span class='fas fa-sitemap'></span></td> <td><span class='fas fa-sitemap'></span></td>
<td>{% trans "Category Path" %}</td> <td>{% trans "Category Path" %}</td>
@ -71,6 +72,7 @@
{% else %} {% else %}
<h3>{% trans "Category Details" %}</h3> <h3>{% trans "Category Details" %}</h3>
<table class='table table-striped table-condensed'> <table class='table table-striped table-condensed'>
<col width='25'>
<tr> <tr>
<td><span class='fas fa-sitemap'></span></td> <td><span class='fas fa-sitemap'></span></td>
<td>{% trans "Part Categories" %}</td> <td>{% trans "Part Categories" %}</td>

View File

@ -13,6 +13,7 @@
<div class='row'> <div class='row'>
<div class='col-sm-6'> <div class='col-sm-6'>
<table class='table table-striped'> <table class='table table-striped'>
<col width='25'>
<tr> <tr>
<td></td> <td></td>
<td><b>{% trans "Part name" %}</b></td> <td><b>{% trans "Part name" %}</b></td>

View File

@ -70,6 +70,7 @@
</div> </div>
</p> </p>
<table class='table table-condensed'> <table class='table table-condensed'>
<col width='25'>
{% if part.IPN %} {% if part.IPN %}
<tr> <tr>
<td></td> <td></td>

View File

@ -43,6 +43,12 @@ def part_allocation_count(build, part, *args, **kwargs):
return decimal2string(build.getAllocatedQuantity(part)) return decimal2string(build.getAllocatedQuantity(part))
@register.simple_tag()
def inventree_instance_name(*args, **kwargs):
""" Return the InstanceName associated with the current database """
return version.inventreeInstanceName()
@register.simple_tag() @register.simple_tag()
def inventree_version(*args, **kwargs): def inventree_version(*args, **kwargs):
""" Return InvenTree version string """ """ Return InvenTree version string """

View File

@ -73,6 +73,7 @@
<div class='row'> <div class='row'>
<div class='col-sm-6'> <div class='col-sm-6'>
<table class="table table-striped"> <table class="table table-striped">
<col width='25'>
<tr> <tr>
<td><span class='fas fa-shapes'></span></td> <td><span class='fas fa-shapes'></span></td>
<td>Part</td> <td>Part</td>

View File

@ -36,6 +36,7 @@
{% if location %} {% if location %}
<h3>{% trans "Location Details" %}</h3> <h3>{% trans "Location Details" %}</h3>
<table class='table table-striped table-condensed'> <table class='table table-striped table-condensed'>
<col width='25'>
<tr> <tr>
<td><span class='fas fa-sitemap'></span></td> <td><span class='fas fa-sitemap'></span></td>
<td>{% trans "Location Path" %}</td> <td>{% trans "Location Path" %}</td>
@ -60,6 +61,7 @@
{% else %} {% else %}
<h3>{% trans "Stock Details" %}</h3> <h3>{% trans "Stock Details" %}</h3>
<table class='table table-striped table-condensed'> <table class='table table-striped table-condensed'>
<col width='25'>
<tr> <tr>
<td><span class='fas fa-map-marker-alt'></span></td> <td><span class='fas fa-map-marker-alt'></span></td>
<td>{% trans "Stock Locations" %}</td> <td>{% trans "Stock Locations" %}</td>

View File

@ -24,10 +24,16 @@ InvenTree | Index
{% endblock %} {% endblock %}
{% block js_ready %} {% block js_ready %}
console.log("abcde?");
{{ block.super }} {{ block.super }}
$("#to-build-table").bootstrapTable(); //TODO: These calls to bootstrapTable() are failing, for some reason?
$("#to-order-table").bootstrapTable(); //$("#to-build-table").bootstrapTable();
$("#starred-parts-table").bootstrapTable(); //$("#to-order-table").bootstrapTable();
//$("#starred-parts-table").bootstrapTable();
console.log("Got to here...");
{% endblock %} {% endblock %}

View File

@ -10,35 +10,41 @@
<span aria-hidden="true">&times;</span> <span aria-hidden="true">&times;</span>
</button> </button>
<img src="{% static 'img/inventree.png' %}" height='60' style='float: left;' alt='Inventree Logo'> <img src="{% static 'img/inventree.png' %}" height='60' style='float: left;' alt='Inventree Logo'>
<h3>{% trans "InvenTree Version Information" %}</h3>
</div> </div>
<div class='modal-form-content'> <div class='modal-form-content'>
<div> <div>
<!--
-->
<h4>{% trans "InvenTree Version Information" %}</h4>
<table class='table table-striped table-condensed'> <table class='table table-striped table-condensed'>
<tr> <tr>
<td>{% trans "Version" %}</td><td><a href="https://github.com/inventree/InvenTree/releases">{% inventree_version %}</a></td> <td></td>
<td>{% trans "Instance Name" %}</td>
<td>{% inventree_instance_name %}</td>
</tr> </tr>
<tr> <tr>
<td><span class='fas fa-hashtag'></span></td>
<td>{% trans "InvenTree Version" %}</td><td><a href="https://github.com/inventree/InvenTree/releases">{% inventree_version %}</a></td>
</tr>
<tr>
<td><span class='fas fa-code-branch'></span></td>
<td>{% trans "Commit Hash" %}</td><td><a href="https://github.com/inventree/InvenTree/commit/{% inventree_commit_hash %}">{% inventree_commit_hash %}</a></td> <td>{% trans "Commit Hash" %}</td><td><a href="https://github.com/inventree/InvenTree/commit/{% inventree_commit_hash %}">{% inventree_commit_hash %}</a></td>
</tr> </tr>
<tr> <tr>
<td><span class='fas fa-calendar-alt'></span></td>
<td>{% trans "Commit Date" %}</td><td>{% inventree_commit_date %}</td> <td>{% trans "Commit Date" %}</td><td>{% inventree_commit_date %}</td>
</tr> </tr>
<tr> <tr>
<td colspan="2"></td> <td><span class='fas fa-book'></span></td>
</tr>
<tr>
<td>{% trans "InvenTree Documentation" %}</td> <td>{% trans "InvenTree Documentation" %}</td>
<td><a href="{% inventree_docs_url %}">{% inventree_docs_url %}</a></td> <td><a href="{% inventree_docs_url %}">{% inventree_docs_url %}</a></td>
</tr> </tr>
<tr> <tr>
<td><span class='fab fa-github'></span></td>
<td>{% trans "View Code on GitHub" %}</td><td><a href="{% inventree_github_url %}">{% inventree_github_url %}</a></td> <td>{% trans "View Code on GitHub" %}</td><td><a href="{% inventree_github_url %}">{% inventree_github_url %}</a></td>
</tr> </tr>
<tr> <tr>
<td></td> <td><span class='fas fa-exclamation-circle'></span></td>
<td><a href='https://github.com/inventree/InvenTree/issues'><button class='btn btn-default'>Submit Bug Report</button></a></td> <td>{% trans "Submit Bug Report" %}</td>
<td><a href='{% inventree_github_url %}/issues'>{% inventree_github_url %}/issues</a></td>
</tr> </tr>
</table> </table>

View File

@ -28,6 +28,7 @@
<meta name="theme-color" content="#ffffff"> <meta name="theme-color" content="#ffffff">
<!-- CSS --> <!-- CSS -->
<link rel="stylesheet" href="{% static 'fontawesome/css/brands.css' %}">
<link rel="stylesheet" href="{% static 'fontawesome/css/solid.css' %}"> <link rel="stylesheet" href="{% static 'fontawesome/css/solid.css' %}">
<link rel="stylesheet" href="{% static 'css/bootstrap_3.3.7_css_bootstrap.min.css' %}"> <link rel="stylesheet" href="{% static 'css/bootstrap_3.3.7_css_bootstrap.min.css' %}">
<link rel="stylesheet" href="{% static 'css/bootstrap-table.css' %}"> <link rel="stylesheet" href="{% static 'css/bootstrap-table.css' %}">
@ -108,6 +109,7 @@ InvenTree
<script type='text/javascript' src="{% static 'script/inventree/sidenav.js' %}"></script> <script type='text/javascript' src="{% static 'script/inventree/sidenav.js' %}"></script>
<script type='text/javascript' src="{% static 'fontawesome/js/solid.js' %}"></script> <script type='text/javascript' src="{% static 'fontawesome/js/solid.js' %}"></script>
<script type='text/javascript' src="{% static 'fontawesome/js/brands.js' %}"></script>
<script type='text/javascript' src="{% static 'fontawesome/js/fontawesome.js' %}"></script> <script type='text/javascript' src="{% static 'fontawesome/js/fontawesome.js' %}"></script>
{% block js_load %} {% block js_load %}

View File

@ -1,11 +1,11 @@
<table class='table table-striped table-condensed' id='{{ table_id }}'> <table class='table table-striped table-condensed' id='{{ table_id }}'>
<tr> <tr>
<th>Part</th> <th data-field='part' data-sortable='true' data-searchable='true'>Part</th>
<th>Description</th> <th data-field='part' data-sortable='true' data-searchable='true'>Description</th>
<th>In Stock</th> <th data-field='part' data-sortable='true' data-searchable='true'>In Stock</th>
<th>On Order</th> <th data-field='part' data-sortable='true' data-searchable='true'>On Order</th>
<th>Allocted</th> <th data-field='part' data-sortable='true' data-searchable='true'>Allocted</th>
<th>Net Stock</th> <th data-field='part' data-sortable='true' data-searchable='true'>Net Stock</th>
</tr> </tr>
{% for part in parts %} {% for part in parts %}
<tr> <tr>

View File

@ -7,22 +7,26 @@
<td colspan='2'><b>{% trans "Parts" %}</b></td> <td colspan='2'><b>{% trans "Parts" %}</b></td>
</tr> </tr>
<tr> <tr>
<td>{% trans "Parts" %}</td> <td><span class='fas fa-sitemap'></span></td>
<td>{{ part_count }}</td>
</tr>
<tr>
<td>{% trans "Part Categories" %}</td> <td>{% trans "Part Categories" %}</td>
<td>{{ part_cat_count }}</td> <td>{{ part_cat_count }}</td>
</tr> </tr>
<tr>
<td><span class='fas fa-shapes'></span></td>
<td>{% trans "Parts" %}</td>
<td>{{ part_count }}</td>
</tr>
<tr> <tr>
<td colspan="2"><b>{% trans "Stock Items" %}</b></td> <td colspan="2"><b>{% trans "Stock Items" %}</b></td>
</tr> </tr>
<tr> <tr>
<td>{% trans "Stock Items" %}</td> <td><span class='fas fa-map-marker-alt'></span></td>
<td>{{ stock_item_count }}</td>
</tr>
<tr>
<td>{% trans "Stock Locations" %}</td> <td>{% trans "Stock Locations" %}</td>
<td>{{ stock_loc_count }}</td> <td>{{ stock_loc_count }}</td>
</tr> </tr>
<tr>
<td><span class='fas fa-boxes'></span></td>
<td>{% trans "Stock Items" %}</td>
<td>{{ stock_item_count }}</td>
</tr>
</table> </table>