mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 06:03:20 +00:00
use typing.Self for custom queryset methods
This commit is contained in:
parent
d04b4c77c6
commit
6962b39fc9
@ -23,6 +23,8 @@
|
|||||||
#
|
#
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Self
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core import validators
|
from django.core import validators
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
@ -265,12 +267,11 @@ class Club(models.Model):
|
|||||||
|
|
||||||
|
|
||||||
class MembershipQuerySet(models.QuerySet):
|
class MembershipQuerySet(models.QuerySet):
|
||||||
def ongoing(self) -> "MembershipQuerySet":
|
def ongoing(self) -> Self:
|
||||||
"""Filter all memberships which are not finished yet."""
|
"""Filter all memberships which are not finished yet."""
|
||||||
# noinspection PyTypeChecker
|
|
||||||
return self.filter(Q(end_date=None) | Q(end_date__gte=timezone.now()))
|
return self.filter(Q(end_date=None) | Q(end_date__gte=timezone.now()))
|
||||||
|
|
||||||
def board(self) -> "MembershipQuerySet":
|
def board(self) -> Self:
|
||||||
"""Filter all memberships where the user is/was in the board.
|
"""Filter all memberships where the user is/was in the board.
|
||||||
|
|
||||||
Be aware that users who were in the board in the past
|
Be aware that users who were in the board in the past
|
||||||
@ -279,7 +280,6 @@ class MembershipQuerySet(models.QuerySet):
|
|||||||
If you want to get the users who are currently in the board,
|
If you want to get the users who are currently in the board,
|
||||||
mind combining this with the :meth:`ongoing` queryset method
|
mind combining this with the :meth:`ongoing` queryset method
|
||||||
"""
|
"""
|
||||||
# noinspection PyTypeChecker
|
|
||||||
return self.filter(role__gt=settings.SITH_MAXIMUM_FREE_ROLE)
|
return self.filter(role__gt=settings.SITH_MAXIMUM_FREE_ROLE)
|
||||||
|
|
||||||
def update(self, **kwargs):
|
def update(self, **kwargs):
|
||||||
|
@ -362,7 +362,6 @@ class CounterQuerySet(models.QuerySet):
|
|||||||
```
|
```
|
||||||
"""
|
"""
|
||||||
subquery = user.counters.filter(pk=OuterRef("pk"))
|
subquery = user.counters.filter(pk=OuterRef("pk"))
|
||||||
# noinspection PyTypeChecker
|
|
||||||
return self.annotate(has_annotated_barman=Exists(subquery))
|
return self.annotate(has_annotated_barman=Exists(subquery))
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
from typing import Self
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
@ -61,7 +62,7 @@ class SasFile(SithFile):
|
|||||||
|
|
||||||
|
|
||||||
class PictureQuerySet(models.QuerySet):
|
class PictureQuerySet(models.QuerySet):
|
||||||
def viewable_by(self, user: User) -> PictureQuerySet:
|
def viewable_by(self, user: User) -> Self:
|
||||||
"""Filter the pictures that this user can view.
|
"""Filter the pictures that this user can view.
|
||||||
|
|
||||||
Warnings:
|
Warnings:
|
||||||
@ -173,7 +174,7 @@ class Picture(SasFile):
|
|||||||
|
|
||||||
|
|
||||||
class AlbumQuerySet(models.QuerySet):
|
class AlbumQuerySet(models.QuerySet):
|
||||||
def viewable_by(self, user: User) -> PictureQuerySet:
|
def viewable_by(self, user: User) -> Self:
|
||||||
"""Filter the albums that this user can view.
|
"""Filter the albums that this user can view.
|
||||||
|
|
||||||
Warnings:
|
Warnings:
|
||||||
|
Loading…
Reference in New Issue
Block a user