feat: extend intervention filtering to support codes/identifiers for thematics, contracts, and orders, and remove global search hook
This commit is contained in:
parent
49019400b8
commit
66ab7a2f3d
1 changed files with 47 additions and 20 deletions
|
|
@ -459,6 +459,8 @@ def interventions_geojson(request):
|
|||
types = _expand_csv_params(request.GET.getlist('type'))
|
||||
providers = _expand_csv_params(request.GET.getlist('provider'))
|
||||
contracts = _expand_csv_params(request.GET.getlist('contract'))
|
||||
orders = _expand_csv_params(request.GET.getlist('order'))
|
||||
codes = _expand_csv_params(request.GET.getlist('code') + request.GET.getlist('codes'))
|
||||
assigned_teams = _expand_csv_params(request.GET.getlist('assigned_team'))
|
||||
assigned_members = _expand_csv_params(request.GET.getlist('assigned_member'))
|
||||
pause_reasons = _expand_csv_params(request.GET.getlist('pause_reason'))
|
||||
|
|
@ -473,7 +475,16 @@ def interventions_geojson(request):
|
|||
search_q = (request.GET.get('q') or '').strip()
|
||||
|
||||
if thematics:
|
||||
qs = qs.filter(thematic__code__in=thematics)
|
||||
thematic_list = _expand_csv_params(thematics)
|
||||
if thematic_list:
|
||||
t_ids = [t for t in thematic_list if t.isdigit()]
|
||||
t_codes = [t for t in thematic_list if not t.isdigit()]
|
||||
thematic_q = Q()
|
||||
if t_ids:
|
||||
thematic_q |= Q(thematic_id__in=t_ids)
|
||||
if t_codes:
|
||||
thematic_q |= Q(thematic__code__in=t_codes)
|
||||
qs = qs.filter(thematic_q)
|
||||
if locations:
|
||||
selected_loc = _parse_selected_locations(request)
|
||||
allowed_ct_ids = _allowed_ct_ids_from_thematics(thematics) if thematics else None
|
||||
|
|
@ -493,7 +504,41 @@ def interventions_geojson(request):
|
|||
if providers:
|
||||
qs = qs.filter(assigned_provider_id__in=providers)
|
||||
if contracts:
|
||||
qs = qs.filter(contract_id__in=contracts)
|
||||
c_ids = [c for c in contracts if c.isdigit()]
|
||||
c_codes = [c for c in contracts if not c.isdigit()]
|
||||
contract_q = Q()
|
||||
if c_ids:
|
||||
contract_q |= Q(contract_id__in=c_ids)
|
||||
if c_codes:
|
||||
contract_q |= Q(contract__contract_number__in=c_codes)
|
||||
qs = qs.filter(contract_q)
|
||||
if orders:
|
||||
order_q = Q()
|
||||
has_null = False
|
||||
has_not_null = False
|
||||
o_ids = []
|
||||
o_codes = []
|
||||
for o in orders:
|
||||
o_lower = o.lower()
|
||||
if o_lower in ('null', 'none', '0', 'false', 'without', 'no_order', 'without_order'):
|
||||
has_null = True
|
||||
elif o_lower in ('with', 'has_order', 'not_null', 'with_order', 'true'):
|
||||
has_not_null = True
|
||||
elif o.isdigit():
|
||||
o_ids.append(int(o))
|
||||
else:
|
||||
o_codes.append(o)
|
||||
if has_null:
|
||||
order_q |= Q(order__isnull=True)
|
||||
if has_not_null:
|
||||
order_q |= Q(order__isnull=False)
|
||||
if o_ids:
|
||||
order_q |= Q(order_id__in=o_ids)
|
||||
if o_codes:
|
||||
order_q |= Q(order__order_code__in=o_codes)
|
||||
qs = qs.filter(order_q)
|
||||
if codes:
|
||||
qs = qs.filter(code__in=codes)
|
||||
if assigned_members:
|
||||
qs = qs.filter(assigned_member_id__in=assigned_members)
|
||||
if assigned_teams:
|
||||
|
|
@ -508,24 +553,6 @@ def interventions_geojson(request):
|
|||
if preparation_states:
|
||||
qs = qs.filter(prep_state__in=preparation_states)
|
||||
|
||||
if search_q:
|
||||
words = search_q.split()
|
||||
from common.hooks import hooks
|
||||
qs = hooks.apply_search_annotations(qs)
|
||||
def _word_q(word):
|
||||
q_base = (
|
||||
Q(title__icontains=word)
|
||||
| Q(code__icontains=word)
|
||||
| Q(location_code__icontains=word)
|
||||
| Q(contract__contract_number__icontains=word)
|
||||
)
|
||||
q_base |= hooks.get_search_filters(word)
|
||||
return q_base
|
||||
combined = Q()
|
||||
for w in words:
|
||||
combined &= _word_q(w)
|
||||
qs = qs.filter(combined)
|
||||
|
||||
# --- annotate once (DB does geometry + dates)
|
||||
if date_type == 'planned':
|
||||
effective_begin = Coalesce('begin_time', 'planned_begin_time', output_field=DateTimeField())
|
||||
|
|
|
|||
Loading…
Reference in a new issue