Add version related tags

- Docs URL points to correct documentation version
- Display if we are in "development" version
This commit is contained in:
Oliver Walters 2021-09-12 23:13:55 +10:00
parent 695370c8d7
commit 06c03039da
3 changed files with 73 additions and 21 deletions

View File

@ -70,7 +70,7 @@ def inventreeInstanceTitle():
def inventreeVersion():
""" Returns the InvenTree version string """
return INVENTREE_SW_VERSION
return INVENTREE_SW_VERSION.lower().strip()
def inventreeVersionTuple(version=None):
@ -84,6 +84,33 @@ def inventreeVersionTuple(version=None):
return [int(g) for g in match.groups()]
def isInvenTreeDevelopmentVersion():
"""
Return True if current InvenTree version is a "development" version
"""
print("is dev?", inventreeVersion())
return inventreeVersion().endswith('dev')
def inventreeDocsVersion():
"""
Return the version string matching the latest documentation.
Development -> "latest"
Release -> "major.minor"
"""
if isInvenTreeDevelopmentVersion():
return "latest"
else:
major, minor, patch = inventreeVersionTuple()
return f"{major}.{minor}"
def isInvenTreeUpToDate():
"""
Test if the InvenTree instance is "up to date" with the latest version.

View File

@ -136,6 +136,21 @@ def inventree_version(*args, **kwargs):
return version.inventreeVersion()
@register.simple_tag()
def inventree_is_development(*args, **kwargs):
return version.isInvenTreeDevelopmentVersion()
@register.simple_tag()
def inventree_is_release(*args, **kwargs):
return not version.isInvenTreeDevelopmentVersion()
@register.simple_tag()
def inventree_docs_version(*args, **kwargs):
return version.inventreeDocsVersion()
@register.simple_tag()
def inventree_api_version(*args, **kwargs):
""" Return InvenTree API version """
@ -169,7 +184,10 @@ def inventree_github_url(*args, **kwargs):
@register.simple_tag()
def inventree_docs_url(*args, **kwargs):
""" Return URL for InvenTree documenation site """
return "https://inventree.readthedocs.io/"
tag = version.inventreeDocsVersion()
return f"https://inventree.readthedocs.io/en/{tag}"
@register.simple_tag()

View File

@ -22,13 +22,39 @@
<td>{% trans "InvenTree Version" %}</td>
<td>
<a href="https://github.com/inventree/InvenTree/releases">{% inventree_version %}</a>{% include "clip.html" %}
{% inventree_is_development as dev %}
{% if dev %}
<span class='label label-blue float-right'>{% trans "Development Version" %}</span>
{% else %}
{% if up_to_date %}
<span class='label label-green float-right'>{% trans "Up to Date" %}</span>
{% else %}
<span class='label label-red float-right'>{% trans "Update Available" %}</span>
{% endif %}
{% endif %}
</td>
</tr>
{% if dev %}
{% inventree_commit_hash as hash %}
{% if hash %}
<tr>
<td><span class='fas fa-code-branch'></span></td>
<td>{% trans "Commit Hash" %}</td><td>{{ hash }}{% include "clip.html" %}</td>
</tr>
{% endif %}
{% inventree_commit_date as commit_date %}
{% if commit_date %}
<tr>
<td><span class='fas fa-calendar-alt'></span></td>
<td>{% trans "Commit Date" %}</td><td>{{ commit_date }}{% include "clip.html" %}</td>
</tr>
{% endif %}
{% endif %}
<tr>
<td><span class='fas fa-book'></span></td>
<td>{% trans "InvenTree Documentation" %}</td>
<td><a href="{% inventree_docs_url %}">{% inventree_docs_url %}</a></td>
</tr>
<tr>
<td><span class='fas fa-code'></span></td>
<td>{% trans "API Version" %}</td>
@ -44,25 +70,6 @@
<td>{% trans "Django Version" %}</td>
<td><a href="https://www.djangoproject.com/">{% django_version %}</a>{% include "clip.html" %}</td>
</tr>
{% inventree_commit_hash as hash %}
{% if hash %}
<tr>
<td><span class='fas fa-code-branch'></span></td>
<td>{% trans "Commit Hash" %}</td><td>{{ hash }}{% include "clip.html" %}</td>
</tr>
{% endif %}
{% inventree_commit_date as commit_date %}
{% if commit_date %}
<tr>
<td><span class='fas fa-calendar-alt'></span></td>
<td>{% trans "Commit Date" %}</td><td>{{ commit_date }}{% include "clip.html" %}</td>
</tr>
{% endif %}
<tr>
<td><span class='fas fa-book'></span></td>
<td>{% trans "InvenTree Documentation" %}</td>
<td><a href="{% inventree_docs_url %}">{% inventree_docs_url %}</a></td>
</tr>
<tr>
<td><span class='fab fa-github'></span></td>
<td>{% trans "View Code on GitHub" %}</td>