merge resolution
This commit is contained in:
@@ -28,7 +28,7 @@ from history.models import HistorySync
|
||||
from back_latienda.permissions import IsCreator
|
||||
from .utils import extract_search_filters, find_related_products_v3, find_related_products_v6
|
||||
from utils.tag_serializers import TaggitSerializer
|
||||
from utils.tag_filters import ProductTagFilter
|
||||
from utils.tag_filters import ProductTagFilter, ProductOrderFilter
|
||||
|
||||
|
||||
logging.basicConfig(
|
||||
@@ -40,21 +40,11 @@ logging.basicConfig(
|
||||
|
||||
|
||||
class ProductViewSet(viewsets.ModelViewSet):
|
||||
# queryset = Product.objects.all()
|
||||
queryset = Product.objects.all().order_by('-created')
|
||||
serializer_class = ProductSerializer
|
||||
permission_classes = [IsAuthenticatedOrReadOnly, IsCreator]
|
||||
filter_backends = [DjangoFilterBackend, OrderingFilter]
|
||||
filterset_class = ProductTagFilter
|
||||
filterset_fields = ['name', 'tags', 'category', 'attributes', 'company', 'created']
|
||||
# TODO: figure out why cant use filterset for company filter
|
||||
def get_queryset(self):
|
||||
try:
|
||||
company_id = self.request.GET.get('company')
|
||||
company_id = int(company_id)
|
||||
queryset = Product.objects.filter(company__id=company_id)
|
||||
except:
|
||||
queryset = Product.objects.all()
|
||||
return queryset
|
||||
|
||||
def perform_create(self, serializer):
|
||||
serializer.save(creator=self.request.user)
|
||||
@@ -159,7 +149,7 @@ def product_search(request):
|
||||
Takes a string of data, return relevant products
|
||||
|
||||
Params:
|
||||
- query_string: used for search [MANDATORY]
|
||||
- q: used for search [MANDATORY]
|
||||
- limit: max number of returned instances [OPTIONAL]
|
||||
- offset: where to start counting results [OPTIONAL]
|
||||
- shipping_cost: true/false
|
||||
@@ -168,7 +158,7 @@ def product_search(request):
|
||||
- tags: string
|
||||
"""
|
||||
# capture query params
|
||||
query_string = request.GET.get('query_string', None)
|
||||
q = request.GET.get('q', None)
|
||||
limit = request.GET.get('limit', None)
|
||||
offset = request.GET.get('offset', None)
|
||||
shipping_cost = request.GET.get('shipping_cost', None)
|
||||
@@ -192,9 +182,9 @@ def product_search(request):
|
||||
price_min = request.GET.get('price_min', None)
|
||||
price_max = request.GET.get('price_max', None)
|
||||
|
||||
if query_string is None:
|
||||
if q is None:
|
||||
return Response({"errors": {"details": "No query string to parse"}})
|
||||
elif query_string is '':
|
||||
elif q is '':
|
||||
# return everything
|
||||
serializer = ProductSerializer(Product.objects.all(), many=True)
|
||||
products = serializer.data
|
||||
@@ -205,7 +195,7 @@ def product_search(request):
|
||||
result_set = set()
|
||||
|
||||
# split query string into single words
|
||||
chunks = query_string.split(' ')
|
||||
chunks = q.split(' ')
|
||||
for chunk in chunks:
|
||||
product_set = find_related_products_v6(chunk, shipping_cost, discount, category, tags, price_min, price_max)
|
||||
# add to result set
|
||||
|
||||
Reference in New Issue
Block a user