Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
838622f5
Commit
838622f5
authored
Dec 04, 2013
by
Calen Pennington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle integrity errors when creating/retrieving AnonymousUserId entries
parent
7171397d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
6 deletions
+24
-6
common/djangoapps/student/models.py
+24
-6
No files found.
common/djangoapps/student/models.py
View file @
838622f5
...
...
@@ -20,7 +20,7 @@ import uuid
from
django.conf
import
settings
from
django.contrib.auth.models
import
User
from
django.contrib.auth.signals
import
user_logged_in
,
user_logged_out
from
django.db
import
models
from
django.db
import
models
,
IntegrityError
from
django.db.models.signals
import
post_save
from
django.dispatch
import
receiver
import
django.dispatch
...
...
@@ -74,12 +74,30 @@ def anonymous_id_for_user(user, course_id):
hasher
.
update
(
settings
.
SECRET_KEY
)
hasher
.
update
(
str
(
user
.
id
))
hasher
.
update
(
course_id
)
digest
=
hasher
.
hexdigest
()
return
AnonymousUserId
.
objects
.
get_or_create
(
defaults
=
{
'anonymous_user_id'
:
hasher
.
hexdigest
()},
user
=
user
,
course_id
=
course_id
)[
0
]
.
anonymous_user_id
try
:
anonymous_user_id
,
created
=
AnonymousUserId
.
objects
.
get_or_create
(
defaults
=
{
'anonymous_user_id'
:
digest
},
user
=
user
,
course_id
=
course_id
)
if
anonymous_user_id
.
anonymous_user_id
!=
digest
:
log
.
error
(
"Stored anonymous user id {stored!r} for user {user!r} "
"in course {course!r} doesn't match computed id {digest!r}"
.
format
(
user
=
user
,
course
=
course_id
,
stored
=
anonymous_user_id
.
anonymous_user_id
,
digest
=
digest
)
)
except
IntegrityError
:
# Another thread has already created this entry, so
# continue
pass
return
digest
def
user_by_anonymous_id
(
id
):
...
...
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