コード例 #1
0
def get_footer_navigation_links():
    """
    Helper to get navigation links for the footer

    Returns:
        List, which contains dictionaries of url
    """

    faq_link = FAQS_LINK_AR if get_language() == ARABIC_LANGUAGE_CODE else FAQS_LINK

    links = [
        (marketing_link('ABOUT'), _('About'), TARGET_SELF),
        (reverse('our_team'), _('Our Team'), TARGET_SELF),
        (marketing_link('CONTACT'), _('Contact'), TARGET_SELF),
        (settings.SUPPORT_LINK, _('Support'), TARGET_BLANK),
        (faq_link, _('FAQ\'s'), TARGET_BLANK),
        (marketing_link('PRIVACY'), _('Privacy Policy'), TARGET_SELF),
        (marketing_link('TOS'), _('Terms of Use'), TARGET_SELF),
    ]

    return [
        {
            'url': link_url,
            'title': link_title,
            'target': target,
        }
        for link_url, link_title, target in links
    ]
コード例 #2
0
def _footer_business_links(language=settings.LANGUAGE_CODE):
    """Return the business links to display in the footer. """
    platform_name = configuration_helpers.get_value('platform_name',
                                                    settings.PLATFORM_NAME)
    links = [
        ("about", (marketing_link("ABOUT"), _("About"))),
        ("enterprise", (_add_enterprise_marketing_footer_query_params(
            marketing_link("ENTERPRISE")),
                        _("{platform_name} for Business").format(
                            platform_name=platform_name))),
    ]

    if language == settings.LANGUAGE_CODE:
        links.append(
            ('affiliates', (marketing_link("AFFILIATES"), _("Affiliates"))))
        links.append(
            ('openedx', (_footer_openedx_link()["url"], _("Open edX"))))
        links.append(('careers', (marketing_link("CAREERS"), _("Careers"))))
        links.append(("news", (marketing_link("NEWS"), _("News"))))

    return [{
        "name": link_name,
        "title": link_title,
        "url": link_url,
    } for link_name, (link_url, link_title) in links
            if link_url and link_url != "#"]
コード例 #3
0
 def test_override_marketing_link_valid(self):
     expected_link = 'https://edx.org'
     # test marketing site on
     with patch.dict('django.conf.settings.FEATURES',
                     {'ENABLE_MKTG_SITE': True}):
         link = marketing_link('TOS')
         assert link == expected_link
     # test marketing site off
     with patch.dict('django.conf.settings.FEATURES',
                     {'ENABLE_MKTG_SITE': False}):
         link = marketing_link('TOS')
         assert link == expected_link
コード例 #4
0
 def test_override_marketing_link_invalid(self):
     expected_link = '#'
     # test marketing site on
     with patch.dict('django.conf.settings.FEATURES',
                     {'ENABLE_MKTG_SITE': True}):
         link = marketing_link('TOS')
         self.assertEqual(link, expected_link)
     # test marketing site off
     with patch.dict('django.conf.settings.FEATURES',
                     {'ENABLE_MKTG_SITE': False}):
         link = marketing_link('TOS')
         self.assertEqual(link, expected_link)
コード例 #5
0
def _footer_more_info_links(language=settings.LANGUAGE_CODE):
    """Return the More Information footer links (e.g. terms of service). """

    links = [
        ("terms_of_service_and_honor_code",
         (marketing_link("TOS_AND_HONOR"),
          _("Terms of Service & Honor Code"))),
        ("privacy_policy", (marketing_link("PRIVACY"), _("Privacy Policy"))),
        ("accessibility_policy", (marketing_link("ACCESSIBILITY"),
                                  _("Accessibility Policy"))),
    ]

    # Backwards compatibility: If a combined "terms of service and honor code"
    # link isn't provided, add separate TOS and honor code links.
    tos_and_honor_link = marketing_link("TOS_AND_HONOR")
    if not (tos_and_honor_link and tos_and_honor_link != "#"):
        links.extend([
            ("terms_of_service", (marketing_link("TOS"),
                                  _("Terms of Service"))),
            ("honor_code", (marketing_link("HONOR"), _("Honor Code"))),
        ])

    if language == settings.LANGUAGE_CODE:
        links.append(("trademarks", (marketing_link("TRADEMARKS"),
                                     _("Trademark Policy"))))
        links.append(("sitemap", (marketing_link("SITE_MAP"), _("Sitemap"))))

    return [{
        "name": link_name,
        "title": link_title,
        "url": link_url,
    } for link_name, (link_url, link_title) in links
            if link_url and link_url != "#"]
