remove unused function

This commit is contained in:
Oliver Walters 2021-08-05 00:25:47 +10:00
parent aa4ed9feb0
commit dd78464a74
3 changed files with 2 additions and 61 deletions

View File

@ -235,57 +235,6 @@ def rename_part_image(instance, filename):
return os.path.join(base, fname)
def match_part_names(match, threshold=80, reverse=True, compare_length=False):
""" Return a list of parts whose name matches the search term using fuzzy search.
Args:
match: Term to match against
threshold: Match percentage that must be exceeded (default = 65)
reverse: Ordering for search results (default = True - highest match is first)
compare_length: Include string length checks
Returns:
A sorted dict where each element contains the following key:value pairs:
- 'part' : The matched part
- 'ratio' : The matched ratio
"""
match = str(match).strip().lower()
if len(match) == 0:
return []
parts = Part.objects.all()
matches = []
for part in parts:
compare = str(part.name).strip().lower()
if len(compare) == 0:
continue
ratio = fuzz.partial_token_sort_ratio(compare, match)
if compare_length:
# Also employ primitive length comparison
# TODO - Improve this somewhat...
l_min = min(len(match), len(compare))
l_max = max(len(match), len(compare))
ratio *= (l_min / l_max)
if ratio >= threshold:
matches.append({
'part': part,
'ratio': round(ratio, 1)
})
matches = sorted(matches, key=lambda item: item['ratio'], reverse=reverse)
return matches
class PartManager(TreeManager):
"""
Defines a custom object manager for the Part model.

View File

@ -12,7 +12,7 @@ from django.core.exceptions import ValidationError
import os
from .models import Part, PartCategory, PartTestTemplate
from .models import rename_part_image, match_part_names
from .models import rename_part_image
from .templatetags import inventree_extras
import part.settings
@ -163,12 +163,6 @@ class PartTest(TestCase):
def test_copy(self):
self.r2.deep_copy(self.r1, image=True, bom=True)
def test_match_names(self):
matches = match_part_names('M2x5 LPHS')
self.assertTrue(len(matches) > 0)
def test_sell_pricing(self):
# check that the sell pricebreaks were loaded
self.assertTrue(self.r1.has_price_breaks)

View File

@ -14,8 +14,7 @@ from django.shortcuts import HttpResponseRedirect
from django.utils.translation import gettext_lazy as _
from django.urls import reverse
from django.views.generic import DetailView, ListView
from django.forms.models import model_to_dict
from django.forms import HiddenInput, CheckboxInput
from django.forms import HiddenInput
from django.conf import settings
from django.contrib import messages
@ -35,7 +34,6 @@ from .models import PartCategory, Part, PartRelated
from .models import PartParameterTemplate
from .models import PartCategoryParameterTemplate
from .models import BomItem
from .models import match_part_names
from .models import PartSellPriceBreak, PartInternalPriceBreak
from common.models import InvenTreeSetting