Skip to content
Snippets Groups Projects
Commit 5bf8c1e2 authored by Todd Dembrey's avatar Todd Dembrey
Browse files

Cache the properties on the users, because they dont change in a request

parent 2651e7cc
No related branches found
No related tags found
No related merge requests found
from django.db import models from django.db import models
from django.contrib.auth.models import AbstractUser, BaseUserManager from django.contrib.auth.models import AbstractUser, BaseUserManager
from django.utils.functional import cached_property
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from .groups import REVIEWER_GROUP_NAME, STAFF_GROUP_NAME from .groups import REVIEWER_GROUP_NAME, STAFF_GROUP_NAME
...@@ -85,15 +86,15 @@ class User(AbstractUser): ...@@ -85,15 +86,15 @@ class User(AbstractUser):
def get_short_name(self): def get_short_name(self):
return self.email return self.email
@property @cached_property
def is_apply_staff(self): def is_apply_staff(self):
return self.groups.filter(name=STAFF_GROUP_NAME).exists() or self.is_superuser return self.groups.filter(name=STAFF_GROUP_NAME).exists() or self.is_superuser
@property @cached_property
def is_reviewer(self): def is_reviewer(self):
return self.groups.filter(name=REVIEWER_GROUP_NAME).exists() return self.groups.filter(name=REVIEWER_GROUP_NAME).exists()
@property @cached_property
def is_applicant(self): def is_applicant(self):
return not self.is_apply_staff and not self.is_reviewer return not self.is_apply_staff and not self.is_reviewer
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment