本文整理汇总了Python中student.models.unique_id_for_user函数的典型用法代码示例。如果您正苦于以下问题:Python unique_id_for_user函数的具体用法?Python unique_id_for_user怎么用?Python unique_id_for_user使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了unique_id_for_user函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
self.factory = RequestFactory()
self.url = reverse('foldit_ops')
pwd = 'abc'
self.user = User.objects.create_user('testuser', '[email protected]', pwd)
self.user2 = User.objects.create_user('testuser2', '[email protected]', pwd)
self.unique_user_id = unique_id_for_user(self.user)
self.unique_user_id2 = unique_id_for_user(self.user2)
now = datetime.now(UTC)
self.tomorrow = now + timedelta(days=1)
self.yesterday = now - timedelta(days=1)
UserProfile.objects.create(user=self.user)
UserProfile.objects.create(user=self.user2)
示例2: peer_grading_notifications
def peer_grading_notifications(course, user):
system = LmsModuleSystem(track_function=None, get_module=None, render_template=render_to_string, replace_urls=None)
peer_gs = peer_grading_service.PeerGradingService(settings.OPEN_ENDED_GRADING_INTERFACE, system)
pending_grading = False
img_path = ""
course_id = course.id
student_id = unique_id_for_user(user)
notification_type = "peer"
success, notification_dict = get_value_from_cache(student_id, course_id, notification_type)
if success:
return notification_dict
try:
notifications = json.loads(peer_gs.get_notifications(course_id, student_id))
if notifications["success"]:
if notifications["student_needs_to_peer_grade"]:
pending_grading = True
except:
# Non catastrophic error, so no real action
notifications = {}
# This is a dev_facing_error
log.info(
"Problem with getting notifications from peer grading service for course {0} user {1}.".format(
course_id, student_id
)
)
if pending_grading:
img_path = "/static/images/grading_notification.png"
notification_dict = {"pending_grading": pending_grading, "img_path": img_path, "response": notifications}
set_value_in_cache(student_id, course_id, notification_type, notification_dict)
return notification_dict
示例3: get_anon_ids
def get_anon_ids(request, course_id): # pylint: disable=W0613
"""
Respond with 2-column CSV output of user-id, anonymized-user-id
"""
# TODO: the User.objects query and CSV generation here could be
# centralized into analytics. Currently analytics has similar functionality
# but not quite what's needed.
course_id = SlashSeparatedCourseKey.from_deprecated_string(course_id)
def csv_response(filename, header, rows):
"""Returns a CSV http response for the given header and rows (excel/utf-8)."""
response = HttpResponse(mimetype='text/csv')
response['Content-Disposition'] = 'attachment; filename={0}'.format(filename)
writer = csv.writer(response, dialect='excel', quotechar='"', quoting=csv.QUOTE_ALL)
# In practice, there should not be non-ascii data in this query,
# but trying to do the right thing anyway.
encoded = [unicode(s).encode('utf-8') for s in header]
writer.writerow(encoded)
for row in rows:
encoded = [unicode(s).encode('utf-8') for s in row]
writer.writerow(encoded)
return response
students = User.objects.filter(
courseenrollment__course_id=course_id,
).order_by('id')
header = ['User ID', 'Anonymized user ID', 'Course Specific Anonymized user ID']
rows = [[s.id, unique_id_for_user(s), anonymous_id_for_user(s, course_id)] for s in students]
return csv_response(course_id.to_deprecated_string().replace('/', '-') + '-anon-ids.csv', header, rows)
示例4: get_anon_ids
def get_anon_ids(request, course_id): # pylint: disable=W0613
"""
Respond with 2-column CSV output of user-id, anonymized-user-id
"""
# TODO: the User.objects query and CSV generation here could be
# centralized into analytics. Currently analytics has similar functionality
# but not quite what's needed.
def csv_response(filename, header, rows):
"""Returns a CSV http response for the given header and rows (excel/utf-8)."""
response = HttpResponse(mimetype="text/csv")
response["Content-Disposition"] = "attachment; filename={0}".format(filename)
writer = csv.writer(response, dialect="excel", quotechar='"', quoting=csv.QUOTE_ALL)
# In practice, there should not be non-ascii data in this query,
# but trying to do the right thing anyway.
encoded = [unicode(s).encode("utf-8") for s in header]
writer.writerow(encoded)
for row in rows:
encoded = [unicode(s).encode("utf-8") for s in row]
writer.writerow(encoded)
return response
students = User.objects.filter(courseenrollment__course_id=course_id).order_by("id")
header = ["User ID", "Anonymized user ID"]
rows = [[s.id, unique_id_for_user(s)] for s in students]
return csv_response(course_id.replace("/", "-") + "-anon-ids.csv", header, rows)
示例5: staff_grading_notifications
def staff_grading_notifications(course, user):
staff_gs = StaffGradingService(settings.OPEN_ENDED_GRADING_INTERFACE)
pending_grading = False
img_path = ""
course_id = course.id
student_id = unique_id_for_user(user)
notification_type = "staff"
success, notification_dict = get_value_from_cache(student_id, course_id, notification_type)
if success:
return notification_dict
try:
notifications = json.loads(staff_gs.get_notifications(course_id))
if notifications["success"]:
if notifications["staff_needs_to_grade"]:
pending_grading = True
except:
# Non catastrophic error, so no real action
notifications = {}
# This is a dev_facing_error
log.info(
"Problem with getting notifications from staff grading service for course {0} user {1}.".format(
course_id, student_id
)
)
if pending_grading:
img_path = "/static/images/grading_notification.png"
notification_dict = {"pending_grading": pending_grading, "img_path": img_path, "response": notifications}
set_value_in_cache(student_id, course_id, notification_type, notification_dict)
return notification_dict
示例6: handle
def handle(self, *args, **options):
if len(args) != 1:
raise CommandError("Usage: unique_id_mapping %s" %
" ".join(("<%s>" % arg for arg in Command.args)))
course_id = args[0]
# Generate the output filename from the course ID.
# Change slashes to dashes first, and then append .csv extension.
output_filename = course_id.replace('/', '-') + ".csv"
# Figure out which students are enrolled in the course
students = User.objects.filter(courseenrollment__course_id=course_id)
if len(students) == 0:
self.stdout.write("No students enrolled in %s" % course_id)
return
# Write mapping to output file in CSV format with a simple header
try:
with open(output_filename, 'wb') as output_file:
csv_writer = csv.writer(output_file)
csv_writer.writerow(("User ID", "Anonymized user ID"))
for student in students:
csv_writer.writerow((student.id, unique_id_for_user(student)))
except IOError:
raise CommandError("Error writing to file: %s" % output_filename)
示例7: get_next
def get_next(request, course_id):
"""
Get the next thing to grade for course_id and with the location specified
in the request.
Returns a json dict with the following keys:
'success': bool
'submission_id': a unique identifier for the submission, to be passed back
with the grade.
'submission': the submission, rendered as read-only html for grading
'rubric': the rubric, also rendered as html.
'message': if there was no submission available, but nothing went wrong,
there will be a message field.
'error': if success is False, will have an error message with more info.
"""
_check_access(request.user, course_id)
required = set(["location"])
if request.method != "POST":
raise Http404
actual = set(request.POST.keys())
missing = required - actual
if len(missing) > 0:
return _err_response("Missing required keys {0}".format(", ".join(missing)))
grader_id = unique_id_for_user(request.user)
p = request.POST
location = p["location"]
return HttpResponse(_get_next(course_id, grader_id, location), mimetype="application/json")
示例8: peer_grading_notifications
def peer_grading_notifications(course, user):
peer_gs = peer_grading_service.PeerGradingService(settings.OPEN_ENDED_GRADING_INTERFACE, render_to_string)
pending_grading = False
img_path = ""
course_id = course.id
student_id = unique_id_for_user(user)
notification_type = "peer"
success, notification_dict = get_value_from_cache(student_id, course_id, notification_type)
if success:
return notification_dict
try:
notifications = json.loads(peer_gs.get_notifications(course_id, student_id))
if notifications['success']:
if notifications['student_needs_to_peer_grade']:
pending_grading = True
except:
#Non catastrophic error, so no real action
notifications = {}
#This is a dev_facing_error
log.info(
"Problem with getting notifications from peer grading service for course {0} user {1}.".format(course_id,
student_id))
if pending_grading:
img_path = "/static/images/grading_notification.png"
notification_dict = {'pending_grading': pending_grading, 'img_path': img_path, 'response': notifications}
set_value_in_cache(student_id, course_id, notification_type, notification_dict)
return notification_dict
示例9: _is_embargoed_by_profile_country
def _is_embargoed_by_profile_country(self, user, course_id="", course_is_embargoed=False):
"""
Check whether the user is embargoed based on the country code in the user's profile.
Args:
user (User): The user attempting to access courseware.
Keyword Args:
course_id (unicode): The course the user is trying to access.
course_is_embargoed (boolean): Whether the course the user is accessing has been embargoed.
Returns:
A unicode message if the user is embargoed, otherwise `None`
"""
cache_key = u'user.{user_id}.profile.country'.format(user_id=user.id)
profile_country = cache.get(cache_key)
if profile_country is None:
profile = getattr(user, 'profile', None)
if profile is not None:
profile_country = profile.country.code.upper()
else:
profile_country = ""
cache.set(cache_key, profile_country)
if profile_country in self._embargoed_countries:
return self.REASONS['profile_country'].format(
user_id=unique_id_for_user(user),
profile_country=profile_country,
from_course=self._from_course_msg(course_id, course_is_embargoed)
)
else:
return None
示例10: test_process_survey_link
def test_process_survey_link(self):
username = "fred"
user = Mock(username=username)
user_id = unique_id_for_user(user)
link1 = "http://www.mysurvey.com"
self.assertEqual(process_survey_link(link1, user), link1)
link2 = "http://www.mysurvey.com?unique={UNIQUE_ID}"
link2_expected = "http://www.mysurvey.com?unique={UNIQUE_ID}".format(UNIQUE_ID=user_id)
self.assertEqual(process_survey_link(link2, user), link2_expected)
示例11: flagged_problem_list
def flagged_problem_list(request, course_id):
'''
Show a student problem list
'''
course = get_course_with_access(request.user, course_id, 'staff')
student_id = unique_id_for_user(request.user)
# call problem list service
success = False
error_text = ""
problem_list = []
base_course_url = reverse('courses')
# Make a service that can query edX ORA.
controller_qs = create_controller_query_service()
try:
problem_list_json = controller_qs.get_flagged_problem_list(course_id)
problem_list_dict = json.loads(problem_list_json)
success = problem_list_dict['success']
if 'error' in problem_list_dict:
error_text = problem_list_dict['error']
problem_list = []
else:
problem_list = problem_list_dict['flagged_submissions']
except GradingServiceError:
#This is a staff_facing_error
error_text = STAFF_ERROR_MESSAGE
#This is a dev_facing_error
log.error("Could not get flagged problem list from external grading service for open ended.")
success = False
# catch error if if the json loads fails
except ValueError:
#This is a staff_facing_error
error_text = STAFF_ERROR_MESSAGE
#This is a dev_facing_error
log.error("Could not parse problem list from external grading service response.")
success = False
ajax_url = _reverse_with_slash('open_ended_flagged_problems', course_id)
context = {
'course': course,
'course_id': course_id,
'ajax_url': ajax_url,
'success': success,
'problem_list': problem_list,
'error_text': error_text,
# Checked above
'staff_access': True,
}
return render_to_response('open_ended_problems/open_ended_flagged_problems.html', context)
示例12: flagged_problem_list
def flagged_problem_list(request, course_id):
"""
Show a student problem list
"""
course = get_course_with_access(request.user, course_id, "staff")
student_id = unique_id_for_user(request.user)
# call problem list service
success = False
error_text = ""
problem_list = []
base_course_url = reverse("courses")
try:
problem_list_json = controller_qs.get_flagged_problem_list(course_id)
problem_list_dict = json.loads(problem_list_json)
success = problem_list_dict["success"]
if "error" in problem_list_dict:
error_text = problem_list_dict["error"]
problem_list = []
else:
problem_list = problem_list_dict["flagged_submissions"]
except GradingServiceError:
# This is a staff_facing_error
error_text = STAFF_ERROR_MESSAGE
# This is a dev_facing_error
log.error("Could not get flagged problem list from external grading service for open ended.")
success = False
# catch error if if the json loads fails
except ValueError:
# This is a staff_facing_error
error_text = STAFF_ERROR_MESSAGE
# This is a dev_facing_error
log.error("Could not parse problem list from external grading service response.")
success = False
ajax_url = _reverse_with_slash("open_ended_flagged_problems", course_id)
context = {
"course": course,
"course_id": course_id,
"ajax_url": ajax_url,
"success": success,
"problem_list": problem_list,
"error_text": error_text,
# Checked above
"staff_access": True,
}
return render_to_response("open_ended_problems/open_ended_flagged_problems.html", context)
示例13: make
def make(svalue):
"""
Given a User value entry `svalue`, extracts the student's email and fullname,
and provides a unique id for the user.
Returns a dictionary with keys 'EMAIL', 'FULLNAME', and 'EDX_ID'.
"""
fake_user = FakeUser(svalue["user_id"], svalue["user__username"], lambda: True)
entry = {
"EMAIL": svalue["user__email"],
"FULLNAME": svalue["name"].title(),
"EDX_ID": unique_id_for_user(fake_user),
}
return entry
示例14: make
def make(svalue):
"""
Given a User value entry `svalue`, extracts the student's email and fullname,
and provides a unique id for the user.
Returns a dictionary with keys 'EMAIL', 'FULLNAME', and 'EDX_ID'.
"""
fake_user = FakeUser(svalue['user_id'], svalue['user__username'], lambda: True)
entry = {
'EMAIL': svalue['user__email'],
'FULLNAME': svalue['name'].title(),
'EDX_ID': unique_id_for_user(fake_user)
}
return entry
示例15: student_problem_list
def student_problem_list(request, course_id):
"""
Show a list of problems they have attempted to a student.
Fetch the list from the grading controller server and append some data.
@param request: The request object for this view.
@param course_id: The id of the course to get the problem list for.
@return: Renders an HTML problem list table.
"""
assert isinstance(course_id, basestring)
course_key = SlashSeparatedCourseKey.from_deprecated_string(course_id)
# Load the course. Don't catch any errors here, as we want them to be loud.
course = get_course_with_access(request.user, "load", course_key)
# The anonymous student id is needed for communication with ORA.
student_id = unique_id_for_user(request.user)
base_course_url = reverse("courses")
error_text = ""
student_problem_list = StudentProblemList(course_key, student_id)
# Get the problem list from ORA.
success = student_problem_list.fetch_from_grading_service()
# If we fetched the problem list properly, add in additional problem data.
if success:
# Add in links to problems.
valid_problems = student_problem_list.add_problem_data(base_course_url)
else:
# Get an error message to show to the student.
valid_problems = []
error_text = student_problem_list.error_text
ajax_url = _reverse_with_slash("open_ended_problems", course_key)
context = {
"course": course,
"course_id": course_key.to_deprecated_string(),
"ajax_url": ajax_url,
"success": success,
"problem_list": valid_problems,
"error_text": error_text,
# Checked above
"staff_access": False,
}
return render_to_response("open_ended_problems/open_ended_problems.html", context)