mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-16 20:15:44 +00:00
update the remaining docstrings
This commit is contained in:
@ -1,6 +1,4 @@
|
||||
"""
|
||||
Files management tools.
|
||||
"""
|
||||
"""Files management tools."""
|
||||
|
||||
import os
|
||||
|
||||
@ -12,7 +10,7 @@ from rapidfuzz import fuzz
|
||||
|
||||
|
||||
class FileManager:
|
||||
""" Class for managing an uploaded file """
|
||||
"""Class for managing an uploaded file."""
|
||||
|
||||
name = ''
|
||||
|
||||
@ -32,8 +30,7 @@ class FileManager:
|
||||
HEADERS = []
|
||||
|
||||
def __init__(self, file, name=None):
|
||||
""" Initialize the FileManager class with a user-uploaded file object """
|
||||
|
||||
"""Initialize the FileManager class with a user-uploaded file object."""
|
||||
# Set name
|
||||
if name:
|
||||
self.name = name
|
||||
@ -46,8 +43,7 @@ class FileManager:
|
||||
|
||||
@classmethod
|
||||
def validate(cls, file):
|
||||
""" Validate file extension and data """
|
||||
|
||||
"""Validate file extension and data."""
|
||||
cleaned_data = None
|
||||
|
||||
ext = os.path.splitext(file.name)[-1].lower().replace('.', '')
|
||||
@ -79,21 +75,15 @@ class FileManager:
|
||||
return cleaned_data
|
||||
|
||||
def process(self, file):
|
||||
""" Process file """
|
||||
|
||||
"""Process file."""
|
||||
self.data = self.__class__.validate(file)
|
||||
|
||||
def update_headers(self):
|
||||
""" Update headers """
|
||||
|
||||
"""Update headers."""
|
||||
self.HEADERS = self.REQUIRED_HEADERS + self.ITEM_MATCH_HEADERS + self.OPTIONAL_MATCH_HEADERS + self.OPTIONAL_HEADERS
|
||||
|
||||
def setup(self):
|
||||
"""
|
||||
Setup headers
|
||||
should be overriden in usage to set the Different Headers
|
||||
"""
|
||||
|
||||
"""Setup headers should be overriden in usage to set the Different Headers."""
|
||||
if not self.name:
|
||||
return
|
||||
|
||||
@ -101,14 +91,12 @@ class FileManager:
|
||||
self.update_headers()
|
||||
|
||||
def guess_header(self, header, threshold=80):
|
||||
"""
|
||||
Try to match a header (from the file) to a list of known headers
|
||||
"""Try to match a header (from the file) to a list of known headers.
|
||||
|
||||
Args:
|
||||
header - Header name to look for
|
||||
threshold - Match threshold for fuzzy search
|
||||
"""
|
||||
|
||||
# Replace null values with empty string
|
||||
if header is None:
|
||||
header = ''
|
||||
@ -143,7 +131,7 @@ class FileManager:
|
||||
return None
|
||||
|
||||
def columns(self):
|
||||
""" Return a list of headers for the thingy """
|
||||
"""Return a list of headers for the thingy."""
|
||||
headers = []
|
||||
|
||||
for header in self.data.headers:
|
||||
@ -176,15 +164,14 @@ class FileManager:
|
||||
return len(self.data.headers)
|
||||
|
||||
def row_count(self):
|
||||
""" Return the number of rows in the file. """
|
||||
|
||||
"""Return the number of rows in the file."""
|
||||
if self.data is None:
|
||||
return 0
|
||||
|
||||
return len(self.data)
|
||||
|
||||
def rows(self):
|
||||
""" Return a list of all rows """
|
||||
"""Return a list of all rows."""
|
||||
rows = []
|
||||
|
||||
for i in range(self.row_count()):
|
||||
@ -221,15 +208,14 @@ class FileManager:
|
||||
return rows
|
||||
|
||||
def get_row_data(self, index):
|
||||
""" Retrieve row data at a particular index """
|
||||
"""Retrieve row data at a particular index."""
|
||||
if self.data is None or index >= len(self.data):
|
||||
return None
|
||||
|
||||
return self.data[index]
|
||||
|
||||
def get_row_dict(self, index):
|
||||
""" Retrieve a dict object representing the data row at a particular offset """
|
||||
|
||||
"""Retrieve a dict object representing the data row at a particular offset."""
|
||||
if self.data is None or index >= len(self.data):
|
||||
return None
|
||||
|
||||
|
Reference in New Issue
Block a user