mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Simplify report snippet class definition
This commit is contained in:
parent
a025b7239d
commit
6ebebe03d4
@ -6,16 +6,16 @@ from django.contrib import admin
|
||||
from .models import ReportSnippet, TestReport, ReportAsset
|
||||
|
||||
|
||||
class ReportSnippetAdmin(admin.ModelAdmin):
|
||||
|
||||
list_display = ('name', 'description', 'template')
|
||||
|
||||
|
||||
class ReportTemplateAdmin(admin.ModelAdmin):
|
||||
|
||||
list_display = ('name', 'description', 'template', 'filters', 'enabled')
|
||||
|
||||
|
||||
class ReportSnippetAdmin(admin.ModelAdmin):
|
||||
|
||||
list_display = ('id', 'snippet', 'description')
|
||||
|
||||
|
||||
class ReportAssetAdmin(admin.ModelAdmin):
|
||||
|
||||
list_display = ('id', 'asset', 'description')
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Generated by Django 3.0.7 on 2021-02-03 05:57
|
||||
# Generated by Django 3.0.7 on 2021-02-04 04:37
|
||||
|
||||
import django.core.validators
|
||||
from django.db import migrations, models
|
||||
@ -16,12 +16,8 @@ class Migration(migrations.Migration):
|
||||
name='ReportSnippet',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(help_text='Template name', max_length=100, unique=True, verbose_name='Name')),
|
||||
('template', models.FileField(help_text='Report template file', upload_to=report.models.rename_template, validators=[django.core.validators.FileExtensionValidator(allowed_extensions=['html', 'htm', 'tex'])], verbose_name='Template')),
|
||||
('description', models.CharField(help_text='Report template description', max_length=250, verbose_name='Description')),
|
||||
('snippet', models.FileField(help_text='Report snippet file', upload_to=report.models.rename_snippet, validators=[django.core.validators.FileExtensionValidator(allowed_extensions=['html', 'htm'])])),
|
||||
('description', models.CharField(help_text='Snippet file description', max_length=250)),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
]
|
||||
|
@ -135,18 +135,6 @@ class ReportBase(models.Model):
|
||||
)
|
||||
|
||||
|
||||
class ReportSnippet(ReportBase):
|
||||
"""
|
||||
Report template 'snippet' which can be used to make templates
|
||||
that can then be included in other reports.
|
||||
|
||||
Useful for 'common' template actions, sub-templates, etc
|
||||
"""
|
||||
|
||||
def getSubdir(self):
|
||||
return ""
|
||||
|
||||
|
||||
class ReportTemplateBase(ReportBase):
|
||||
"""
|
||||
Reporting template model.
|
||||
@ -264,6 +252,30 @@ class TestReport(ReportTemplateBase):
|
||||
}
|
||||
|
||||
|
||||
def rename_snippet(instance, filename):
|
||||
|
||||
filename = os.path.basename(filename)
|
||||
|
||||
return os.path.join('report', 'snippets', filename)
|
||||
|
||||
|
||||
class ReportSnippet(models.Model):
|
||||
"""
|
||||
Report template 'snippet' which can be used to make templates
|
||||
that can then be included in other reports.
|
||||
|
||||
Useful for 'common' template actions, sub-templates, etc
|
||||
"""
|
||||
|
||||
snippet = models.FileField(
|
||||
upload_to=rename_snippet,
|
||||
help_text=_('Report snippet file'),
|
||||
validators=[FileExtensionValidator(allowed_extensions=['html', 'htm'])],
|
||||
)
|
||||
|
||||
description = models.CharField(max_length=250, help_text=_("Snippet file description"))
|
||||
|
||||
|
||||
def rename_asset(instance, filename):
|
||||
|
||||
filename = os.path.basename(filename)
|
||||
|
Loading…
Reference in New Issue
Block a user