Skip to content

Commit

Permalink
cleanup version sorting
Browse files Browse the repository at this point in the history
fixes: pulp#1516
  • Loading branch information
jerabekjiri committed Jul 25, 2023
1 parent 478463b commit d99bc80
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions pulp_ansible/app/galaxy/v3/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,20 @@
class SemanticVersionOrderingFilter(filters.OrderingFilter):
def filter(self, qs, value):
if value is not None and any(v in ["version", "-version"] for v in value):
order = ""
prerelease_order = F("prerelease").asc(nulls_last=False)
if "-version" in value:
order = "-"
prerelease_order = F("prerelease").desc(nulls_last=False)
order = "-" if "-version" in value else ""

return qs.annotate(
prerelease=Case(
When(collection_version__version_prerelease="", then=Value(None)),
default=F("collection_version__version_prerelease"),
)
default="collection_version__version_prerelease",
),
).order_by(
f"{order}collection_version__version_major",
f"{order}collection_version__version_minor",
f"{order}collection_version__version_patch",
prerelease_order,
f"{order}prerelease",
)

return super().filter(qs, value)


Expand Down

0 comments on commit d99bc80

Please sign in to comment.