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

[Recherche] Remonter les prestataires qui ont un logo #913

Merged
merged 2 commits into from
Sep 20, 2023
Merged
Changes from 1 commit
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
Next Next commit
Siae search: add has_logo in default ordering
raphodn committed Sep 19, 2023
commit 375a5cddbb762940f66f9058cbbc343f268510ea
13 changes: 8 additions & 5 deletions lemarche/www/siaes/forms.py
Original file line number Diff line number Diff line change
@@ -335,23 +335,26 @@ def order_queryset(self, qs):
- push siae to update their profile, and have the freshest data at the top
- we tried random order ("?"), but it had some bugs with pagination
**BUT**
- if a Siae has a a SiaeOffer, or a description, or a User, then it is "boosted"
- if a Siae has a a SiaeOffer, or a description, or a logo, or a User, then it is "boosted"
- if the search is on a CITY perimeter, we order by coordinates first
- if the search is by keyword, order by "similarity" only
"""
DEFAULT_ORDERING = ["-updated_at"]
ORDER_BY_FIELDS = ["-has_offer", "-has_description", "-has_user"] + DEFAULT_ORDERING
ORDER_BY_FIELDS = ["-has_offer", "-has_description", "-has_logo", "-has_user"] + DEFAULT_ORDERING
# annotate on description presence: https://stackoverflow.com/a/65014409/4293684
# qs = qs.annotate(has_description=Exists(F("description"))) # doesn't work
qs = qs.annotate(
has_offer=Case(
When(offer_count__gte=1, then=Value(True)), default=Value(False), output_field=BooleanField()
)
)
qs = qs.annotate(
has_description=Case(
When(description__gte=1, then=Value(True)), default=Value(False), output_field=BooleanField()
)
)
qs = qs.annotate(
has_offer=Case(
When(offer_count__gte=1, then=Value(True)), default=Value(False), output_field=BooleanField()
)
has_logo=Case(When(logo_url__gte=1, then=Value(True)), default=Value(False), output_field=BooleanField())
)
qs = qs.annotate(
has_user=Case(When(user_count__gte=1, then=Value(True)), default=Value(False), output_field=BooleanField())