コード例 #6
0
def _footer_legal_links(language=settings.LANGUAGE_CODE):
    """Return the legal footer links (e.g. terms of service). """

    links = [
        ("terms_of_service_and_honor_code",
         (marketing_link("TOS_AND_HONOR"),
          _("Terms of Service & Honor Code"))),
        ("privacy_policy", (marketing_link("PRIVACY"), _("Privacy Policy"))),
        ("accessibility_policy", (marketing_link("ACCESSIBILITY"),
                                  _("Accessibility Policy"))),
        ("media_kit", (marketing_link("MEDIA_KIT"), _("Media Kit"))),
    ]

    # Backwards compatibility: If a combined "terms of service and honor code"
    # link isn't provided, add separate TOS and honor code links.
    tos_and_honor_link = marketing_link("TOS_AND_HONOR")
    if not (tos_and_honor_link and tos_and_honor_link != "#"):
        links.extend([
            ("terms_of_service", (marketing_link("TOS"),
                                  _("Terms of Service"))),
            ("honor_code", (marketing_link("HONOR"), _("Honor Code"))),
        ])

    if language == settings.LANGUAGE_CODE:
        position = _find_position_of_link(links, 'accessibility_policy')
        links.insert(position,
                     ("sitemap", (marketing_link("SITE_MAP"), _("Sitemap"))))

    return [{
        "name": link_name,
        "title": link_title,
        "url": link_url,
    } for link_name, (link_url, link_title) in links
            if link_url and link_url != "#"]
コード例 #7
0
    def test_link_map_url_reverse(self):
        url_link_map = {
            'ABOUT': 'dashboard',
            'BAD_URL': 'foobarbaz',
        }

        with patch.dict('django.conf.settings.FEATURES',
                        {'ENABLE_MKTG_SITE': False}):
            with override_settings(MKTG_URL_LINK_MAP=url_link_map):
                link = marketing_link('ABOUT')
                assert link == '/dashboard'

                link = marketing_link('BAD_URL')
                assert link == '#'
コード例 #8
0
 def test_marketing_link(self):
     with override_settings(
             MKTG_URL_LINK_MAP={'ABOUT': self._get_test_url_name()}):
         # test marketing site on
         with patch.dict('django.conf.settings.FEATURES',
                         {'ENABLE_MKTG_SITE': True}):
             expected_link = 'https://dummy-root/about-us'
             link = marketing_link('ABOUT')
             assert link == expected_link
         # test marketing site off
         with patch.dict('django.conf.settings.FEATURES',
                         {'ENABLE_MKTG_SITE': False}):
             expected_link = reverse(self._get_test_url_name())
             link = marketing_link('ABOUT')
             assert link == expected_link
コード例 #9
0
def _footer_connect_links(language=settings.LANGUAGE_CODE):
    """Return the connect links to display in the footer. """
    links = [
        ("blog", (marketing_link("BLOG"), _("Blog"))),
        ("contact", (_build_support_form_url(full_path=True),
                     _("Contact Us"))),
        ("help-center", (_build_help_center_url(language), _("Help Center"))),
    ]

    if language == settings.LANGUAGE_CODE:
        links.append(
            ("media_kit", (marketing_link("MEDIA_KIT"), _("Media Kit"))))
        links.append(("donate", (marketing_link("DONATE"), _("Donate"))))

    return [{
        "name": link_name,
        "title": link_title,
        "url": link_url,
    } for link_name, (link_url, link_title) in links
            if link_url and link_url != "#"]
