On ne filtre les départements que si on en donne

This commit is contained in:
Tom Hubrecht 2021-10-12 11:18:54 +02:00
parent b3f7e944c3
commit 4e7fe564cf

View file

@ -130,13 +130,17 @@ class HomeView(FormView):
def form_valid(self, form):
name = form.cleaned_data["name"]
promotion = form.cleaned_data["year"]
depts = form.cleaned_data["department"]
result = Profile.objects.filter(
Q(full_name__icontains=name)
| Q(nickname__icontains=name)
| Q(user__username__icontains=name)
).filter(department__in=form.cleaned_data["department"])
)
if promotion is not None:
if depts:
result = result.filter(department__in=depts)
if promotion:
result = result.filter(promotion=promotion)
return self.render_to_response(self.get_context_data(result=result))