Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Django Auth Lti
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
Model registry
Operate
Environments
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Marcel Heijink
Django Auth Lti
Commits
9d6b714a
Commit
9d6b714a
authored
11 years ago
by
Colin Murtaugh
Browse files
Options
Downloads
Patches
Plain Diff
added timing
parent
1ef31c30
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
django_auth_lti/middleware.py
+17
-3
17 additions, 3 deletions
django_auth_lti/middleware.py
django_auth_lti/timer.py
+31
-0
31 additions, 0 deletions
django_auth_lti/timer.py
with
48 additions
and
3 deletions
django_auth_lti/middleware.py
+
17
−
3
View file @
9d6b714a
...
...
@@ -2,6 +2,8 @@ from django.contrib import auth
from
django.core.exceptions
import
ImproperlyConfigured
,
PermissionDenied
from
timer
import
Timer
import
logging
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -29,7 +31,12 @@ class LTIAuthMiddleware(object):
"
before the PINAuthMiddleware class.
"
)
# if the user is already authenticated, just return
if
request
.
user
.
is_authenticated
():
with
Timer
()
as
t
:
is_auth
=
request
.
user
.
is_authenticated
()
logger
.
debug
(
'
is_authenticated() took %s s
'
%
t
.
secs
)
if
is_auth
:
# nothing more to do!
logger
.
debug
(
'
inside process_request: user is already authenticated: %s
'
%
request
.
user
)
return
...
...
@@ -39,14 +46,21 @@ class LTIAuthMiddleware(object):
logger
.
debug
(
'
the request.user is not authenticated
'
)
# authenticate and log the user in
user
=
auth
.
authenticate
(
request
=
request
)
with
Timer
()
as
t
:
user
=
auth
.
authenticate
(
request
=
request
)
logger
.
debug
(
'
authenticate() took %s s
'
%
t
.
secs
)
if
user
is
not
None
:
# User is valid. Set request.user and persist user in the session
# by logging the user in.
logger
.
debug
(
'
user was successfully authenticated; now log them in
'
)
request
.
user
=
user
auth
.
login
(
request
,
user
)
with
Timer
()
as
t
:
auth
.
login
(
request
,
user
)
logger
.
debug
(
'
login() took %s s
'
%
t
.
secs
)
else
:
# User could not be authenticated! Bail!
logger
.
error
(
'
user could not be authenticated; let the request continue in case another auth plugin is configured
'
)
...
...
This diff is collapsed.
Click to expand it.
django_auth_lti/timer.py
0 → 100644
+
31
−
0
View file @
9d6b714a
import
time
class
Timer
(
object
):
def
__init__
(
self
,
verbose
=
False
):
self
.
verbose
=
verbose
def
__enter__
(
self
):
self
.
start
=
time
.
time
()
return
self
def
__exit__
(
self
,
*
args
):
self
.
end
=
time
.
time
()
self
.
secs
=
self
.
end
-
self
.
start
self
.
msecs
=
self
.
secs
*
1000
# millisecs
if
self
.
verbose
:
print
'
elapsed time: %f ms
'
%
self
.
msecs
'''
Example usage:
from timer import Timer
with Timer() as t:
do_something()
print
"
=> elasped lpush: %s s
"
% t.secs
with Timer as t:
do_something_else()
print
"
=> elasped lpop: %s s
"
% t.secs
'''
\ No newline at end of file
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