search view fixes/updates

This commit is contained in:
vabene1111 2021-05-01 22:16:29 +02:00
parent 0a99791021
commit aafbc497cc
6 changed files with 22 additions and 17 deletions

View File

@ -1,3 +1,4 @@
from datetime import datetime, timedelta
from functools import reduce
from django.contrib.postgres.search import TrigramSimilarity
@ -22,10 +23,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).values_list('recipe__pk', flat=True).distinct()
# TODO filter by created by in last two weeks and re add limit to recipe selection (after reversing the order)
# Distinct does not work with order by
return queryset.filter(pk__in=list(set(last_viewed_recipes)))
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:])
if settings.DATABASES['default']['ENGINE'] in ['django.db.backends.postgresql_psycopg2',
'django.db.backends.postgresql']:

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

View File

@ -42,16 +42,22 @@
{{ $t('Reset_Search') }}
</button>
</div>
<div class="col-md-3" style="position: relative; margin-top: 1vh">
<div class="col-md-2" style="position: relative; margin-top: 1vh">
<b-form-checkbox v-model="search_internal" name="check-button" @change="refreshData"
class="shadow-none"
style="position:relative;top: 50%; transform: translateY(-50%);" switch>
{{ $t('show_only_internal') }}
</b-form-checkbox>
</div>
<div class="col-md-1" style="position: relative; margin-top: 1vh">
<button id="id_settings_button" class="btn btn-primary btn-block"><i class="fas fa-cog"></i></button>
</div>
</div>
<button id="id_settings_button" class="btn btn-primary"><i class="fas fa-cog"></i></button>
<b-popover
target="id_settings_button"
triggers="click"
@ -61,8 +67,8 @@
<b-form-group
v-bind:label="$t('Recently_Viewed')"
label-for="popover-input-1"
label-cols="3"
class="mb-1">
label-cols="6"
class="mb-3">
<b-form-input
type="number"
v-model="settings.recently_viewed"
@ -70,11 +76,12 @@
size="sm"
></b-form-input>
</b-form-group>
<b-form-group
v-bind:label="$t('Meal_Plan')"
label-for="popover-input-2"
label-cols="3"
class="mb-1">
label-cols="6"
class="mb-3">
<b-form-checkbox
switch
v-model="settings.show_meal_plan"
@ -85,9 +92,7 @@
</div>
<div class="row" style="margin-top: 1vh">
<div class="col-12" style="text-align: right">
<b-button size="sm" variant="secondary" style="margin-right:8px">Cancel
</b-button>
<b-button size="sm" variant="primary">Ok</b-button>
<b-button size="sm" variant="secondary" style="margin-right:8px" @click="$root.$emit('bv::hide::popover')">{{$t('Close')}}</b-button>
</div>
</div>
</b-popover>