コード例 #1
0
ファイル: views.py プロジェクト: ratanasoth/edx-enterprise
    def notify_enrolled_learners(cls, enterprise_customer, request, course_id, users):
        """
        Notify learners about a course in which they've been enrolled.

        Args:
            enterprise_customer: The EnterpriseCustomer being linked to
            request: The HTTP request that's being processed
            course_id: The specific course the learners were enrolled in
            users: An iterable of the users or pending users who were enrolled
        """
        course_details = CourseCatalogApiClient(request.user).get_course_run(course_id)
        if not course_details:
            logging.warning(
                _(
                    "Course details were not found for course key {} - Course Catalog API returned nothing. "
                    "Proceeding with enrollment, but notifications won't be sent"
                ).format(course_id)
            )
            return
        course_url = course_details.get('marketing_url')
        if course_url is None:
            # If we didn't get a useful path to the course on a marketing site from the catalog API,
            # then we should build a path to the course on the LMS directly.
            course_url = get_reversed_url_by_site(
                request,
                enterprise_customer.site,
                'about_course',
                args=(course_id,),
            )
        course_name = course_details.get('title')

        try:
            course_start = parse_lms_api_datetime(course_details.get('start'))
        except (TypeError, ValueError):
            course_start = None
            logging.exception(
                "None or empty value passed as course start date.\nCourse Details:\n{course_details}".format(
                    course_details=course_details,
                )
            )

        with mail.get_connection() as email_conn:
            for user in users:
                send_email_notification_message(
                    user=user,
                    enrolled_in={
                        'name': course_name,
                        'url': course_url,
                        'type': 'course',
                        'start': course_start,
                    },
                    enterprise_customer=enterprise_customer,
                    email_connection=email_conn
                )
コード例 #2
0
ファイル: views.py プロジェクト: ratanasoth/edx-enterprise
    def get_enterprise_course_enrollment_page(self, request,
                                              enterprise_customer,
                                              course_details, course_modes):
        """
        Render enterprise specific course track selection page.
        """
        platform_name = configuration_helpers.get_value(
            'PLATFORM_NAME', settings.PLATFORM_NAME)
        course_start_date = ''
        if course_details['start']:
            course_start_date = parse(
                course_details['start']).strftime('%B %d, %Y')

        try:
            effort_hours = int(course_details['effort'].split(':')[0])
        except (AttributeError, ValueError):
            course_effort = ''
        else:
            course_effort = self.context_data['effort_hours_text'].format(
                hours=effort_hours)
        course_run = CourseCatalogApiClient(request.user).get_course_run(
            course_details['course_id'])

        course_modes = self.set_final_prices(course_modes, request)
        premium_modes = [mode for mode in course_modes if mode['premium']]

        try:
            organization = organizations_helpers.get_organization(
                course_details['org'])
            organization_logo = organization['logo'].url
            organization_name = organization['name']
        except (TypeError, ValidationError, ValueError):
            organization_logo = None
            organization_name = None

        context_data = {
            'page_title':
            self.context_data['page_title'],
            'LANGUAGE_CODE':
            get_language_from_request(request),
            'platform_name':
            platform_name,
            'course_id':
            course_details['course_id'],
            'course_name':
            course_details['name'],
            'course_organization':
            course_details['org'],
            'course_short_description':
            course_details['short_description'] or '',
            'course_pacing':
            self.pacing_options.get(course_details['pacing'], ''),
            'course_start_date':
            course_start_date,
            'course_image_uri':
            course_details['media']['course_image']['uri'],
            'enterprise_customer':
            enterprise_customer,
            'enterprise_welcome_text':
            self.context_data['enterprise_welcome_text'].format(
                enterprise_customer_name=enterprise_customer.name,
                platform_name=platform_name,
                strong_start='<strong>',
                strong_end='</strong>',
            ),
            'confirmation_text':
            self.context_data['confirmation_text'],
            'starts_at_text':
            self.context_data['starts_at_text'],
            'view_course_details_text':
            self.context_data['view_course_details_text'],
            'select_mode_text':
            self.context_data['select_mode_text'],
            'price_text':
            self.context_data['price_text'],
            'continue_link_text':
            self.context_data['continue_link_text'],
            'course_modes':
            filter_audit_course_modes(enterprise_customer, course_modes),
            'course_effort':
            course_effort,
            'level_text':
            self.context_data['level_text'],
            'effort_text':
            self.context_data['effort_text'],
            'course_overview':
            course_details['overview'],
            'organization_logo':
            organization_logo,
            'organization_name':
            organization_name,
            'course_level_type':
            course_run.get('level_type', ''),
            'close_modal_button_text':
            self.context_data['close_modal_button_text'],
            'premium_modes':
            premium_modes,
        }
        return render(request,
                      'enterprise/enterprise_course_enrollment_page.html',
                      context=context_data)