コード例 #10
0
def _footer_navigation_links(language=settings.LANGUAGE_CODE):
    """Return the navigation links to display in the footer. """
    platform_name = configuration_helpers.get_value('platform_name',
                                                    settings.PLATFORM_NAME)
    links = [
        ("about", (marketing_link("ABOUT"), _("About"))),
        ("enterprise", (marketing_link("ENTERPRISE"),
                        _("{platform_name} for Business").format(
                            platform_name=platform_name))),
        ("blog", (marketing_link("BLOG"), _("Blog"))),
        ("help-center", (_build_help_center_url(language), _("Help Center"))),
        ("contact", (_build_support_form_url(), _("Contact"))),
        ("careers", (marketing_link("CAREERS"), _("Careers"))),
        ("donate", (marketing_link("DONATE"), _("Donate"))),
    ]

    if language == settings.LANGUAGE_CODE:
        position = _find_position_of_link(links, 'blog')
        links.insert(position, ("news", (marketing_link("NEWS"), _("News"))))

    return [{
        "name": link_name,
        "title": link_title,
        "url": link_url,
    } for link_name, (link_url, link_title) in links
            if link_url and link_url != "#"]
コード例 #11
0
    def _add_honor_code_field(self, form_desc, required=True):
        """
        Add an honor code field to a form description.

        Arguments:
            form_desc: A form description

        Keyword Arguments:
            required (bool): Whether this field is required; defaults to True
        """

        # Translators: 'Terms of Service' is a legal document users must agree to
        # in order to register a new account.

        terms_field_label = Text(
            _("""
        By continuing, you confirm that you are at least 16 years of age and agree to
        Al-Dabbagh Group’s {terms_of_service_link_start}{terms_of_service}{terms_of_service_link_end} and
        {privacy_link_start}{privacy_policy}{privacy_link_end}.
        """)).format(
                terms_of_service=_(u'Terms of Use'),
                terms_of_service_link_start=HTML(
                    u'<a href="{terms_url}" rel="noopener" target="_blank">').
                format(terms_url=marketing_link('TOS')),
                terms_of_service_link_end=HTML('</a>'),
                privacy_policy=_(u'Privacy Policy'),
                privacy_link_start=HTML(
                    u'<a href="{privacy_url}" rel="noopener" target="_blank">'
                ).format(privacy_url=marketing_link('PRIVACY')),
                privacy_link_end=HTML('</a>'))

        form_desc.add_field('honor_code',
                            label=terms_field_label,
                            field_type='plaintext',
                            default=False,
                            required=required)
コード例 #12
0
def get_base_template_context(site):
    """
    Dict with entries needed for all templates that use the base template.
    """
    # When on LMS and a dashboard is available, use that as the dashboard url.
    # Otherwise, use the home url instead.
    try:
        dashboard_url = reverse('dashboard')
    except NoReverseMatch:
        dashboard_url = reverse('home')

    if hasattr(site, 'configuration'):
        site_configuration_values = site.configuration.site_values
    else:
        site_configuration_values = {}

    return {
        # Platform information
        'homepage_url':
        marketing_link('ROOT'),
        'dashboard_url':
        dashboard_url,
        'template_revision':
        getattr(settings, 'EDX_PLATFORM_REVISION', None),
        'platform_name':
        get_config_value_from_site_or_settings(
            'PLATFORM_NAME',
            site=site,
            site_config_name='platform_name',
        ),
        'contact_email':
        get_config_value_from_site_or_settings(
            'CONTACT_EMAIL', site=site, site_config_name='contact_email'),
        'contact_mailing_address':
        get_config_value_from_site_or_settings(
            'CONTACT_MAILING_ADDRESS',
            site=site,
            site_config_name='contact_mailing_address'),
        'social_media_urls':
        get_config_value_from_site_or_settings('SOCIAL_MEDIA_FOOTER_URLS',
                                               site=site),
        'mobile_store_urls':
        get_config_value_from_site_or_settings('MOBILE_STORE_URLS', site=site),
        'logo_url':
        get_logo_url_for_email(),
        'site_configuration_values':
        site_configuration_values,
    }
