show recently added recipes in search
This commit is contained in:
parent
61d1528911
commit
fe3e611dd1
@ -2,7 +2,8 @@ from datetime import datetime, timedelta
|
||||
from functools import reduce
|
||||
|
||||
from django.contrib.postgres.search import TrigramSimilarity
|
||||
from django.db.models import Q
|
||||
from django.db.models import Q, Case, When, Value
|
||||
from django.forms import IntegerField
|
||||
|
||||
from cookbook.models import ViewLog
|
||||
from recipes import settings
|
||||
@ -23,7 +24,9 @@ def search_recipes(request, queryset, params):
|
||||
search_last_viewed = int(params.get('last_viewed', 0))
|
||||
|
||||
if search_last_viewed > 0:
|
||||
last_viewed_recipes = ViewLog.objects.filter(created_by=request.user, space=request.space, created_at__gte=datetime.now() - timedelta(days=14)).values_list('recipe__pk', flat=True).distinct()
|
||||
last_viewed_recipes = ViewLog.objects.filter(created_by=request.user, space=request.space,
|
||||
created_at__gte=datetime.now() - timedelta(days=14)).values_list(
|
||||
'recipe__pk', flat=True).distinct()
|
||||
|
||||
return queryset.filter(pk__in=list(set(last_viewed_recipes))[-search_last_viewed:])
|
||||
|
||||
@ -60,6 +63,10 @@ def search_recipes(request, queryset, params):
|
||||
if search_internal == 'true':
|
||||
queryset = queryset.filter(internal=True)
|
||||
|
||||
queryset = queryset.annotate(
|
||||
new_recipe=Case(When(created_at__gte=(datetime.now() - timedelta(days=7)), then=Value(100)),
|
||||
default=Value(0), )).order_by('-new_recipe', 'name')
|
||||
|
||||
if search_random == 'true':
|
||||
queryset = queryset.order_by("?")
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,5 +0,0 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"vue-cookies": "^1.7.4"
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@
|
||||
"axios": "^0.21.1",
|
||||
"bootstrap-vue": "^2.21.2",
|
||||
"core-js": "^3.6.5",
|
||||
"lodash": "^4.17.21",
|
||||
"moment": "^2.29.1",
|
||||
"vue": "^2.6.11",
|
||||
"vue-class-component": "^7.2.3",
|
||||
|
@ -13,8 +13,7 @@
|
||||
|
||||
|
||||
<b-input-group class="mt-3">
|
||||
<b-input class="form-control" v-model="search_input" @keyup="refreshData"
|
||||
v-bind:placeholder="$t('Search')"></b-input>
|
||||
<b-input class="form-control" v-model="search_input" v-bind:placeholder="$t('Search')"></b-input>
|
||||
<b-input-group-append>
|
||||
<b-button v-b-toggle.collapse_advanced_search variant="primary" class="shadow-none"><i
|
||||
class="fas fa-caret-down" v-if="!settings.advanced_search_visible"></i><i class="fas fa-caret-up"
|
||||
@ -224,6 +223,7 @@ import {BootstrapVue} from 'bootstrap-vue'
|
||||
|
||||
import 'bootstrap-vue/dist/bootstrap-vue.css'
|
||||
import moment from 'moment'
|
||||
import _debounce from 'lodash/debounce'
|
||||
|
||||
import VueCookies from 'vue-cookies'
|
||||
|
||||
@ -295,6 +295,9 @@ export default {
|
||||
'settings.recently_viewed': function () {
|
||||
this.loadRecentlyViewed()
|
||||
},
|
||||
search_input: _debounce(function () {
|
||||
this.refreshData()
|
||||
}, 300),
|
||||
},
|
||||
methods: {
|
||||
refreshData: function () {
|
||||
@ -344,7 +347,7 @@ export default {
|
||||
loadRecentlyViewed: function () {
|
||||
let apiClient = new ApiApiFactory()
|
||||
if (this.settings.recently_viewed > 0) {
|
||||
apiClient.listRecipes({query: {last_viewed: this.settings.recently_viewed}}).then(result => {
|
||||
apiClient.listRecipes({options: {query: {last_viewed: this.settings.recently_viewed}}}).then(result => {
|
||||
this.last_viewed_recipes = result.data.results
|
||||
})
|
||||
} else {
|
||||
|
@ -24,6 +24,7 @@
|
||||
{{ recipe.description }}
|
||||
<keywords :recipe="recipe" style="margin-top: 4px"></keywords>
|
||||
<b-badge pill variant="info" v-if="!recipe.internal">{{ $t('External') }}</b-badge>
|
||||
<b-badge pill variant="success" v-if="Date.parse(recipe.created_at) > new Date(Date.now() - (7 * (1000 * 60 * 60 * 24)))">{{ $t('New') }}</b-badge>
|
||||
</template>
|
||||
<template v-else>{{ meal_plan.note }}</template>
|
||||
</b-card-text>
|
||||
|
@ -37,6 +37,7 @@
|
||||
"Rating": "Rating",
|
||||
"Close": "Close",
|
||||
"Add": "Add",
|
||||
"New": "New",
|
||||
"Ingredients": "Ingredients",
|
||||
"min": "min",
|
||||
"Servings": "Servings",
|
||||
|
Loading…
Reference in New Issue
Block a user