mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-25 02:24:26 +00:00
Put users that never logged in at the end
This commit is contained in:
parent
f182de5929
commit
93f4dede3e
@ -2,6 +2,7 @@ from typing import Annotated
|
|||||||
|
|
||||||
import annotated_types
|
import annotated_types
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.db.models import F
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from ninja import Query
|
from ninja import Query
|
||||||
from ninja_extra import ControllerBase, api_controller, paginate, route
|
from ninja_extra import ControllerBase, api_controller, paginate, route
|
||||||
@ -56,7 +57,9 @@ class UserController(ControllerBase):
|
|||||||
)
|
)
|
||||||
@paginate(PageNumberPaginationExtra, page_size=20)
|
@paginate(PageNumberPaginationExtra, page_size=20)
|
||||||
def search_users(self, filters: Query[UserFilterSchema]):
|
def search_users(self, filters: Query[UserFilterSchema]):
|
||||||
return filters.filter(User.objects.order_by("-last_login"))
|
return filters.filter(
|
||||||
|
User.objects.order_by(F("last_login").desc(nulls_last=True))
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
DepthValue = Annotated[int, annotated_types.Ge(0), annotated_types.Le(10)]
|
DepthValue = Annotated[int, annotated_types.Ge(0), annotated_types.Le(10)]
|
||||||
|
@ -5,6 +5,7 @@ from django.test import TestCase
|
|||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils.timezone import now
|
from django.utils.timezone import now
|
||||||
from model_bakery import baker, seq
|
from model_bakery import baker, seq
|
||||||
|
from model_bakery.recipe import Recipe
|
||||||
|
|
||||||
from core.baker_recipes import subscriber_user
|
from core.baker_recipes import subscriber_user
|
||||||
from core.models import User
|
from core.models import User
|
||||||
@ -14,15 +15,20 @@ class TestSearchUsers(TestCase):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def setUpTestData(cls):
|
def setUpTestData(cls):
|
||||||
User.objects.all().delete()
|
User.objects.all().delete()
|
||||||
cls.users = baker.make(
|
user_recipe = Recipe(
|
||||||
User,
|
User,
|
||||||
_quantity=11,
|
|
||||||
first_name=seq("First", suffix="Name"),
|
first_name=seq("First", suffix="Name"),
|
||||||
last_name=seq("Last", suffix="Name"),
|
last_name=seq("Last", suffix="Name"),
|
||||||
nick_name=seq("Nick", suffix="Name"),
|
nick_name=seq("Nick", suffix="Name"),
|
||||||
last_login=seq(now() - timedelta(days=30), timedelta(days=1)),
|
|
||||||
_bulk_create=True,
|
|
||||||
)
|
)
|
||||||
|
cls.users = [
|
||||||
|
user_recipe.make(last_login=None),
|
||||||
|
*user_recipe.make(
|
||||||
|
last_login=seq(now() - timedelta(days=30), timedelta(days=1)),
|
||||||
|
_quantity=10,
|
||||||
|
_bulk_create=True,
|
||||||
|
),
|
||||||
|
]
|
||||||
call_command("update_index", "core", "--remove")
|
call_command("update_index", "core", "--remove")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
Loading…
Reference in New Issue
Block a user