コード例 #13
0
def courses(request):
    """
    Render the "find courses" page. If the marketing site is enabled, redirect
    to that. Otherwise, if subdomain branding is on, this is the university
    profile page. Otherwise, it's the edX courseware.views.views.courses page
    """
    enable_mktg_site = configuration_helpers.get_value(
        'ENABLE_MKTG_SITE', settings.FEATURES.get('ENABLE_MKTG_SITE', False))

    if enable_mktg_site:
        return redirect(marketing_link('COURSES'), permanent=True)

    if not settings.FEATURES.get('COURSES_ARE_BROWSABLE'):
        raise Http404

    #  we do not expect this case to be reached in cases where
    #  marketing is enabled or the courses are not browsable
    return courseware_views.courses(request)
コード例 #14
0
def get_url(name):
    """
    Lookup and return page url, lookup is performed in the following order

    1. get url, If configuration URL override exists, return it
    2. Otherwise return the marketing URL.

    :return: string containing page url.
    """
    # If a configuration URL override exists, return it.  Otherwise return the marketing URL.
    configuration_url = get_configuration_url(name)
    if configuration_url != EMPTY_URL:
        return configuration_url

    # get marketing link, if marketing is disabled then platform url will be used instead.
    url = marketing_link(name)

    return url or EMPTY_URL
コード例 #15
0
    def _add_terms_of_service_field(self, form_desc, required=True):
        """Add a terms of service field to a form description.
        Arguments:
            form_desc: A form description
        Keyword Arguments:
            required (bool): Whether this field is required; defaults to True
        """
        # Translators: This is a legal document users must agree to
        # in order to register a new account.
        terms_label = _("Terms of Service")
        terms_link = marketing_link("TOS")

        # Translators: "Terms of service" is a legal document users must agree to
        # in order to register a new account.
        label = Text(
            _("I agree to the {platform_name} {tos_link_start}{terms_of_service}{tos_link_end}"
              )).format(
                  platform_name=configuration_helpers.get_value(
                      "PLATFORM_NAME", settings.PLATFORM_NAME),
                  terms_of_service=terms_label,
                  tos_link_start=HTML(
                      "<a href='{terms_link}' rel='noopener' target='_blank'>"
                  ).format(terms_link=terms_link),
                  tos_link_end=HTML("</a>"),
              )

        # Translators: "Terms of service" is a legal document users must agree to
        # in order to register a new account.
        error_msg = _(
            "You must agree to the {platform_name} {terms_of_service}").format(
                platform_name=configuration_helpers.get_value(
                    "PLATFORM_NAME", settings.PLATFORM_NAME),
                terms_of_service=terms_label)

        form_desc.add_field(
            "terms_of_service",
            label=label,
            field_type="checkbox",
            default=False,
            required=required,
            error_messages={"required": error_msg},
        )
