8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-27 07:02:26 +00:00

Add email state search filter

This commit is contained in:
Jean-Romain Garnier 2020-04-19 17:07:29 +02:00 committed by Gabriel Detraz
parent f8a55bbbe5
commit 47740c4a91
3 changed files with 31 additions and 6 deletions

View file

@ -166,7 +166,8 @@ def contains_filter(attribute, word, case_sensitive=False):
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
with the given query according to the given filters.
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_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["clubs"] |= filter_clubs
@ -207,7 +211,8 @@ def search_single_word(word, filters, user, start, end,
filter_machines = (
contains_filter("name", 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__related_domain__name",
word, case_sensitive)
@ -228,6 +233,7 @@ def search_single_word(word, filters, user, start, end,
filter_factures = (
contains_filter("user__pseudo", word, case_sensitive)
& Q(user__state__in=user_state)
& Q(user__email_state__in=email_state)
)
if start is not None:
filter_factures &= Q(date__gte=start)
@ -240,6 +246,7 @@ def search_single_word(word, filters, user, start, end,
filter_bans = (
contains_filter("user__pseudo", word, case_sensitive)
& Q(user__state__in=user_state)
& Q(user__email_state__in=email_state)
) | contains_filter("raison", word, case_sensitive)
if start is not None:
filter_bans &= (
@ -260,6 +267,7 @@ def search_single_word(word, filters, user, start, end,
filter_whitelists = (
contains_filter("user__pseudo", word, case_sensitive)
& Q(user__state__in=user_state)
& Q(user__email_state__in=email_state)
) | contains_filter("raison", word, case_sensitive)
if start is not None:
filter_whitelists &= (
@ -397,7 +405,7 @@ def apply_filters(filters, user, aff):
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
search_single_word"""
if query.operator == "+":
@ -406,7 +414,8 @@ def search_single_query(query, filters, user, start, end, user_state, aff):
for q in query.subqueries:
# Construct an independent filter for each subquery
subfilters = search_single_query(q, empty_filters(), user,
start, end, user_state, aff)
start, end, user_state,
email_state, aff)
# Apply the subfilter
for field in filter_fields():
@ -420,7 +429,8 @@ def search_single_query(query, filters, user, start, end, user_state, aff):
# Handle standard queries
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):

View file

@ -37,6 +37,12 @@ CHOICES_USER = (
("4", _("Fully archived")),
)
CHOICES_EMAILS = (
("0", _("Confirmed")),
("1", _("Not confirmed")),
("2", _("Waiting for email confirmation")),
)
CHOICES_AFF = (
("0", _("Users")),
("1", _("Machines")),
@ -93,6 +99,13 @@ class SearchFormPlus(Form):
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(
label=_("Display filter"),
required=False,

View file

@ -38,6 +38,7 @@ from search.forms import (
SearchForm,
SearchFormPlus,
CHOICES_USER,
CHOICES_EMAILS,
CHOICES_AFF,
initial_choices,
)
@ -56,6 +57,7 @@ def get_results(query, request, params):
start = params.get("s", None)
end = params.get("e", None)
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))
filters = empty_filters()
@ -63,7 +65,7 @@ def get_results(query, request, params):
queries = create_queries(query)
for q in queries:
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)