mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Made changes that resemble PR #4050 to the part import wizard to make the correct form show. Added option to download a part import template file. Increased the number of allowable formfield because the importer creates a lot of table fields when importing multiple parts at once.
38 lines
928 B
Python
38 lines
928 B
Python
"""Functionality for Part import template.
|
|
|
|
Primarily Part import tools.
|
|
"""
|
|
|
|
from InvenTree.helpers import DownloadFile, GetExportFormats
|
|
|
|
from .admin import PartImportResource
|
|
from .models import Part
|
|
|
|
|
|
def IsValidPartFormat(fmt):
|
|
"""Test if a file format specifier is in the valid list of part import template file formats."""
|
|
return fmt.strip().lower() in GetExportFormats()
|
|
|
|
|
|
def MakePartTemplate(fmt):
|
|
"""Generate a part import template file (for user download)."""
|
|
fmt = fmt.strip().lower()
|
|
|
|
if not IsValidPartFormat(fmt):
|
|
fmt = 'csv'
|
|
|
|
# Create an "empty" queryset, essentially.
|
|
# This will then export just the row headers!
|
|
query = Part.objects.filter(pk=None)
|
|
|
|
dataset = PartImportResource().export(
|
|
queryset=query,
|
|
importing=True
|
|
)
|
|
|
|
data = dataset.export(fmt)
|
|
|
|
filename = 'InvenTree_Part_Template.' + fmt
|
|
|
|
return DownloadFile(data, filename)
|