Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
go
Commits
07e4a9bd
Commit
07e4a9bd
authored
Nov 17, 2016
by
David Haynes
Browse files
Comments in the go_extras functions
- heh, I didn't know these were actually defined somewhere
parent
0f8e773e
Pipeline
#488
passed with stage
in 7 minutes
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
go/go/templatetags/go_extras.py
View file @
07e4a9bd
# Django Imports
from
django
import
template
# App Imports
from
go.models
import
RegisteredUser
register
=
template
.
Library
()
# To be a valid tag library, the module must contain a module-level variable
# named register that is a template.Library instance, in which all the tags and
# filters are registered.
register
=
template
.
Library
()
"""
check if a user is registered
"""
@
register
.
filter
def
is_registered
(
user
):
# try getting the RegisteredUser of the current user
try
:
registered
=
RegisteredUser
.
objects
.
get
(
username
=
user
.
username
)
# if it works then the user is registered
return
True
except
RegisteredUser
.
DoesNotExist
:
# if they don't exist then they are not registered
return
False
"""
check if a user is approved
"""
@
register
.
filter
def
is_approved
(
user
):
# try getting the RegisteredUser of the current user
try
:
registered
=
RegisteredUser
.
objects
.
get
(
username
=
user
.
username
)
# if they exist, return whether or not they are approved (boolean)
return
registered
.
approved
except
RegisteredUser
.
DoesNotExist
:
# if they don't exist then they are not approved
return
False
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment