history admin dropdown for admin
This commit is contained in:
@@ -14,7 +14,6 @@ from rest_framework import status
|
||||
from companies.factories import CompanyFactory
|
||||
from products.factories import ProductFactory, ActiveProductFactory
|
||||
from products.models import Product
|
||||
# from products.utils import find_related_products_v3
|
||||
|
||||
from core.factories import CustomUserFactory
|
||||
from core.utils import get_tokens_for_user
|
||||
@@ -1159,45 +1158,6 @@ class AdminProductViewSetTest(APITestCase):
|
||||
self.assertEquals(response.status_code, 204)
|
||||
|
||||
|
||||
'''
|
||||
class FindRelatedProductsTest(APITestCase):
|
||||
|
||||
def setUp(self):
|
||||
"""Tests setup
|
||||
"""
|
||||
self.factory = ActiveProductFactory
|
||||
self.model = Product
|
||||
# clear table
|
||||
self.model.objects.all().delete()
|
||||
|
||||
def test_v3_find_by_tags(self):
|
||||
# create tagged product
|
||||
tag = 'cool'
|
||||
expected_instances = [
|
||||
self.factory(tags=tag),
|
||||
self.factory(tags=f'{tag} hat'),
|
||||
self.factory(tags=f'temperatures/{tag}'),
|
||||
self.factory(tags=f'temperatures/{tag}, body/hot'),
|
||||
self.factory(tags=f'temperatures/{tag}, hats/{tag}'),
|
||||
# multiple hits
|
||||
self.factory(tags=tag, attributes=tag),
|
||||
self.factory(tags=tag, attributes=tag, category=tag),
|
||||
self.factory(tags=tag, attributes=tag, category=tag, name=tag),
|
||||
self.factory(tags=tag, attributes=tag, category=tag, name=tag, description=tag),
|
||||
]
|
||||
|
||||
unexpected_instances = [
|
||||
self.factory(tags="notcool"), # shouldn't catch it
|
||||
self.factory(tags="azules"),
|
||||
]
|
||||
|
||||
# searh for it
|
||||
results = find_related_products_v3(tag)
|
||||
|
||||
# assert result
|
||||
self.assertTrue(len(results) == len(expected_instances))
|
||||
'''
|
||||
|
||||
class PurchaseEmailTest(APITestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
||||
@@ -87,31 +87,13 @@ def extract_search_filters(result_set):
|
||||
|
||||
def get_related_products(description, tags, attributes, category):
|
||||
products_qs = Product.objects.filter(
|
||||
description=description,
|
||||
tags__in=tags,
|
||||
attributes__in=attributes,
|
||||
category=category
|
||||
)[:6]
|
||||
Q(description=description) |
|
||||
Q(tags__in=tags) |
|
||||
Q(attributes__in=attributes) |
|
||||
Q(category=category)
|
||||
)[:10]
|
||||
return products_qs
|
||||
|
||||
'''
|
||||
def find_related_products_v3(keyword):
|
||||
"""
|
||||
Ranked product search
|
||||
|
||||
SearchVectors for the fields
|
||||
SearchQuery for the value
|
||||
SearchRank for relevancy scoring and ranking
|
||||
"""
|
||||
vector = SearchVector('name') + SearchVector('description') + SearchVector('tags__label') + SearchVector('attributes__label') + SearchVector('category__name')
|
||||
query = SearchQuery(keyword)
|
||||
|
||||
products_qs = Product.objects.annotate(
|
||||
rank=SearchRank(vector, query)
|
||||
).filter(rank__gt=0.05) # removed order_by because its lost in casting
|
||||
|
||||
return set(products_qs)
|
||||
'''
|
||||
|
||||
def ranked_product_search(keyword, shipping_cost=None, discount=None, category=None, tags=None, price_min=None,price_max=None):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user