2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-18 13:05:42 +00:00

Refactor template helpers for displaying uploaded images (#3377)

* Refactor template helpers for displaying uploaded images

* Unit test for asset tag

* Unit tests for 'uploaded_image' tag

* Add simple tests for part_image and company_image functions

* Unit test for barcode constructor

* Unit tests for qrcode

* Refactor the 'company_logo.png' to be a new template tag

- Add unit tests

* Adds a new field to the report asset model

- Unique key which can be used to identify particular assets
- e.g. company logo

* Refactor logo image tags

- Make use of existing CUSTOM_LOGO setting
- Adds a "logo_image" template tag for reports

* Remove previous migration - strategy no longer required
This commit is contained in:
Oliver
2022-07-22 12:01:56 +10:00
committed by GitHub
parent 2bc8556993
commit d2ab6b012d
10 changed files with 312 additions and 83 deletions

View File

@ -7,8 +7,7 @@ from datetime import date, datetime
from django import template
from django.conf import settings as djangosettings
from django.core.files.storage import default_storage
from django.templatetags.static import StaticNode, static
from django.templatetags.static import StaticNode
from django.urls import reverse
from django.utils.html import format_html
from django.utils.safestring import mark_safe
@ -174,6 +173,16 @@ def inventree_title(*args, **kwargs):
return version.inventreeInstanceTitle()
@register.simple_tag()
def inventree_logo(**kwargs):
"""Return the InvenTree logo, *or* a custom logo if the user has uploaded one.
Returns a path to an image file, which can be rendered in the web interface
"""
return InvenTree.helpers.getLogoImage(**kwargs)
@register.simple_tag()
def inventree_base_url(*args, **kwargs):
"""Return the INVENTREE_BASE_URL setting."""
@ -473,14 +482,6 @@ def inventree_customize(reference, *args, **kwargs):
return djangosettings.CUSTOMIZE.get(reference, '')
@register.simple_tag()
def inventree_logo(*args, **kwargs):
"""Return the path to the logo-file."""
if settings.CUSTOM_LOGO:
return default_storage.url(settings.CUSTOM_LOGO)
return static('img/inventree.png')
class I18nStaticNode(StaticNode):
"""Custom StaticNode.