コード例 #16
0
ファイル: test_email.py プロジェクト: rick0ne/edx-platform
    def assertChangeEmailSent(self, test_body_type):
        """
        Assert that the correct email was sent to confirm an email change, the same
        email contents should be sent to both old and new addresses
        """
        self.check_confirm_email_change(
            'email_change_successful.html', {
                'old_email': self.user.email,
                'new_email': self.pending_change_request.new_email
            })

        # Must have two items in outbox: one for old email, another for new email
        self.assertEqual(len(mail.outbox), 2)

        use_https = self.request.is_secure()
        if settings.FEATURES['ENABLE_MKTG_SITE']:
            contact_link = marketing_link('CONTACT')
        else:
            contact_link = '{protocol}://{site}{link}'.format(
                protocol='https' if use_https else 'http',
                site=settings.SITE_NAME,
                link=reverse('contact'),
            )

        # Verifying contents
        for msg in mail.outbox:
            self.assertEqual(msg.subject, self.email_subject)

            body_text = {
                'plain_text': msg.body,
                'html': msg.alternatives[0][0]
            }
            assert test_body_type in body_text

            body_to_be_tested = body_text[test_body_type]
            for fragment in self.email_fragments:
                self.assertIn(fragment, body_to_be_tested)

            self.assertIn(contact_link, body_to_be_tested)
コード例 #17
0
def learner_profile_context(request, profile_username, user_is_staff):
    """Context for the learner profile page.

    Args:
        logged_in_user (object): Logged In user.
        profile_username (str): username of user whose profile is requested.
        user_is_staff (bool): Logged In user has staff access.
        build_absolute_uri_func ():

    Returns:
        dict

    Raises:
        ObjectDoesNotExist: the specified profile_username does not exist.
    """
    profile_user = User.objects.get(username=profile_username)
    logged_in_user = request.user

    own_profile = (logged_in_user.username == profile_username)

    account_settings_data = get_account_settings(request,
                                                 [profile_username])[0]

    preferences_data = get_user_preferences(profile_user, profile_username)

    #Added by Mahendra
    user_enrolled_courses = CourseEnrollment.objects.filter(
        user_id=profile_user.id, is_active=1)
    cid = []
    for courseid in user_enrolled_courses:
        course_id = courseid.course_id
        cid.append(course_id)

    instructor_courses = CourseAccessRole.objects.filter(
        user_id=profile_user.id, role='instructor')
    instrsuctor_courseids = []
    for courseid in instructor_courses:
        course_id = courseid.course_id
        instrsuctor_courseids.append(course_id)

    try:
        userprofile_extrainfo = extrafields.objects.get(
            user_id=profile_user.id)
    except Exception as e:
        userprofile_extrainfo, created = extrafields.objects.get_or_create(
            user_id=profile_user.id)

    course_data = CourseOverview.objects.all().filter(
        pk__in=cid).order_by('start')[::-1]
    instructor_course_delivered = CourseOverview.objects.all().filter(
        pk__in=instrsuctor_courseids).order_by('start')[::-1]
    experience_data = experience.objects.all().filter(
        user=profile_user.id).order_by('-year')
    education_data = education.objects.all().filter(
        user=profile_user.id).order_by('-id')
    award_data = awards.objects.all().filter(
        user=profile_user.id).order_by('-year')
    research_data = research_papers.objects.all().filter(
        user=profile_user.id).order_by('-id')
    featured_data = media_featured.objects.all().filter(
        user=profile_user.id).order_by('-id')
    clinic_hospital_data = clinic_hospital_address.objects.all().filter(
        user=profile_user.id).order_by('-id')
    userprofile = UserProfile.objects.get(user_id=profile_user.id)
    course_certificates = certificate_api.get_certificates_for_user(
        profile_user.username)
    awareness_videos = healthcare_awareness_videos.objects.all().filter(
        user=profile_user.id)

    context = {
        'own_profile':
        own_profile,
        'platform_name':
        configuration_helpers.get_value('platform_name',
                                        settings.PLATFORM_NAME),
        'data': {
            'profile_user_id':
            profile_user.id,
            'default_public_account_fields':
            settings.ACCOUNT_VISIBILITY_CONFIGURATION['public_fields'],
            'default_visibility':
            settings.ACCOUNT_VISIBILITY_CONFIGURATION['default_visibility'],
            'accounts_api_url':
            reverse("accounts_api", kwargs={'username': profile_username}),
            'preferences_api_url':
            reverse('preferences_api', kwargs={'username': profile_username}),
            'preferences_data':
            preferences_data,
            'account_settings_data':
            account_settings_data,
            'profile_image_upload_url':
            reverse('profile_image_upload',
                    kwargs={'username': profile_username}),
            'profile_image_remove_url':
            reverse('profile_image_remove',
                    kwargs={'username': profile_username}),
            'profile_image_max_bytes':
            settings.PROFILE_IMAGE_MAX_BYTES,
            'profile_image_min_bytes':
            settings.PROFILE_IMAGE_MIN_BYTES,
            'account_settings_page_url':
            reverse('account_settings'),
            'has_preferences_access':
            (logged_in_user.username == profile_username or user_is_staff),
            'own_profile':
            own_profile,
            'country_options':
            list(countries),
            'find_courses_url':
            marketing_link('COURSES'),
            'language_options':
            settings.ALL_LANGUAGES,
            'badges_logo':
            staticfiles_storage.url('certificates/images/backpack-logo.png'),
            'badges_icon':
            staticfiles_storage.url(
                'certificates/images/ico-mozillaopenbadges.png'),
            'backpack_ui_img':
            staticfiles_storage.url('certificates/images/backpack-ui.png'),
            'platform_name':
            configuration_helpers.get_value('platform_name',
                                            settings.PLATFORM_NAME),
            'social_platforms':
            settings.SOCIAL_PLATFORMS,
        },
        'show_program_listing':
        ProgramsApiConfig.is_enabled(),
        'show_dashboard_tabs':
        True,
        'disable_courseware_js':
        True,
        'nav_hidden':
        True,
        'records_url':
        get_credentials_records_url(),
        #Added by Mahendra
        'instructor_courses':
        instructor_course_delivered,
        'courses':
        course_data,
        'experience_data':
        experience_data,
        'education_data':
        education_data,
        'award_data':
        award_data,
        'research_data':
        research_data,
        'featured_data':
        featured_data,
        'clinic_hospital_data':
        clinic_hospital_data,
        'userprofile':
        userprofile,
        'userprofile_extrainfo':
        userprofile_extrainfo,
        'course_certificates':
        course_certificates,
        'awareness_videos':
        awareness_videos,
    }

    if own_profile or user_is_staff:
        achievements_fragment = LearnerAchievementsFragmentView(
        ).render_to_fragment(
            request,
            username=profile_user.username,
            own_profile=own_profile,
        )
        context['achievements_fragment'] = achievements_fragment

    if badges_enabled():
        context['data']['badges_api_url'] = reverse(
            "badges_api:user_assertions",
            kwargs={'username': profile_username})

    return context
