def get_object(self): """ Return the requested course object, if the user has appropriate permissions. """ overview = course_detail( self.request, self.request.user.username, CourseKey.from_string(self.kwargs['course_key_string']), ) if self.request.user.is_anonymous: mode = None is_active = False else: mode, is_active = CourseEnrollment.enrollment_mode_for_user( overview.effective_user, overview.id) overview.enrollment = {'mode': mode, 'is_active': is_active} if not is_active: user_has_access = allow_public_access(overview, [COURSE_VISIBILITY_PUBLIC]) else: user_has_access = True overview.user_has_access = user_has_access overview.user_has_staff_access = has_access(self.request.user, 'staff', overview).has_access return overview
def _register_course_home_messages(request, course, user_access, course_start_data): """ Register messages to be shown in the course home content page. """ allow_anonymous = allow_public_access(course, [COURSE_VISIBILITY_PUBLIC]) if user_access['is_anonymous'] and not allow_anonymous: CourseHomeMessages.register_info_message( request, Text( _(u'{sign_in_link} or {register_link} and then enroll in this course.' ) ).format( sign_in_link=HTML( u'<a href="/login?next={current_url}">{sign_in_label}</a>' ).format( sign_in_label=_('Sign in'), current_url=urlquote_plus(request.path), ), register_link=HTML( u'<a href="/register?next={current_url}">{register_label}</a>' ).format( register_label=_('register'), current_url=urlquote_plus(request.path), )), title=Text( _('You must be enrolled in the course to see course content.') )) if not user_access['is_anonymous'] and not user_access['is_staff'] and \ not user_access['is_enrolled']: title = Text(_(u'Welcome to {course_display_name}')).format( course_display_name=course.display_name) if CourseMode.is_masters_only(course.id): # if a course is a Master's only course, we will not offer user ability to self-enroll CourseHomeMessages.register_info_message( request, Text( _('You must be enrolled in the course to see course content. ' 'Please contact your degree administrator or edX Support if you have questions.' )), title=title) elif not course.invitation_only: CourseHomeMessages.register_info_message( request, Text( _(u'{open_enroll_link}Enroll now{close_enroll_link} to access the full course.' )).format(open_enroll_link=HTML( '<button class="enroll-btn btn-link">'), close_enroll_link=HTML('</button>')), title=title) else: CourseHomeMessages.register_info_message( request, Text( _('You must be enrolled in the course to see course content.' )), )
def _register_course_home_messages(request, course, user_access, course_start_data): """ Register messages to be shown in the course home content page. """ allow_anonymous = allow_public_access(course, [COURSE_VISIBILITY_PUBLIC]) if user_access['is_anonymous'] and not allow_anonymous: sign_in_or_register_text = (_(u'{sign_in_link} or {register_link} and then enroll in this course.') if not CourseMode.is_masters_only(course.id) else _(u'{sign_in_link} or {register_link}.')) CourseHomeMessages.register_info_message( request, Text(sign_in_or_register_text).format( sign_in_link=HTML(u'<a href="/login?next={current_url}">{sign_in_label}</a>').format( sign_in_label=_('Sign in'), current_url=urlquote_plus(request.path), ), register_link=HTML(u'<a href="/register?next={current_url}">{register_label}</a>').format( register_label=_('register'), current_url=urlquote_plus(request.path), ) ), title=Text(_('You must be enrolled in the course to see course content.')) ) if not user_access['is_anonymous'] and not user_access['is_staff'] and \ not user_access['is_enrolled']: title = Text(_(u'Welcome to {course_display_name}')).format( course_display_name=course.display_name ) if CourseMode.is_masters_only(course.id): # if a course is a Master's only course, we will not offer user ability to self-enroll CourseHomeMessages.register_info_message( request, Text(_('You must be enrolled in the course to see course content. ' 'Please contact your degree administrator or edX Support if you have questions.')), title=title ) elif not course.invitation_only: CourseHomeMessages.register_info_message( request, Text(_( u'{open_enroll_link}Enroll now{close_enroll_link} to access the full course.' )).format( open_enroll_link=HTML('<button class="enroll-btn btn-link">'), close_enroll_link=HTML('</button>') ), title=title ) else: CourseHomeMessages.register_info_message( request, Text(_('You must be enrolled in the course to see course content.')), )
def render(self, request): """ Render the index page. """ self._redirect_if_needed_to_pay_for_course() self._prefetch_and_bind_course(request) if self.course.has_children_at_depth(CONTENT_DEPTH): self._reset_section_to_exam_if_required() self.chapter = self._find_chapter() self.section = self._find_section() if self.chapter and self.section: self._redirect_if_not_requested_section() self._save_positions() self._prefetch_and_bind_section() check_content_start_date_for_masquerade_user( self.course_key, self.effective_user, request, self.course.start, self.chapter.start, self.section.start) if not request.user.is_authenticated: qs = urllib.urlencode({ 'course_id': self.course_key, 'enrollment_action': 'enroll', 'email_opt_in': False, }) allow_anonymous = allow_public_access(self.course, [COURSE_VISIBILITY_PUBLIC]) if not allow_anonymous: PageLevelMessages.register_warning_message( request, Text( _("You are not signed in. To see additional course content, {sign_in_link} or " "{register_link}, and enroll in this course.")). format( sign_in_link=HTML( '<a href="{url}">{sign_in_label}</a>').format( sign_in_label=_('sign in'), url='{}?{}'.format(reverse('signin_user'), qs), ), register_link=HTML( '<a href="/{url}">{register_label}</a>').format( register_label=_('register'), url='{}?{}'.format(reverse('register_user'), qs), ), )) return render_to_response('courseware/courseware.html', self._create_courseware_context(request))
def render(self, request): """ Render the index page. """ self._redirect_if_needed_to_pay_for_course() self._prefetch_and_bind_course(request) if self.course.has_children_at_depth(CONTENT_DEPTH): self._reset_section_to_exam_if_required() self.chapter = self._find_chapter() self.section = self._find_section() if self.chapter and self.section: self._redirect_if_not_requested_section() self._save_positions() self._prefetch_and_bind_section() check_content_start_date_for_masquerade_user(self.course_key, self.effective_user, request, self.course.start, self.chapter.start, self.section.start) if not request.user.is_authenticated: qs = urllib.urlencode({ 'course_id': self.course_key, 'enrollment_action': 'enroll', 'email_opt_in': False, }) allow_anonymous = allow_public_access(self.course, [COURSE_VISIBILITY_PUBLIC]) if not allow_anonymous: PageLevelMessages.register_warning_message( request, Text(_(u"You are not signed in. To see additional course content, {sign_in_link} or " u"{register_link}, and enroll in this course.")).format( sign_in_link=HTML(u'<a href="{url}">{sign_in_label}</a>').format( sign_in_label=_('sign in'), url='{}?{}'.format(reverse('signin_user'), qs), ), register_link=HTML(u'<a href="/{url}">{register_label}</a>').format( register_label=_('register'), url=u'{}?{}'.format(reverse('register_user'), qs), ), ) ) return render_to_response('courseware/courseware.html', self._create_courseware_context(request))
def _register_course_home_messages(request, course, user_access, course_start_data): """ Register messages to be shown in the course home content page. """ allow_anonymous = allow_public_access(course, [COURSE_VISIBILITY_PUBLIC]) if user_access['is_anonymous'] and not allow_anonymous: CourseHomeMessages.register_info_message( request, Text(_( u'{sign_in_link} or {register_link} and then enroll in this course.' )).format( sign_in_link=HTML(u'<a href="/login?next={current_url}">{sign_in_label}</a>').format( sign_in_label=_('Sign in'), current_url=urlquote_plus(request.path), ), register_link=HTML(u'<a href="/register?next={current_url}">{register_label}</a>').format( register_label=_('register'), current_url=urlquote_plus(request.path), ) ), title=Text(_('You must be enrolled in the course to see course content.')) ) if not user_access['is_anonymous'] and not user_access['is_staff'] and \ not user_access['is_enrolled']: if not course.invitation_only: CourseHomeMessages.register_info_message( request, Text(_( u'{open_enroll_link}Enroll now{close_enroll_link} to access the full course.' )).format( open_enroll_link=HTML('<button class="enroll-btn btn-link">'), close_enroll_link=HTML('</button>') ), title=Text(_(u'Welcome to {course_display_name}')).format( course_display_name=course.display_name ) ) else: CourseHomeMessages.register_info_message( request, Text(_('You must be enrolled in the course to see course content.')), )