mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add ReportAsset model
- Files which can be embedded into a report
This commit is contained in:
parent
b78fe88c26
commit
70c5b27d22
@ -72,6 +72,27 @@ if DEBUG:
|
|||||||
format='%(asctime)s %(levelname)s %(message)s',
|
format='%(asctime)s %(levelname)s %(message)s',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Web URL endpoint for served static files
|
||||||
|
STATIC_URL = '/static/'
|
||||||
|
|
||||||
|
# The filesystem location for served static files
|
||||||
|
STATIC_ROOT = os.path.abspath(CONFIG.get('static_root', os.path.join(BASE_DIR, 'static')))
|
||||||
|
|
||||||
|
STATICFILES_DIRS = [
|
||||||
|
os.path.join(BASE_DIR, 'InvenTree', 'static'),
|
||||||
|
]
|
||||||
|
|
||||||
|
# Web URL endpoint for served media files
|
||||||
|
MEDIA_URL = '/media/'
|
||||||
|
|
||||||
|
# The filesystem location for served static files
|
||||||
|
MEDIA_ROOT = os.path.abspath(CONFIG.get('media_root', os.path.join(BASE_DIR, 'media')))
|
||||||
|
|
||||||
|
if DEBUG:
|
||||||
|
print("InvenTree running in DEBUG mode")
|
||||||
|
print("MEDIA_ROOT:", MEDIA_ROOT)
|
||||||
|
print("STATIC_ROOT:", STATIC_ROOT)
|
||||||
|
|
||||||
# Does the user wish to use the sentry.io integration?
|
# Does the user wish to use the sentry.io integration?
|
||||||
sentry_opts = CONFIG.get('sentry', {})
|
sentry_opts = CONFIG.get('sentry', {})
|
||||||
|
|
||||||
@ -161,7 +182,11 @@ ROOT_URLCONF = 'InvenTree.urls'
|
|||||||
TEMPLATES = [
|
TEMPLATES = [
|
||||||
{
|
{
|
||||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||||
'DIRS': [os.path.join(BASE_DIR, 'templates')],
|
'DIRS': [
|
||||||
|
os.path.join(BASE_DIR, 'templates'),
|
||||||
|
# Allow templates in the reporting directory to be accessed
|
||||||
|
os.path.join(MEDIA_ROOT, 'report'),
|
||||||
|
],
|
||||||
'APP_DIRS': True,
|
'APP_DIRS': True,
|
||||||
'OPTIONS': {
|
'OPTIONS': {
|
||||||
'context_processors': [
|
'context_processors': [
|
||||||
@ -316,31 +341,6 @@ DATE_INPUT_FORMATS = [
|
|||||||
"%Y-%m-%d",
|
"%Y-%m-%d",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
# Static files (CSS, JavaScript, Images)
|
|
||||||
# https://docs.djangoproject.com/en/1.10/howto/static-files/
|
|
||||||
|
|
||||||
# Web URL endpoint for served static files
|
|
||||||
STATIC_URL = '/static/'
|
|
||||||
|
|
||||||
# The filesystem location for served static files
|
|
||||||
STATIC_ROOT = os.path.abspath(CONFIG.get('static_root', os.path.join(BASE_DIR, 'static')))
|
|
||||||
|
|
||||||
STATICFILES_DIRS = [
|
|
||||||
os.path.join(BASE_DIR, 'InvenTree', 'static'),
|
|
||||||
]
|
|
||||||
|
|
||||||
# Web URL endpoint for served media files
|
|
||||||
MEDIA_URL = '/media/'
|
|
||||||
|
|
||||||
# The filesystem location for served static files
|
|
||||||
MEDIA_ROOT = os.path.abspath(CONFIG.get('media_root', os.path.join(BASE_DIR, 'media')))
|
|
||||||
|
|
||||||
if DEBUG:
|
|
||||||
print("InvenTree running in DEBUG mode")
|
|
||||||
print("MEDIA_ROOT:", MEDIA_ROOT)
|
|
||||||
print("STATIC_ROOT:", STATIC_ROOT)
|
|
||||||
|
|
||||||
# crispy forms use the bootstrap templates
|
# crispy forms use the bootstrap templates
|
||||||
CRISPY_TEMPLATE_PACK = 'bootstrap3'
|
CRISPY_TEMPLATE_PACK = 'bootstrap3'
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
from .models import ReportTemplate
|
from .models import ReportTemplate, ReportAsset
|
||||||
|
|
||||||
|
|
||||||
class ReportTemplateAdmin(admin.ModelAdmin):
|
class ReportTemplateAdmin(admin.ModelAdmin):
|
||||||
@ -11,4 +11,10 @@ class ReportTemplateAdmin(admin.ModelAdmin):
|
|||||||
list_display = ('template', 'description')
|
list_display = ('template', 'description')
|
||||||
|
|
||||||
|
|
||||||
|
class ReportAssetAdmin(admin.ModelAdmin):
|
||||||
|
|
||||||
|
list_display = ('asset', 'description')
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(ReportTemplate, ReportTemplateAdmin)
|
admin.site.register(ReportTemplate, ReportTemplateAdmin)
|
||||||
|
admin.site.register(ReportAsset, ReportAssetAdmin)
|
||||||
|
22
InvenTree/report/migrations/0003_reportasset.py
Normal file
22
InvenTree/report/migrations/0003_reportasset.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# Generated by Django 3.0.5 on 2020-05-21 04:04
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import report.models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('report', '0002_auto_20200521_0350'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='ReportAsset',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('asset', models.FileField(help_text='Report asset file', upload_to=report.models.rename_asset)),
|
||||||
|
('description', models.CharField(help_text='Asset file description', max_length=250)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
@ -17,7 +17,7 @@ def rename_template(instance, filename):
|
|||||||
|
|
||||||
filename = os.path.basename(filename)
|
filename = os.path.basename(filename)
|
||||||
|
|
||||||
return os.path.join('report', 'template', filename)
|
return os.path.join('report', 'report_template', filename)
|
||||||
|
|
||||||
|
|
||||||
class ReportTemplate(models.Model):
|
class ReportTemplate(models.Model):
|
||||||
@ -35,3 +35,29 @@ class ReportTemplate(models.Model):
|
|||||||
)
|
)
|
||||||
|
|
||||||
description = models.CharField(max_length=250, help_text=_("Report template description"))
|
description = models.CharField(max_length=250, help_text=_("Report template description"))
|
||||||
|
|
||||||
|
|
||||||
|
def rename_asset(instance, filename):
|
||||||
|
|
||||||
|
filename = os.path.basename(filename)
|
||||||
|
|
||||||
|
return os.path.join('report', 'assets', filename)
|
||||||
|
|
||||||
|
|
||||||
|
class ReportAsset(models.Model):
|
||||||
|
"""
|
||||||
|
Asset file for use in report templates.
|
||||||
|
For example, an image to use in a header file.
|
||||||
|
Uploaded asset files appear in MEDIA_ROOT/report/assets,
|
||||||
|
and can be loaded in a template using the {% report_asset <filename> %} tag.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return os.path.basename(self.asset.name)
|
||||||
|
|
||||||
|
asset = models.FileField(
|
||||||
|
upload_to=rename_asset,
|
||||||
|
help_text=_("Report asset file"),
|
||||||
|
)
|
||||||
|
|
||||||
|
description = models.CharField(max_length=250, help_text=_("Asset file description"))
|
||||||
|
@ -15,6 +15,8 @@ InvenTree | {% trans "Stock Item" %} - {{ item }}
|
|||||||
{% block pre_content %}
|
{% block pre_content %}
|
||||||
{% include 'stock/loc_link.html' with location=item.location %}
|
{% include 'stock/loc_link.html' with location=item.location %}
|
||||||
|
|
||||||
|
{% include "report_template/test.html" with item=item %}
|
||||||
|
|
||||||
{% if item.hasRequiredTests and not item.passedAllRequiredTests %}
|
{% if item.hasRequiredTests and not item.passedAllRequiredTests %}
|
||||||
<div class='alert alert-block alert-danger'>
|
<div class='alert alert-block alert-danger'>
|
||||||
{% trans "This stock item has not passed all required tests" %}
|
{% trans "This stock item has not passed all required tests" %}
|
||||||
|
Loading…
Reference in New Issue
Block a user