Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix du bug de téléchargement des structures qui ont vu des dépôts de besoins #969

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions lemarche/siaes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def with_in_user_favorite_list_stats(self, user):
def has_contact_email(self):
return self.exclude(contact_email__isnull=True).exclude(contact_email__exact="")

def filter_with_tender(self, tender):
def filter_with_tender(self, tender, tender_status=None):
"""
Filter Siaes with tenders:
- first we filter the Siae that are live + can be contacted
Expand Down Expand Up @@ -354,7 +354,25 @@ def filter_with_tender(self, tender):
# filter by siae_kind
if len(tender.siae_kind):
qs = qs.filter(kind__in=tender.siae_kind)
# return

# tender status
if tender_status == "INTERESTED":
madjid-asa marked this conversation as resolved.
Show resolved Hide resolved
qs = qs.filter(tendersiae__tender=tender, tendersiae__detail_contact_click_date__isnull=False)
qs = qs.order_by("-tendersiae__detail_contact_click_date")
elif tender_status == "VIEWED":
qs = qs.filter(
Q(tendersiae__tender=tender)
& (
Q(tendersiae__email_link_click_date__isnull=False)
| Q(tendersiae__detail_display_date__isnull=False)
)
)
qs = qs.order_by("-tendersiae__email_link_click_date")
elif tender_status == "ALL":
# why need to filter more ?
qs = qs.filter(tendersiae__tender=tender, tendersiae__email_send_date__isnull=False)
qs = qs.order_by("-tendersiae__email_send_date")

return qs.distinct()

def with_tender_stats(self):
Expand Down
7 changes: 2 additions & 5 deletions lemarche/www/siaes/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,12 +306,9 @@ def filter_queryset(self, qs=None): # noqa C901

# a Tender author can export its Siae list
tender = self.cleaned_data.get("tender", None)
tender_status = self.cleaned_data.get("tender_status", None)
if tender:
if tender_status: # status == "INTERESTED"
qs = qs.filter(tendersiae__tender=tender, tendersiae__detail_contact_click_date__isnull=False)
else:
qs = qs.filter(tendersiae__tender=tender, tendersiae__email_send_date__isnull=False)
tender_status = self.cleaned_data.get("tender_status", "ALL")
qs = qs.filter_with_tender(tender=tender, tender_status=tender_status)

locations = self.cleaned_data.get("locations", None)
if locations:
Expand Down
20 changes: 3 additions & 17 deletions lemarche/www/tenders/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.contrib import messages
from django.contrib.auth.mixins import LoginRequiredMixin
from django.core.paginator import Paginator
from django.db.models import Prefetch, Q
from django.db.models import Prefetch
from django.http import HttpResponseForbidden, HttpResponseRedirect
from django.shortcuts import get_object_or_404, redirect
from django.urls import reverse_lazy
Expand Down Expand Up @@ -482,27 +482,13 @@ def get_queryset(self):
qs = super().get_queryset()
# first get the tender's siaes
self.tender = Tender.objects.get(slug=self.kwargs.get("slug"))
if self.status == "INTERESTED": # status == "INTERESTED"
qs = qs.filter(tendersiae__tender=self.tender, tendersiae__detail_contact_click_date__isnull=False)
qs = qs.order_by("-tendersiae__detail_contact_click_date")
elif self.status == "VIEWED": # status == "INTERESTED"
qs = qs.filter(
Q(tendersiae__tender=self.tender)
& (
Q(tendersiae__email_link_click_date__isnull=False)
| Q(tendersiae__detail_display_date__isnull=False)
)
).distinct()
qs = qs.order_by("-tendersiae__email_link_click_date")
else: # default
qs = qs.filter(tendersiae__tender=self.tender, tendersiae__email_send_date__isnull=False)
qs = qs.order_by("-tendersiae__email_send_date")
qs = qs.filter_with_tender(tender=self.tender, tender_status=self.status)
# then filter with the form
self.filter_form = SiaeFilterForm(data=self.request.GET)
qs = self.filter_form.filter_queryset(qs)
return qs

def get(self, request, status=None, *args, **kwargs):
def get(self, request, status="ALL", *args, **kwargs):
"""
- set status
- update 'siae_list_last_seen_date'
Expand Down