yarn build
This commit is contained in:
parent
2da0f5c478
commit
1f21631c5a
@ -4,7 +4,7 @@ from recipes import settings
|
||||
from django.contrib.postgres.search import (
|
||||
SearchQuery, SearchRank, TrigramSimilarity
|
||||
)
|
||||
from django.db.models import Q, Subquery, Case, When, Value
|
||||
from django.db.models import Max, Q, Subquery, Case, When, Value
|
||||
from django.utils import translation
|
||||
|
||||
from cookbook.managers import DICTIONARY
|
||||
@ -35,15 +35,16 @@ def search_recipes(request, queryset, params):
|
||||
|
||||
return queryset.filter(pk__in=last_viewed_recipes[len(last_viewed_recipes) - min(len(last_viewed_recipes), search_last_viewed):])
|
||||
|
||||
orderby = []
|
||||
if search_new == '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')
|
||||
default=Value(0), ))
|
||||
orderby += ['new_recipe']
|
||||
else:
|
||||
queryset = queryset.order_by('name')
|
||||
queryset = queryset
|
||||
|
||||
search_type = search_prefs.search or 'plain'
|
||||
search_sort = None
|
||||
if len(search_string) > 0:
|
||||
unaccent_include = search_prefs.unaccent.values_list('field', flat=True)
|
||||
|
||||
@ -109,13 +110,14 @@ def search_recipes(request, queryset, params):
|
||||
else:
|
||||
query_filter = f
|
||||
|
||||
# TODO this is kind of a dumb method to sort. create settings to choose rank vs most often made, date created or rating
|
||||
# TODO add order by user settings - only do search rank and annotation if rank order is configured
|
||||
search_rank = (
|
||||
SearchRank('name_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)
|
||||
)
|
||||
queryset = queryset.filter(query_filter).annotate(rank=search_rank)
|
||||
orderby += ['-rank']
|
||||
else:
|
||||
queryset = queryset.filter(query_filter)
|
||||
|
||||
@ -147,8 +149,10 @@ def search_recipes(request, queryset, params):
|
||||
|
||||
if search_random == 'true':
|
||||
queryset = queryset.order_by("?")
|
||||
elif search_sort == 'rank':
|
||||
queryset = queryset.order_by('-rank')
|
||||
else:
|
||||
# TODO add order by user settings
|
||||
orderby += ['name']
|
||||
queryset = queryset.order_by(*orderby)
|
||||
|
||||
return queryset
|
||||
|
||||
|
@ -4,7 +4,6 @@ from rest_framework.schemas.utils import is_list_view
|
||||
|
||||
# TODO move to separate class to cleanup
|
||||
class RecipeSchema(AutoSchema):
|
||||
|
||||
def get_path_parameters(self, path, method):
|
||||
if not is_list_view(path, method, self.view):
|
||||
return super(RecipeSchema, self).get_path_parameters(path, method)
|
||||
@ -55,6 +54,11 @@ class RecipeSchema(AutoSchema):
|
||||
"description": 'true or false. returns the results in randomized order.',
|
||||
'schema': {'type': 'string', },
|
||||
})
|
||||
parameters.append({
|
||||
"name": 'new', "in": "query", "required": False,
|
||||
"description": 'true or false. returns new results first in search results',
|
||||
'schema': {'type': 'string', },
|
||||
})
|
||||
return parameters
|
||||
|
||||
|
||||
|
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
@ -19,7 +19,7 @@ from django.contrib.staticfiles.storage import staticfiles_storage
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from dotenv import load_dotenv
|
||||
from webpack_loader.loader import WebpackLoader
|
||||
# load_dotenv()
|
||||
load_dotenv()
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
# Get vars from .env files
|
||||
@ -280,14 +280,14 @@ else:
|
||||
# }
|
||||
|
||||
# SQLite testing DB
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'OPTIONS': ast.literal_eval(os.getenv('DB_OPTIONS')) if os.getenv('DB_OPTIONS') else {},
|
||||
'NAME': 'db.sqlite3',
|
||||
'CONN_MAX_AGE': 600,
|
||||
}
|
||||
}
|
||||
# DATABASES = {
|
||||
# 'default': {
|
||||
# 'ENGINE': 'django.db.backends.sqlite3',
|
||||
# 'OPTIONS': ast.literal_eval(os.getenv('DB_OPTIONS')) if os.getenv('DB_OPTIONS') else {},
|
||||
# 'NAME': 'db.sqlite3',
|
||||
# 'CONN_MAX_AGE': 600,
|
||||
# }
|
||||
# }
|
||||
|
||||
CACHES = {
|
||||
'default': {
|
||||
|
@ -450,6 +450,7 @@ export default {
|
||||
let parent = {}
|
||||
let pageSize = 200
|
||||
let keyword = String(kw.id)
|
||||
console.log(apiClient.listRecipes)
|
||||
|
||||
apiClient.listRecipes(
|
||||
undefined, keyword, undefined, undefined, undefined, undefined,
|
||||
|
@ -380,6 +380,7 @@ export default {
|
||||
refreshData: function (random) {
|
||||
this.random_search = random
|
||||
let apiClient = new ApiApiFactory()
|
||||
|
||||
apiClient.listRecipes(
|
||||
this.settings.search_input,
|
||||
this.settings.search_keywords.map(function (A) {
|
||||
|
@ -4193,12 +4193,13 @@ export const ApiApiAxiosParamCreator = function (configuration?: Configuration)
|
||||
* @param {string} [booksOr] If recipe should be in all (AND) or any (OR) any of the provided books.
|
||||
* @param {string} [internal] true or false. If only internal recipes should be returned or not.
|
||||
* @param {string} [random] true or false. returns the results in randomized order.
|
||||
* @param {string} [_new] true or false. returns new results first in search results
|
||||
* @param {number} [page] A page number within the paginated result set.
|
||||
* @param {number} [pageSize] Number of results to return per page.
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
listRecipes: async (query?: string, keywords?: string, foods?: string, books?: string, keywordsOr?: string, foodsOr?: string, booksOr?: string, internal?: string, random?: string, page?: number, pageSize?: number, options: any = {}): Promise<RequestArgs> => {
|
||||
listRecipes: async (query?: string, keywords?: string, foods?: string, books?: string, keywordsOr?: string, foodsOr?: string, booksOr?: string, internal?: string, random?: string, _new?: string, page?: number, pageSize?: number, options: any = {}): Promise<RequestArgs> => {
|
||||
const localVarPath = `/api/recipe/`;
|
||||
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
||||
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
||||
@ -4247,6 +4248,10 @@ export const ApiApiAxiosParamCreator = function (configuration?: Configuration)
|
||||
localVarQueryParameter['random'] = random;
|
||||
}
|
||||
|
||||
if (_new !== undefined) {
|
||||
localVarQueryParameter['new'] = _new;
|
||||
}
|
||||
|
||||
if (page !== undefined) {
|
||||
localVarQueryParameter['page'] = page;
|
||||
}
|
||||
@ -8071,13 +8076,14 @@ export const ApiApiFp = function(configuration?: Configuration) {
|
||||
* @param {string} [booksOr] If recipe should be in all (AND) or any (OR) any of the provided books.
|
||||
* @param {string} [internal] true or false. If only internal recipes should be returned or not.
|
||||
* @param {string} [random] true or false. returns the results in randomized order.
|
||||
* @param {string} [_new] true or false. returns new results first in search results
|
||||
* @param {number} [page] A page number within the paginated result set.
|
||||
* @param {number} [pageSize] Number of results to return per page.
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
async listRecipes(query?: string, keywords?: string, foods?: string, books?: string, keywordsOr?: string, foodsOr?: string, booksOr?: string, internal?: string, random?: string, page?: number, pageSize?: number, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<InlineResponse2001>> {
|
||||
const localVarAxiosArgs = await localVarAxiosParamCreator.listRecipes(query, keywords, foods, books, keywordsOr, foodsOr, booksOr, internal, random, page, pageSize, options);
|
||||
async listRecipes(query?: string, keywords?: string, foods?: string, books?: string, keywordsOr?: string, foodsOr?: string, booksOr?: string, internal?: string, random?: string, _new?: string, page?: number, pageSize?: number, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<InlineResponse2001>> {
|
||||
const localVarAxiosArgs = await localVarAxiosParamCreator.listRecipes(query, keywords, foods, books, keywordsOr, foodsOr, booksOr, internal, random, _new, page, pageSize, options);
|
||||
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
|
||||
},
|
||||
/**
|
||||
@ -9584,13 +9590,14 @@ export const ApiApiFactory = function (configuration?: Configuration, basePath?:
|
||||
* @param {string} [booksOr] If recipe should be in all (AND) or any (OR) any of the provided books.
|
||||
* @param {string} [internal] true or false. If only internal recipes should be returned or not.
|
||||
* @param {string} [random] true or false. returns the results in randomized order.
|
||||
* @param {string} [_new] true or false. returns new results first in search results
|
||||
* @param {number} [page] A page number within the paginated result set.
|
||||
* @param {number} [pageSize] Number of results to return per page.
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
listRecipes(query?: string, keywords?: string, foods?: string, books?: string, keywordsOr?: string, foodsOr?: string, booksOr?: string, internal?: string, random?: string, page?: number, pageSize?: number, options?: any): AxiosPromise<InlineResponse2001> {
|
||||
return localVarFp.listRecipes(query, keywords, foods, books, keywordsOr, foodsOr, booksOr, internal, random, page, pageSize, options).then((request) => request(axios, basePath));
|
||||
listRecipes(query?: string, keywords?: string, foods?: string, books?: string, keywordsOr?: string, foodsOr?: string, booksOr?: string, internal?: string, random?: string, _new?: string, page?: number, pageSize?: number, options?: any): AxiosPromise<InlineResponse2001> {
|
||||
return localVarFp.listRecipes(query, keywords, foods, books, keywordsOr, foodsOr, booksOr, internal, random, _new, page, pageSize, options).then((request) => request(axios, basePath));
|
||||
},
|
||||
/**
|
||||
*
|
||||
@ -11123,14 +11130,15 @@ export class ApiApi extends BaseAPI {
|
||||
* @param {string} [booksOr] If recipe should be in all (AND) or any (OR) any of the provided books.
|
||||
* @param {string} [internal] true or false. If only internal recipes should be returned or not.
|
||||
* @param {string} [random] true or false. returns the results in randomized order.
|
||||
* @param {string} [_new] true or false. returns new results first in search results
|
||||
* @param {number} [page] A page number within the paginated result set.
|
||||
* @param {number} [pageSize] Number of results to return per page.
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
* @memberof ApiApi
|
||||
*/
|
||||
public listRecipes(query?: string, keywords?: string, foods?: string, books?: string, keywordsOr?: string, foodsOr?: string, booksOr?: string, internal?: string, random?: string, page?: number, pageSize?: number, options?: any) {
|
||||
return ApiApiFp(this.configuration).listRecipes(query, keywords, foods, books, keywordsOr, foodsOr, booksOr, internal, random, page, pageSize, options).then((request) => request(this.axios, this.basePath));
|
||||
public listRecipes(query?: string, keywords?: string, foods?: string, books?: string, keywordsOr?: string, foodsOr?: string, booksOr?: string, internal?: string, random?: string, _new?: string, page?: number, pageSize?: number, options?: any) {
|
||||
return ApiApiFp(this.configuration).listRecipes(query, keywords, foods, books, keywordsOr, foodsOr, booksOr, internal, random, _new, page, pageSize, options).then((request) => request(this.axios, this.basePath));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user