本文整理汇总了Python中student.models.CourseEnrollment.is_enrolled_as_verified方法的典型用法代码示例。如果您正苦于以下问题:Python CourseEnrollment.is_enrolled_as_verified方法的具体用法?Python CourseEnrollment.is_enrolled_as_verified怎么用?Python CourseEnrollment.is_enrolled_as_verified使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类student.models.CourseEnrollment
的用法示例。
在下文中一共展示了CourseEnrollment.is_enrolled_as_verified方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_status
# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import is_enrolled_as_verified [as 别名]
def get_status(self, user_id, course_id, related_assessment_location):
"""Get verification attempt status against a user for a given
'checkpoint' and 'course_id'.
Args:
user_id (str): User Id string
course_id (str): A string of course id
related_assessment_location (str): Location of Reverification XBlock
Returns: str or None
"""
user = User.objects.get(id=user_id)
course_key = CourseKey.from_string(course_id)
if not CourseEnrollment.is_enrolled_as_verified(user, course_key):
return self.NON_VERIFIED_TRACK
elif SkippedReverification.check_user_skipped_reverification_exists(user_id, course_key):
return self.SKIPPED_STATUS
try:
checkpoint_status = VerificationStatus.objects.filter(
user_id=user_id,
checkpoint__course_id=course_key,
checkpoint__checkpoint_location=related_assessment_location
).latest()
return checkpoint_status.status
except ObjectDoesNotExist:
return None
示例2: get_verification_context
# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import is_enrolled_as_verified [as 别名]
def get_verification_context(self, request, course):
course_key = CourseKey.from_string(unicode(course.id))
# Establish whether the course has a verified mode
available_modes = CourseMode.modes_for_course_dict(unicode(course.id))
has_verified_mode = CourseMode.has_verified_mode(available_modes)
# Establish whether the user is already enrolled
is_already_verified = CourseEnrollment.is_enrolled_as_verified(request.user, course_key)
# Establish whether the verification deadline has already passed
verification_deadline = VerifiedUpgradeDeadlineDate(course, request.user)
deadline_has_passed = verification_deadline.deadline_has_passed()
# If this proves its worth, we can internationalize and display for more than English speakers.
show_course_sock = (
has_verified_mode and not is_already_verified and
not deadline_has_passed and get_language() == 'en'
)
# Get information about the upgrade
course_price = get_cosmetic_verified_display_price(course)
upgrade_url = EcommerceService().upgrade_url(request.user, course_key)
context = {
'show_course_sock': show_course_sock,
'course_price': course_price,
'course_id': course.id,
'upgrade_url': upgrade_url,
}
return context
示例3: get_verification_context
# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import is_enrolled_as_verified [as 别名]
def get_verification_context(self, request, course):
course_key = CourseKey.from_string(unicode(course.id))
# Establish whether the course has a verified mode
available_modes = CourseMode.modes_for_course_dict(unicode(course.id))
has_verified_mode = CourseMode.has_verified_mode(available_modes)
# Establish whether the user is already enrolled
is_already_verified = CourseEnrollment.is_enrolled_as_verified(request.user.id, course_key)
# Establish whether the verification deadline has already passed
verification_deadline = VerifiedUpgradeDeadlineDate(course, request.user)
deadline_has_passed = verification_deadline.deadline_has_passed()
show_course_sock = has_verified_mode and not is_already_verified and not deadline_has_passed
# Get the price of the course and format correctly
course_price = get_cosmetic_verified_display_price(course)
context = {
'show_course_sock': show_course_sock,
'course_price': course_price,
'course_id': course.id
}
return context
示例4: render_to_fragment
# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import is_enrolled_as_verified [as 别名]
def render_to_fragment(self, request, course_id, user_access, **kwargs):
"""
Renders a course message fragment for the specified course.
"""
course_key = CourseKey.from_string(course_id)
course = get_course_with_access(request.user, 'load', course_key)
# Get time until the start date, if already started, or no start date, value will be zero or negative
now = datetime.now(UTC)
already_started = course.start and now > course.start
days_until_start_string = "started" if already_started else format_timedelta(
course.start - now, locale=to_locale(get_language())
)
course_start_data = {
'course_start_date': format_date(course.start, locale=to_locale(get_language())),
'already_started': already_started,
'days_until_start_string': days_until_start_string
}
# Register the course home messages to be loaded on the page
_register_course_home_messages(request, course, user_access, course_start_data)
# Register course date alerts
for course_date_block in get_course_date_blocks(course, request.user):
course_date_block.register_alerts(request, course)
# Register a course goal message, if appropriate
# Only show the set course goal message for enrolled, unverified
# users that have not yet set a goal in a course that allows for
# verified statuses.
user_goal = get_course_goal(auth.get_user(request), course_key)
is_already_verified = CourseEnrollment.is_enrolled_as_verified(request.user, course_key)
if has_course_goal_permission(request, course_id, user_access) and not is_already_verified and not user_goal:
_register_course_goal_message(request, course)
# Grab the relevant messages
course_home_messages = list(CourseHomeMessages.user_messages(request))
# Pass in the url used to set a course goal
goal_api_url = get_goal_api_url(request)
# Grab the logo
image_src = 'course_experience/images/home_message_author.png'
context = {
'course_home_messages': course_home_messages,
'goal_api_url': goal_api_url,
'image_src': image_src,
'course_id': course_id,
'username': request.user.username,
}
html = render_to_string('course_experience/course-messages-fragment.html', context)
return Fragment(html)
示例5: _get_user_statuses
# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import is_enrolled_as_verified [as 别名]
def _get_user_statuses(user, course_key, checkpoint):
"""
Retrieve all the information we need to determine the user's group.
This will retrieve the information as a multi-get from the cache.
Args:
user (User): User object
course_key (CourseKey): Identifier for the course.
checkpoint (unicode): Location of the checkpoint in the course (serialized usage key)
Returns:
tuple of booleans of the form (is_verified, has_skipped, has_completed)
"""
enrollment_cache_key = CourseEnrollment.cache_key_name(user.id, unicode(course_key))
has_skipped_cache_key = SkippedReverification.cache_key_name(user.id, unicode(course_key))
verification_status_cache_key = VerificationStatus.cache_key_name(user.id, unicode(course_key))
# Try a multi-get from the cache
cache_values = cache.get_many([
enrollment_cache_key,
has_skipped_cache_key,
verification_status_cache_key
])
# Retrieve whether the user is enrolled in a verified mode.
is_verified = cache_values.get(enrollment_cache_key)
if is_verified is None:
is_verified = CourseEnrollment.is_enrolled_as_verified(user, course_key)
cache.set(enrollment_cache_key, is_verified)
# Retrieve whether the user has skipped any checkpoints in this course
has_skipped = cache_values.get(has_skipped_cache_key)
if has_skipped is None:
has_skipped = SkippedReverification.check_user_skipped_reverification_exists(user, course_key)
cache.set(has_skipped_cache_key, has_skipped)
# Retrieve the user's verification status for each checkpoint in the course.
verification_statuses = cache_values.get(verification_status_cache_key)
if verification_statuses is None:
verification_statuses = VerificationStatus.get_all_checkpoints(user.id, course_key)
cache.set(verification_status_cache_key, verification_statuses)
# Check whether the user has completed this checkpoint
# "Completion" here means *any* submission, regardless of its status
# since we want to show the user the content if they've submitted
# photos.
checkpoint = verification_statuses.get(checkpoint)
has_completed_check = bool(checkpoint)
return (is_verified, has_skipped, has_completed_check)
示例6: get
# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import is_enrolled_as_verified [as 别名]
def get(self, request, course_id):
"""
Displays the user's Learner Analytics for the specified course.
Arguments:
request: HTTP request
course_id (unicode): course id
"""
course_key = CourseKey.from_string(course_id)
if not ENABLE_DASHBOARD_TAB.is_enabled(course_key):
raise Http404
course = get_course_with_access(request.user, 'load', course_key, check_if_enrolled=True)
course_url_name = default_course_url_name(course.id)
course_url = reverse(course_url_name, kwargs={'course_id': unicode(course.id)})
is_verified = CourseEnrollment.is_enrolled_as_verified(request.user, course_key)
has_access = is_verified or request.user.is_staff
enrollment = CourseEnrollment.get_enrollment(request.user, course_key)
upgrade_price = None
upgrade_url = None
if enrollment and enrollment.upgrade_deadline:
upgrade_url = EcommerceService().upgrade_url(request.user, course_key)
upgrade_price = get_cosmetic_verified_display_price(course)
context = {
'upgrade_price': upgrade_price,
'upgrade_link': upgrade_url,
'course': course,
'course_url': course_url,
'disable_courseware_js': True,
'uses_pattern_library': True,
'is_self_paced': course.self_paced,
'is_verified': is_verified,
'has_access': has_access,
}
if (has_access):
grading_policy = course.grading_policy
(raw_grade_data, answered_percent, percent_grade) = self.get_grade_data(request.user, course_key, grading_policy['GRADE_CUTOFFS'])
raw_schedule_data = self.get_assignments_with_due_date(request, course_key)
grade_data, schedule_data = self.sort_grade_and_schedule_data(raw_grade_data, raw_schedule_data)
# TODO: LEARNER-3854: Fix hacked defaults with real error handling if implementing Learner Analytics.
try:
weekly_active_users = self.get_weekly_course_activity_count(course_key)
week_streak = self.consecutive_weeks_of_course_activity_for_user(
request.user.username, course_key
)
except Exception as e:
logging.exception(e)
weekly_active_users = 134
week_streak = 1
context.update({
'grading_policy': grading_policy,
'assignment_grades': grade_data,
'answered_percent': answered_percent,
'assignment_schedule': schedule_data,
'assignment_schedule_raw': raw_schedule_data,
'profile_image_urls': get_profile_image_urls_for_user(request.user, request),
'discussion_info': self.get_discussion_data(request, course_key),
'passing_grade': math.ceil(100 * course.lowest_passing_grade),
'percent_grade': math.ceil(100 * percent_grade),
'weekly_active_users': weekly_active_users,
'week_streak': week_streak,
})
return render_to_response('learner_analytics/dashboard.html', context)
示例7: is_certificate_valid
# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import is_enrolled_as_verified [as 别名]
def is_certificate_valid(certificate):
"""
Returns True if the student has a valid, verified certificate for this course, False otherwise.
"""
return CourseEnrollment.is_enrolled_as_verified(certificate.user, certificate.course_id) and certificate.is_valid()