コード例 #18
0
    def _add_honor_code_field(self, form_desc, required=True):
        """Add an honor code field to a form description.
        Arguments:
            form_desc: A form description
        Keyword Arguments:
            required (bool): Whether this field is required; defaults to True
        """

        separate_honor_and_tos = self._is_field_visible("terms_of_service")
        # Separate terms of service and honor code checkboxes
        if separate_honor_and_tos:
            terms_label = _(u"Honor Code")
            terms_link = marketing_link("HONOR")

        # Combine terms of service and honor code checkboxes
        else:
            # Translators: This is a legal document users must agree to
            # in order to register a new account.
            terms_label = _(u"Terms of Service and Honor Code")
            terms_link = marketing_link("HONOR")

        # Translators: "Terms of Service" is a legal document users must agree to
        # in order to register a new account.
        label = Text(_(
            u"I agree to the {platform_name} {terms_of_service_link_start}{terms_of_service}{terms_of_service_link_end}"
        )).format(
            platform_name=configuration_helpers.get_value("PLATFORM_NAME", settings.PLATFORM_NAME),
            terms_of_service=terms_label,
            terms_of_service_link_start=HTML(u"<a href='{terms_link}' rel='noopener' target='_blank'>").format(
                terms_link=terms_link
            ),
            terms_of_service_link_end=HTML("</a>"),
        )

        # Translators: "Terms of Service" is a legal document users must agree to
        # in order to register a new account.
        error_msg = _(u"You must agree to the {platform_name} {terms_of_service}").format(
            platform_name=configuration_helpers.get_value("PLATFORM_NAME", settings.PLATFORM_NAME),
            terms_of_service=terms_label
        )
        field_type = 'checkbox'

        if not separate_honor_and_tos:
            field_type = 'plaintext'

            pp_link = marketing_link("PRIVACY")
            label = Text(_(
                u"By creating an account, you agree to the \
                  {terms_of_service_link_start}{terms_of_service}{terms_of_service_link_end} \
                  and you acknowledge that {platform_name} and each Member process your personal data in accordance \
                  with the {privacy_policy_link_start}Privacy Policy{privacy_policy_link_end}."
            )).format(
                platform_name=configuration_helpers.get_value("PLATFORM_NAME", settings.PLATFORM_NAME),
                terms_of_service=terms_label,
                terms_of_service_link_start=HTML(u"<a href='{terms_url}' rel='noopener' target='_blank'>").format(
                    terms_url=terms_link
                ),
                terms_of_service_link_end=HTML("</a>"),
                privacy_policy_link_start=HTML(u"<a href='{pp_url}' rel='noopener' target='_blank'>").format(
                    pp_url=pp_link
                ),
                privacy_policy_link_end=HTML("</a>"),
            )

        form_desc.add_field(
            "honor_code",
            label=label,
            field_type=field_type,
            default=False,
            required=required,
            error_messages={
                "required": error_msg
            },
        )
