Commit 71b585bb by Victor Shnayder

move unique_id_for_user into student/models.py

parent 61ddec46
...@@ -36,10 +36,12 @@ file and check it in at the same time as your model changes. To do that, ...@@ -36,10 +36,12 @@ file and check it in at the same time as your model changes. To do that,
3. Add the migration file created in mitx/common/djangoapps/student/migrations/ 3. Add the migration file created in mitx/common/djangoapps/student/migrations/
""" """
from datetime import datetime from datetime import datetime
from hashlib import sha1
import json import json
import logging import logging
import uuid import uuid
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.db import models from django.db import models
...@@ -191,6 +193,19 @@ class TestCenterUser(models.Model): ...@@ -191,6 +193,19 @@ class TestCenterUser(models.Model):
def email(self): def email(self):
return self.user.email return self.user.email
def unique_id_for_user(user):
"""
Return a unique id for a user, suitable for inserting into
e.g. personalized survey links.
Currently happens to be implemented as a sha1 hash of the username
(and thus assumes that usernames don't change).
"""
return sha1(user.username).hexdigest()
## TODO: Should be renamed to generic UserGroup, and possibly ## TODO: Should be renamed to generic UserGroup, and possibly
# Given an optional field for type of group # Given an optional field for type of group
class UserTestGroup(models.Model): class UserTestGroup(models.Model):
......
...@@ -12,8 +12,10 @@ from django.test import TestCase ...@@ -12,8 +12,10 @@ from django.test import TestCase
from mock import patch, Mock from mock import patch, Mock
from nose.plugins.skip import SkipTest from nose.plugins.skip import SkipTest
from .models import User, UserProfile, CourseEnrollment, replicate_user, USER_FIELDS_TO_COPY from .models import (User, UserProfile, CourseEnrollment,
from .views import process_survey_link, _cert_info, unique_id_for_user replicate_user, USER_FIELDS_TO_COPY,
unique_id_for_user)
from .views import process_survey_link, _cert_info
COURSE_1 = 'edX/toy/2012_Fall' COURSE_1 = 'edX/toy/2012_Fall'
COURSE_2 = 'edx/full/6.002_Spring_2012' COURSE_2 = 'edx/full/6.002_Spring_2012'
......
...@@ -28,7 +28,7 @@ from django.core.cache import cache ...@@ -28,7 +28,7 @@ from django.core.cache import cache
from django_future.csrf import ensure_csrf_cookie, csrf_exempt from django_future.csrf import ensure_csrf_cookie, csrf_exempt
from student.models import (Registration, UserProfile, from student.models import (Registration, UserProfile,
PendingNameChange, PendingEmailChange, PendingNameChange, PendingEmailChange,
CourseEnrollment) CourseEnrollment, unique_id_for_user)
from certificates.models import CertificateStatuses, certificate_status_for_student from certificates.models import CertificateStatuses, certificate_status_for_student
...@@ -39,7 +39,6 @@ from xmodule.modulestore.exceptions import ItemNotFoundError ...@@ -39,7 +39,6 @@ from xmodule.modulestore.exceptions import ItemNotFoundError
from datetime import date from datetime import date
from collections import namedtuple from collections import namedtuple
from hashlib import sha1
from courseware.courses import get_courses_by_university from courseware.courses import get_courses_by_university
from courseware.access import has_access from courseware.access import has_access
...@@ -129,9 +128,6 @@ def press(request): ...@@ -129,9 +128,6 @@ def press(request):
return render_to_response('static_templates/press.html', {'articles': articles}) return render_to_response('static_templates/press.html', {'articles': articles})
def unique_id_for_user(user):
return sha1(user.username).hexdigest()
def process_survey_link(survey_link, user): def process_survey_link(survey_link, user):
""" """
If {UNIQUE_ID} appears in the link, replace it with a unique id for the user. If {UNIQUE_ID} appears in the link, replace it with a unique id for the user.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment