mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 11:23:10 +00:00
Add email state search filter
This commit is contained in:
parent
f8a55bbbe5
commit
47740c4a91
3 changed files with 31 additions and 6 deletions
|
@ -166,7 +166,8 @@ def contains_filter(attribute, word, case_sensitive=False):
|
||||||
|
|
||||||
|
|
||||||
def search_single_word(word, filters, user, start, end,
|
def search_single_word(word, filters, user, start, end,
|
||||||
user_state, aff, case_sensitive=False):
|
user_state, email_state, aff,
|
||||||
|
case_sensitive=False):
|
||||||
""" Construct the correct filters to match differents fields of some models
|
""" Construct the correct filters to match differents fields of some models
|
||||||
with the given query according to the given filters.
|
with the given query according to the given filters.
|
||||||
The match field are either CharField or IntegerField that will be displayed
|
The match field are either CharField or IntegerField that will be displayed
|
||||||
|
@ -199,6 +200,9 @@ def search_single_word(word, filters, user, start, end,
|
||||||
filter_clubs &= Q(state__in=user_state)
|
filter_clubs &= Q(state__in=user_state)
|
||||||
filter_users &= Q(state__in=user_state)
|
filter_users &= Q(state__in=user_state)
|
||||||
|
|
||||||
|
filter_clubs &= Q(email_state__in=email_state)
|
||||||
|
filter_users &= Q(email_state__in=email_state)
|
||||||
|
|
||||||
filters["users"] |= filter_users
|
filters["users"] |= filter_users
|
||||||
filters["clubs"] |= filter_clubs
|
filters["clubs"] |= filter_clubs
|
||||||
|
|
||||||
|
@ -207,7 +211,8 @@ def search_single_word(word, filters, user, start, end,
|
||||||
filter_machines = (
|
filter_machines = (
|
||||||
contains_filter("name", word, case_sensitive)
|
contains_filter("name", word, case_sensitive)
|
||||||
| (contains_filter("user__pseudo", word, case_sensitive)
|
| (contains_filter("user__pseudo", word, case_sensitive)
|
||||||
& Q(user__state__in=user_state))
|
& Q(user__state__in=user_state)
|
||||||
|
& Q(user__email_state__in=email_state))
|
||||||
| contains_filter("interface__domain__name", word, case_sensitive)
|
| contains_filter("interface__domain__name", word, case_sensitive)
|
||||||
| contains_filter("interface__domain__related_domain__name",
|
| contains_filter("interface__domain__related_domain__name",
|
||||||
word, case_sensitive)
|
word, case_sensitive)
|
||||||
|
@ -228,6 +233,7 @@ def search_single_word(word, filters, user, start, end,
|
||||||
filter_factures = (
|
filter_factures = (
|
||||||
contains_filter("user__pseudo", word, case_sensitive)
|
contains_filter("user__pseudo", word, case_sensitive)
|
||||||
& Q(user__state__in=user_state)
|
& Q(user__state__in=user_state)
|
||||||
|
& Q(user__email_state__in=email_state)
|
||||||
)
|
)
|
||||||
if start is not None:
|
if start is not None:
|
||||||
filter_factures &= Q(date__gte=start)
|
filter_factures &= Q(date__gte=start)
|
||||||
|
@ -240,6 +246,7 @@ def search_single_word(word, filters, user, start, end,
|
||||||
filter_bans = (
|
filter_bans = (
|
||||||
contains_filter("user__pseudo", word, case_sensitive)
|
contains_filter("user__pseudo", word, case_sensitive)
|
||||||
& Q(user__state__in=user_state)
|
& Q(user__state__in=user_state)
|
||||||
|
& Q(user__email_state__in=email_state)
|
||||||
) | contains_filter("raison", word, case_sensitive)
|
) | contains_filter("raison", word, case_sensitive)
|
||||||
if start is not None:
|
if start is not None:
|
||||||
filter_bans &= (
|
filter_bans &= (
|
||||||
|
@ -260,6 +267,7 @@ def search_single_word(word, filters, user, start, end,
|
||||||
filter_whitelists = (
|
filter_whitelists = (
|
||||||
contains_filter("user__pseudo", word, case_sensitive)
|
contains_filter("user__pseudo", word, case_sensitive)
|
||||||
& Q(user__state__in=user_state)
|
& Q(user__state__in=user_state)
|
||||||
|
& Q(user__email_state__in=email_state)
|
||||||
) | contains_filter("raison", word, case_sensitive)
|
) | contains_filter("raison", word, case_sensitive)
|
||||||
if start is not None:
|
if start is not None:
|
||||||
filter_whitelists &= (
|
filter_whitelists &= (
|
||||||
|
@ -397,7 +405,7 @@ def apply_filters(filters, user, aff):
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
def search_single_query(query, filters, user, start, end, user_state, aff):
|
def search_single_query(query, filters, user, start, end, user_state, email_state, aff):
|
||||||
""" Handle different queries an construct the correct filters using
|
""" Handle different queries an construct the correct filters using
|
||||||
search_single_word"""
|
search_single_word"""
|
||||||
if query.operator == "+":
|
if query.operator == "+":
|
||||||
|
@ -406,7 +414,8 @@ def search_single_query(query, filters, user, start, end, user_state, aff):
|
||||||
for q in query.subqueries:
|
for q in query.subqueries:
|
||||||
# Construct an independent filter for each subquery
|
# Construct an independent filter for each subquery
|
||||||
subfilters = search_single_query(q, empty_filters(), user,
|
subfilters = search_single_query(q, empty_filters(), user,
|
||||||
start, end, user_state, aff)
|
start, end, user_state,
|
||||||
|
email_state, aff)
|
||||||
|
|
||||||
# Apply the subfilter
|
# Apply the subfilter
|
||||||
for field in filter_fields():
|
for field in filter_fields():
|
||||||
|
@ -420,7 +429,8 @@ def search_single_query(query, filters, user, start, end, user_state, aff):
|
||||||
|
|
||||||
# Handle standard queries
|
# Handle standard queries
|
||||||
return search_single_word(query.text, filters, user, start, end,
|
return search_single_word(query.text, filters, user, start, end,
|
||||||
user_state, aff, query.case_sensitive)
|
user_state, email_state, aff,
|
||||||
|
query.case_sensitive)
|
||||||
|
|
||||||
|
|
||||||
def create_queries(query):
|
def create_queries(query):
|
||||||
|
|
|
@ -37,6 +37,12 @@ CHOICES_USER = (
|
||||||
("4", _("Fully archived")),
|
("4", _("Fully archived")),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
CHOICES_EMAILS = (
|
||||||
|
("0", _("Confirmed")),
|
||||||
|
("1", _("Not confirmed")),
|
||||||
|
("2", _("Waiting for email confirmation")),
|
||||||
|
)
|
||||||
|
|
||||||
CHOICES_AFF = (
|
CHOICES_AFF = (
|
||||||
("0", _("Users")),
|
("0", _("Users")),
|
||||||
("1", _("Machines")),
|
("1", _("Machines")),
|
||||||
|
@ -93,6 +99,13 @@ class SearchFormPlus(Form):
|
||||||
choices=CHOICES_USER,
|
choices=CHOICES_USER,
|
||||||
initial=initial_choices(CHOICES_USER),
|
initial=initial_choices(CHOICES_USER),
|
||||||
)
|
)
|
||||||
|
m = forms.MultipleChoiceField(
|
||||||
|
label=_("Email state filter"),
|
||||||
|
required=False,
|
||||||
|
widget=forms.CheckboxSelectMultiple,
|
||||||
|
choices=CHOICES_EMAILS,
|
||||||
|
initial=initial_choices(CHOICES_EMAILS),
|
||||||
|
)
|
||||||
a = forms.MultipleChoiceField(
|
a = forms.MultipleChoiceField(
|
||||||
label=_("Display filter"),
|
label=_("Display filter"),
|
||||||
required=False,
|
required=False,
|
||||||
|
|
|
@ -38,6 +38,7 @@ from search.forms import (
|
||||||
SearchForm,
|
SearchForm,
|
||||||
SearchFormPlus,
|
SearchFormPlus,
|
||||||
CHOICES_USER,
|
CHOICES_USER,
|
||||||
|
CHOICES_EMAILS,
|
||||||
CHOICES_AFF,
|
CHOICES_AFF,
|
||||||
initial_choices,
|
initial_choices,
|
||||||
)
|
)
|
||||||
|
@ -56,6 +57,7 @@ def get_results(query, request, params):
|
||||||
start = params.get("s", None)
|
start = params.get("s", None)
|
||||||
end = params.get("e", None)
|
end = params.get("e", None)
|
||||||
user_state = params.get("u", initial_choices(CHOICES_USER))
|
user_state = params.get("u", initial_choices(CHOICES_USER))
|
||||||
|
email_state = params.get("m", initial_choices(CHOICES_EMAILS))
|
||||||
aff = params.get("a", initial_choices(CHOICES_AFF))
|
aff = params.get("a", initial_choices(CHOICES_AFF))
|
||||||
|
|
||||||
filters = empty_filters()
|
filters = empty_filters()
|
||||||
|
@ -63,7 +65,7 @@ def get_results(query, request, params):
|
||||||
queries = create_queries(query)
|
queries = create_queries(query)
|
||||||
for q in queries:
|
for q in queries:
|
||||||
filters = search_single_query(
|
filters = search_single_query(
|
||||||
q, filters, request.user, start, end, user_state, aff
|
q, filters, request.user, start, end, user_state, email_state, aff
|
||||||
)
|
)
|
||||||
|
|
||||||
results = apply_filters(filters, request.user, aff)
|
results = apply_filters(filters, request.user, aff)
|
||||||
|
|
Loading…
Reference in a new issue