コード例 #19
0
def learner_profile_context(request, profile_username, user_is_staff):
    """Context for the learner profile page.

    Args:
        logged_in_user (object): Logged In user.
        profile_username (str): username of user whose profile is requested.
        user_is_staff (bool): Logged In user has staff access.
        build_absolute_uri_func ():

    Returns:
        dict

    Raises:
        ObjectDoesNotExist: the specified profile_username does not exist.
    """
    profile_user = User.objects.get(username=profile_username)
    logged_in_user = request.user

    own_profile = (logged_in_user.username == profile_username)

    account_settings_data = get_account_settings(request,
                                                 [profile_username])[0]

    preferences_data = get_user_preferences(profile_user, profile_username)

    context = {
        'own_profile':
        own_profile,
        'platform_name':
        configuration_helpers.get_value('platform_name',
                                        settings.PLATFORM_NAME),
        'data': {
            'profile_user_id':
            profile_user.id,
            'default_public_account_fields':
            settings.ACCOUNT_VISIBILITY_CONFIGURATION['public_fields'],
            'default_visibility':
            settings.ACCOUNT_VISIBILITY_CONFIGURATION['default_visibility'],
            'accounts_api_url':
            reverse("accounts_api", kwargs={'username': profile_username}),
            'preferences_api_url':
            reverse('preferences_api', kwargs={'username': profile_username}),
            'preferences_data':
            preferences_data,
            'account_settings_data':
            account_settings_data,
            'profile_image_upload_url':
            reverse('profile_image_upload',
                    kwargs={'username': profile_username}),
            'profile_image_remove_url':
            reverse('profile_image_remove',
                    kwargs={'username': profile_username}),
            'profile_image_max_bytes':
            settings.PROFILE_IMAGE_MAX_BYTES,
            'profile_image_min_bytes':
            settings.PROFILE_IMAGE_MIN_BYTES,
            'account_settings_page_url':
            reverse('account_settings'),
            'has_preferences_access':
            (logged_in_user.username == profile_username or user_is_staff),
            'own_profile':
            own_profile,
            'country_options':
            list(countries),
            'find_courses_url':
            marketing_link('COURSES'),
            'language_options':
            settings.ALL_LANGUAGES,
            'badges_logo':
            staticfiles_storage.url('certificates/images/backpack-logo.png'),
            'badges_icon':
            staticfiles_storage.url(
                'certificates/images/ico-mozillaopenbadges.png'),
            'backpack_ui_img':
            staticfiles_storage.url('certificates/images/backpack-ui.png'),
            'platform_name':
            configuration_helpers.get_value('platform_name',
                                            settings.PLATFORM_NAME),
            'social_platforms':
            settings.SOCIAL_PLATFORMS,
        },
        'show_program_listing':
        ProgramsApiConfig.is_enabled(),
        'show_dashboard_tabs':
        True,
        'disable_courseware_js':
        True,
        'nav_hidden':
        True,
        'records_url':
        get_credentials_records_url(),
    }

    if own_profile or user_is_staff:
        achievements_fragment = LearnerAchievementsFragmentView(
        ).render_to_fragment(
            request,
            username=profile_user.username,
            own_profile=own_profile,
        )
        context['achievements_fragment'] = achievements_fragment

    if badges_enabled():
        context['data']['badges_api_url'] = reverse(
            "badges_api:user_assertions",
            kwargs={'username': profile_username})

    return context
