fixed search facets and sub recipe
This commit is contained in:
parent
738387ccf0
commit
16d125a243
@ -51,7 +51,7 @@ def search_recipes(request, queryset, params):
|
|||||||
if search_new == 'true':
|
if search_new == 'true':
|
||||||
queryset = (
|
queryset = (
|
||||||
queryset.annotate(new_recipe=Case(
|
queryset.annotate(new_recipe=Case(
|
||||||
When(created_at__gte=(datetime.now() - timedelta(days=7)), then=('pk')), default=Value(0),))
|
When(created_at__gte=(datetime.now() - timedelta(days=7)), then=('pk')), default=Value(0), ))
|
||||||
)
|
)
|
||||||
orderby += ['-new_recipe']
|
orderby += ['-new_recipe']
|
||||||
|
|
||||||
@ -123,9 +123,9 @@ def search_recipes(request, queryset, params):
|
|||||||
|
|
||||||
# TODO add order by user settings - only do search rank and annotation if rank order is configured
|
# TODO add order by user settings - only do search rank and annotation if rank order is configured
|
||||||
search_rank = (
|
search_rank = (
|
||||||
SearchRank('name_search_vector', search_query, cover_density=True)
|
SearchRank('name_search_vector', search_query, cover_density=True)
|
||||||
+ SearchRank('desc_search_vector', search_query, cover_density=True)
|
+ SearchRank('desc_search_vector', search_query, cover_density=True)
|
||||||
+ SearchRank('steps__search_vector', search_query, cover_density=True)
|
+ SearchRank('steps__search_vector', search_query, cover_density=True)
|
||||||
)
|
)
|
||||||
queryset = queryset.filter(query_filter).annotate(rank=search_rank)
|
queryset = queryset.filter(query_filter).annotate(rank=search_rank)
|
||||||
orderby += ['-rank']
|
orderby += ['-rank']
|
||||||
@ -174,7 +174,6 @@ def search_recipes(request, queryset, params):
|
|||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_facet(qs, request):
|
def get_facet(qs, request):
|
||||||
# NOTE facet counts for tree models include self AND descendants
|
# NOTE facet counts for tree models include self AND descendants
|
||||||
facets = {}
|
facets = {}
|
||||||
@ -210,9 +209,9 @@ def get_facet(qs, request):
|
|||||||
# TODO add book facet
|
# TODO add book facet
|
||||||
facets['Books'] = []
|
facets['Books'] = []
|
||||||
facets['Recent'] = ViewLog.objects.filter(
|
facets['Recent'] = ViewLog.objects.filter(
|
||||||
created_by=request.user, space=request.space,
|
created_by=request.user, space=request.space,
|
||||||
created_at__gte=datetime.now() - timedelta(days=14) # TODO make days of recent recipe a setting
|
created_at__gte=datetime.now() - timedelta(days=14) # TODO make days of recent recipe a setting
|
||||||
).values_list('recipe__pk', flat=True)
|
).values_list('recipe__pk', flat=True)
|
||||||
return facets
|
return facets
|
||||||
|
|
||||||
|
|
||||||
|
@ -252,7 +252,6 @@
|
|||||||
select-label="{% trans 'Select' %}"
|
select-label="{% trans 'Select' %}"
|
||||||
:id="'id_step_' + step.id + '_recipe'"
|
:id="'id_step_' + step.id + '_recipe'"
|
||||||
:custom-label="opt => recipes.find(x => x.id == opt).name"
|
:custom-label="opt => recipes.find(x => x.id == opt).name"
|
||||||
|
|
||||||
:multiple="false"
|
:multiple="false"
|
||||||
:loading="recipes_loading"
|
:loading="recipes_loading"
|
||||||
@search-change="searchRecipes">
|
@search-change="searchRecipes">
|
||||||
@ -615,6 +614,13 @@
|
|||||||
this.$http.get("{% url 'api:recipe-detail' recipe.pk %}").then((response) => {
|
this.$http.get("{% url 'api:recipe-detail' recipe.pk %}").then((response) => {
|
||||||
this.recipe = response.data;
|
this.recipe = response.data;
|
||||||
this.loading = false
|
this.loading = false
|
||||||
|
|
||||||
|
//TODO workaround function until view is properly refactored, loads name of selected sub recipe so the input can find its label
|
||||||
|
this.recipe.steps.forEach(s => {
|
||||||
|
if (s.step_recipe != null) {
|
||||||
|
this.recipes.push(s.step_recipe_data)
|
||||||
|
}
|
||||||
|
})
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
this.loading = false
|
this.loading = false
|
||||||
console.log(err)
|
console.log(err)
|
||||||
|
@ -486,7 +486,7 @@ class RecipePagination(PageNumberPagination):
|
|||||||
max_page_size = 100
|
max_page_size = 100
|
||||||
|
|
||||||
def paginate_queryset(self, queryset, request, view=None):
|
def paginate_queryset(self, queryset, request, view=None):
|
||||||
self.facets = get_facet(queryset, request.query_params, request.space)
|
self.facets = get_facet(queryset, request)
|
||||||
return super().paginate_queryset(queryset, request, view)
|
return super().paginate_queryset(queryset, request, view)
|
||||||
|
|
||||||
def get_paginated_response(self, data):
|
def get_paginated_response(self, data):
|
||||||
|
@ -337,6 +337,7 @@ export default {
|
|||||||
this.$nextTick(function () {
|
this.$nextTick(function () {
|
||||||
if (this.$cookies.isKey(SETTINGS_COOKIE_NAME)) {
|
if (this.$cookies.isKey(SETTINGS_COOKIE_NAME)) {
|
||||||
this.settings = Object.assign({}, this.settings, this.$cookies.get(SETTINGS_COOKIE_NAME))
|
this.settings = Object.assign({}, this.settings, this.$cookies.get(SETTINGS_COOKIE_NAME))
|
||||||
|
this.refreshData(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
let urlParams = new URLSearchParams(window.location.search);
|
let urlParams = new URLSearchParams(window.location.search);
|
||||||
|
Loading…
Reference in New Issue
Block a user