fix for history admin crashing when company is null
This commit is contained in:
@@ -9,7 +9,10 @@ class HistoryAdmin(admin.ModelAdmin):
|
|||||||
list_filter = ('company__company_name',)
|
list_filter = ('company__company_name',)
|
||||||
|
|
||||||
def company_name(self, instance):
|
def company_name(self, instance):
|
||||||
return instance.company.company_name
|
if instance.company and instance.company.company_name:
|
||||||
|
return instance.company.company_name
|
||||||
|
else:
|
||||||
|
return 'NULL'
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(models.HistorySync, HistoryAdmin)
|
admin.site.register(models.HistorySync, HistoryAdmin)
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ from rest_framework import status
|
|||||||
from companies.factories import CompanyFactory
|
from companies.factories import CompanyFactory
|
||||||
from products.factories import ProductFactory, ActiveProductFactory
|
from products.factories import ProductFactory, ActiveProductFactory
|
||||||
from products.models import Product
|
from products.models import Product
|
||||||
from products.utils import find_related_products_v3
|
# from products.utils import find_related_products_v3
|
||||||
|
|
||||||
from core.factories import CustomUserFactory
|
from core.factories import CustomUserFactory
|
||||||
from core.utils import get_tokens_for_user
|
from core.utils import get_tokens_for_user
|
||||||
@@ -1159,6 +1159,7 @@ class AdminProductViewSetTest(APITestCase):
|
|||||||
self.assertEquals(response.status_code, 204)
|
self.assertEquals(response.status_code, 204)
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
class FindRelatedProductsTest(APITestCase):
|
class FindRelatedProductsTest(APITestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@@ -1195,7 +1196,7 @@ class FindRelatedProductsTest(APITestCase):
|
|||||||
|
|
||||||
# assert result
|
# assert result
|
||||||
self.assertTrue(len(results) == len(expected_instances))
|
self.assertTrue(len(results) == len(expected_instances))
|
||||||
|
'''
|
||||||
|
|
||||||
class PurchaseEmailTest(APITestCase):
|
class PurchaseEmailTest(APITestCase):
|
||||||
|
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ def extract_search_filters(result_set):
|
|||||||
return filter_dict
|
return filter_dict
|
||||||
|
|
||||||
|
|
||||||
def find_related_products_v7(description, tags, attributes, category):
|
def get_related_products(description, tags, attributes, category):
|
||||||
products_qs = Product.objects.filter(
|
products_qs = Product.objects.filter(
|
||||||
description=description,
|
description=description,
|
||||||
tags__in=tags,
|
tags__in=tags,
|
||||||
@@ -94,7 +94,7 @@ def find_related_products_v7(description, tags, attributes, category):
|
|||||||
)[:6]
|
)[:6]
|
||||||
return products_qs
|
return products_qs
|
||||||
|
|
||||||
|
'''
|
||||||
def find_related_products_v3(keyword):
|
def find_related_products_v3(keyword):
|
||||||
"""
|
"""
|
||||||
Ranked product search
|
Ranked product search
|
||||||
@@ -111,9 +111,9 @@ def find_related_products_v3(keyword):
|
|||||||
).filter(rank__gt=0.05) # removed order_by because its lost in casting
|
).filter(rank__gt=0.05) # removed order_by because its lost in casting
|
||||||
|
|
||||||
return set(products_qs)
|
return set(products_qs)
|
||||||
|
'''
|
||||||
|
|
||||||
|
def ranked_product_search(keyword, shipping_cost=None, discount=None, category=None, tags=None, price_min=None,price_max=None):
|
||||||
def find_related_products_v6(keyword, shipping_cost=None, discount=None, category=None, tags=None, price_min=None,price_max=None):
|
|
||||||
"""
|
"""
|
||||||
Ranked product search
|
Ranked product search
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ from products.serializers import ProductSerializer, TagFilterSerializer, SearchR
|
|||||||
from companies.models import Company
|
from companies.models import Company
|
||||||
from stats.models import StatsLog
|
from stats.models import StatsLog
|
||||||
from back_latienda.permissions import IsCreator, IsSiteAdmin, ReadOnly
|
from back_latienda.permissions import IsCreator, IsSiteAdmin, ReadOnly
|
||||||
from .utils import extract_search_filters, find_related_products_v6, product_loader, find_related_products_v7
|
from .utils import extract_search_filters, ranked_product_search, product_loader, get_related_products
|
||||||
from utils.tag_serializers import TaggitSerializer
|
from utils.tag_serializers import TaggitSerializer
|
||||||
from utils.tag_filters import ProductTagFilter, ProductOrderFilter
|
from utils.tag_filters import ProductTagFilter, ProductOrderFilter
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ class ProductViewSet(viewsets.ModelViewSet):
|
|||||||
"""
|
"""
|
||||||
# TODO: find the most similar products
|
# TODO: find the most similar products
|
||||||
product = self.get_object()
|
product = self.get_object()
|
||||||
qs = find_related_products_v7(product.description, product.tags.all(), product.attributes.all(), product.category)
|
qs = get_related_products(product.description, product.tags.all(), product.attributes.all(), product.category)
|
||||||
serializer = self.serializer_class(qs, many=True)
|
serializer = self.serializer_class(qs, many=True)
|
||||||
return Response(data=serializer.data)
|
return Response(data=serializer.data)
|
||||||
|
|
||||||
@@ -195,7 +195,7 @@ def product_search(request):
|
|||||||
# split query string into single words
|
# split query string into single words
|
||||||
chunks = q.split(' ')
|
chunks = q.split(' ')
|
||||||
for chunk in chunks:
|
for chunk in chunks:
|
||||||
product_set, min_price, max_price = find_related_products_v6(chunk, shipping_cost, discount, category, tags, price_min, price_max)
|
product_set, min_price, max_price = ranked_product_search(chunk, shipping_cost, discount, category, tags, price_min, price_max)
|
||||||
# update price values
|
# update price values
|
||||||
if product_set:
|
if product_set:
|
||||||
if prices['min'] is None or min_price['price__min'] < prices['min']:
|
if prices['min'] is None or min_price['price__min'] < prices['min']:
|
||||||
|
|||||||
Reference in New Issue
Block a user