Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hypha
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ots
hypha
Commits
5bf8c1e2
Commit
5bf8c1e2
authored
6 years ago
by
Todd Dembrey
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
opentech/apply/users/models.py
+4
-3
4 additions, 3 deletions
opentech/apply/users/models.py
with
4 additions
and
3 deletions
opentech/apply/users/models.py
+
4
−
3
View file @
5bf8c1e2
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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment