2 Commits

Author SHA1 Message Date
ace
bc9a7d3832 Updated pyproject.toml for include the template files. 2023-10-01 09:01:55 +03:00
9715122c6c Removed the mistaken shop facet dependency. 2023-09-28 23:50:03 +03:00
2 changed files with 16 additions and 4 deletions

View File

@@ -20,3 +20,9 @@ classifiers = [
[project.urls] [project.urls]
"Homepage" = "https://git.vickys-corner.xyz/ace/starfields-drf-generics" "Homepage" = "https://git.vickys-corner.xyz/ace/starfields-drf-generics"
[options.packages.find]
where = starfields_drf_generics
[options.package_data]
templates.filters =
*.html

View File

@@ -2,7 +2,6 @@ from django_filters import rest_framework as filters
from django.contrib.postgres.search import TrigramSimilarity from django.contrib.postgres.search import TrigramSimilarity
from django.db.models.functions import Concat from django.db.models.functions import Concat
from django.db.models import CharField from django.db.models import CharField
from shop.models.product import Product, Facet
from rest_framework.filters import BaseFilterBackend from rest_framework.filters import BaseFilterBackend
import operator import operator
from django.template import loader from django.template import loader
@@ -216,13 +215,20 @@ class FacetFilter(BaseFilterBackend):
def assign_view_facets(self, request, view): def assign_view_facets(self, request, view):
if not hasattr(view, 'facets'): if not hasattr(view, 'facets'):
if hasattr(view, 'facet_class'):
self.facet_class = self.get_facet_class(view, request)
assert self.facet_class is not None, (
f"{view.__class__.__name__} should include a `facet_class` attribute"
)
if view.category: if view.category:
if view.category.tn_ancestors_pks: if view.category.tn_ancestors_pks:
view.facets = Facet.objects.filter(Q(category__id=view.category.id) | Q(category__id__in=view.category.tn_ancestors_pks.split(','))).prefetch_related('facet_tags') view.facets = self.facet_class.objects.filter(Q(category__id=view.category.id) | Q(category__id__in=view.category.tn_ancestors_pks.split(','))).prefetch_related('facet_tags')
else: else:
view.facets = Facet.objects.filter(category__id=view.category.id).prefetch_related('facet_tags') view.facets = self.facet_class.objects.filter(category__id=view.category.id).prefetch_related('facet_tags')
else: else:
view.facets = Facet.objects.filter(category__tn_level=1).prefetch_related('facet_tags') view.facets = self.facet_class.objects.filter(category__tn_level=1).prefetch_related('facet_tags')
def get_filters_dict(self, request, view): def get_filters_dict(self, request, view):
""" """