search preference settings

This commit is contained in:
smilerz
2021-06-04 13:33:02 -05:00
parent f0e56863c5
commit 7c1b5b2d85
8 changed files with 304 additions and 126 deletions

View File

@ -10,7 +10,8 @@ from hcaptcha.fields import hCaptchaField
from .models import (Comment, Food, InviteLink, Keyword, MealPlan, Recipe,
RecipeBook, RecipeBookEntry, Storage, Sync, Unit, User,
UserPreference, SupermarketCategory, MealType, Space)
UserPreference, SupermarketCategory, MealType, Space,
SearchPreference)
class SelectWidget(widgets.Select):
@ -471,3 +472,38 @@ class UserCreateForm(forms.Form):
attrs={'autocomplete': 'new-password', 'type': 'password'}
)
)
class SearchPreferenceForm(forms.ModelForm):
prefix = 'search'
class Meta:
model = SearchPreference
fields = ('search', 'unaccent', 'icontains', 'istartswith', 'trigram', 'fulltext')
help_texts = {
'search': _('Select type method of search. Click here for full desciption of choices.'),
'unaccent': _('Fields to search ignoring accents. Selecting this option can improve or degrade search quality depending on language'),
'icontains': _("Fields to search for partial matches. (e.g. searching for 'Pie' will return 'pie' and 'piece' and 'soapie')"),
'istartswith': _("Fields to search for beginning of word matches. (e.g. searching for 'sa' will return 'salad' and 'sandwich')"),
'trigram': _("Fields to 'fuzzy' search. (e.g. searching for 'recpie' will find 'recipe'.) Note: this option will conflict with 'web' and 'raw' methods of search."),
'fulltext': _("Fields to full text search. Note: 'web', 'phrase', and 'raw' search methods only function with fulltext fields.")
}
labels = {
'search': _('Search Method'),
'unaccent': _('Ignore Accent'),
'icontains': _("Partial Match"),
'istartswith': _("Starts Wtih"),
'trigram': _("Fuzzy Search"),
'fulltext': _("Full Text")
}
widgets = {
'search': SelectWidget,
'unaccent': MultiSelectWidget,
'icontains': MultiSelectWidget,
'istartswith': MultiSelectWidget,
'trigram': MultiSelectWidget,
'fulltext': MultiSelectWidget,
}