mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 14:13:21 +00:00
Make use of cached_property in User model
This commit is contained in:
parent
c66b9b0512
commit
1e95fb6873
@ -10,6 +10,8 @@ from django.conf import settings
|
|||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from django.contrib.staticfiles.storage import staticfiles_storage
|
from django.contrib.staticfiles.storage import staticfiles_storage
|
||||||
from django.utils.html import escape
|
from django.utils.html import escape
|
||||||
|
from django.utils.functional import cached_property
|
||||||
|
|
||||||
from phonenumber_field.modelfields import PhoneNumberField
|
from phonenumber_field.modelfields import PhoneNumberField
|
||||||
|
|
||||||
from datetime import datetime, timedelta, date
|
from datetime import datetime, timedelta, date
|
||||||
@ -230,25 +232,25 @@ class User(AbstractBaseUser):
|
|||||||
return True
|
return True
|
||||||
return self.groups.filter(name=group_name).exists()
|
return self.groups.filter(name=group_name).exists()
|
||||||
|
|
||||||
@property
|
@cached_property
|
||||||
def is_root(self):
|
def is_root(self):
|
||||||
return self.is_superuser or self.groups.filter(id=settings.SITH_GROUP_ROOT_ID).exists()
|
return self.is_superuser or self.groups.filter(id=settings.SITH_GROUP_ROOT_ID).exists()
|
||||||
|
|
||||||
@property
|
@cached_property
|
||||||
def is_board_member(self):
|
def is_board_member(self):
|
||||||
from club.models import Club
|
from club.models import Club
|
||||||
return Club.objects.filter(unix_name=settings.SITH_MAIN_CLUB['unix_name']).first().get_membership_for(self)
|
return Club.objects.filter(unix_name=settings.SITH_MAIN_CLUB['unix_name']).first().get_membership_for(self)
|
||||||
|
|
||||||
@property
|
@cached_property
|
||||||
def is_launderette_manager(self):
|
def is_launderette_manager(self):
|
||||||
from club.models import Club
|
from club.models import Club
|
||||||
return Club.objects.filter(unix_name=settings.SITH_LAUNDERETTE_MANAGER['unix_name']).first().get_membership_for(self)
|
return Club.objects.filter(unix_name=settings.SITH_LAUNDERETTE_MANAGER['unix_name']).first().get_membership_for(self)
|
||||||
|
|
||||||
@property
|
@cached_property
|
||||||
def is_banned_alcohol(self):
|
def is_banned_alcohol(self):
|
||||||
return self.is_in_group(settings.SITH_GROUP_BANNED_ALCOHOL_ID)
|
return self.is_in_group(settings.SITH_GROUP_BANNED_ALCOHOL_ID)
|
||||||
|
|
||||||
@property
|
@cached_property
|
||||||
def is_banned_counter(self):
|
def is_banned_counter(self):
|
||||||
return self.is_in_group(settings.SITH_GROUP_BANNED_COUNTER_ID)
|
return self.is_in_group(settings.SITH_GROUP_BANNED_COUNTER_ID)
|
||||||
|
|
||||||
@ -422,11 +424,11 @@ class User(AbstractBaseUser):
|
|||||||
escape(self.get_display_name()),
|
escape(self.get_display_name()),
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@cached_property
|
||||||
def subscribed(self):
|
def subscribed(self):
|
||||||
return self.is_in_group(settings.SITH_MAIN_MEMBERS_GROUP)
|
return self.is_in_group(settings.SITH_MAIN_MEMBERS_GROUP)
|
||||||
|
|
||||||
@property
|
@cached_property
|
||||||
def forum_infos(self):
|
def forum_infos(self):
|
||||||
try:
|
try:
|
||||||
return self._forum_infos
|
return self._forum_infos
|
||||||
@ -666,12 +668,12 @@ class SithFile(models.Model):
|
|||||||
else:
|
else:
|
||||||
return super(SithFile, self).__getattribute__(attr)
|
return super(SithFile, self).__getattribute__(attr)
|
||||||
|
|
||||||
@property
|
@cached_property
|
||||||
def as_picture(self):
|
def as_picture(self):
|
||||||
from sas.models import Picture
|
from sas.models import Picture
|
||||||
return Picture.objects.filter(id=self.id).first()
|
return Picture.objects.filter(id=self.id).first()
|
||||||
|
|
||||||
@property
|
@cached_property
|
||||||
def as_album(self):
|
def as_album(self):
|
||||||
from sas.models import Album
|
from sas.models import Album
|
||||||
return Album.objects.filter(id=self.id).first()
|
return Album.objects.filter(id=self.id).first()
|
||||||
|
Loading…
Reference in New Issue
Block a user