コード例 #20
0
def confirm_email_change(request, key):
    """
    User requested a new e-mail. This is called when the activation
    link is clicked. We confirm with the old e-mail, and update
    """
    with transaction.atomic():
        try:
            pec = PendingEmailChange.objects.get(activation_key=key)
        except PendingEmailChange.DoesNotExist:
            response = render_to_response("invalid_email_key.html", {})
            transaction.set_rollback(True)
            return response

        user = pec.user
        address_context = {
            'old_email': user.email,
            'new_email': pec.new_email
        }

        if len(User.objects.filter(email=pec.new_email)) != 0:
            response = render_to_response("email_exists.html", {})
            transaction.set_rollback(True)
            return response

        use_https = request.is_secure()
        if settings.FEATURES['ENABLE_MKTG_SITE']:
            contact_link = marketing_link('CONTACT')
        else:
            contact_link = '{protocol}://{site}{link}'.format(
                protocol='https' if use_https else 'http',
                site=configuration_helpers.get_value('SITE_NAME', settings.SITE_NAME),
                link=reverse('contact'),
            )

        site = Site.objects.get_current()
        message_context = get_base_template_context(site)
        message_context.update({
            'old_email': user.email,
            'new_email': pec.new_email,
            'contact_link': contact_link,
            'from_address': configuration_helpers.get_value('email_from_address', settings.DEFAULT_FROM_EMAIL),
        })

        msg = EmailChangeConfirmation().personalize(
            recipient=Recipient(user.id, user.email),
            language=preferences_api.get_user_preference(user, LANGUAGE_KEY),
            user_context=message_context,
        )

        u_prof = UserProfile.objects.get(user=user)
        meta = u_prof.get_meta()
        if 'old_emails' not in meta:
            meta['old_emails'] = []
        meta['old_emails'].append([user.email, datetime.datetime.now(UTC).isoformat()])
        u_prof.set_meta(meta)
        u_prof.save()
        # Send it to the old email...
        try:
            ace.send(msg)
        except Exception:  # pylint: disable=broad-except
            log.warning('Unable to send confirmation email to old address', exc_info=True)
            response = render_to_response("email_change_failed.html", {'email': user.email})
            transaction.set_rollback(True)
            return response

        user.email = pec.new_email
        user.save()
        pec.delete()
        # And send it to the new email...
        msg.recipient = Recipient(user.id, pec.new_email)
        try:
            ace.send(msg)
        except Exception:  # pylint: disable=broad-except
            log.warning('Unable to send confirmation email to new address', exc_info=True)
            response = render_to_response("email_change_failed.html", {'email': pec.new_email})
            transaction.set_rollback(True)
            return response

        response = render_to_response("email_change_successful.html", address_context)
        return response