Beispiel #1
0
 def redirect_to(full_path):
     clean_url = get_clean_url(full_path)
     section_name = get_page_section(clean_url)
     deprecated_redirect_url = redirect_from_deprecated_url(section_name)
     if deprecated_redirect_url:
         print('Redirecting deprecated url {name}: {url}'.format(
             name=section_name, url=clean_url))
         return deprecated_redirect_url
def index(request):
    template = loader.get_template('new_index.html')
    context = {
        'DLAB_PROJECT_ID': settings.DLAB_PROJECT_ID,
        'PROJECT_DESCRIPTION_EXAMPLE_URL':
        settings.PROJECT_DESCRIPTION_EXAMPLE_URL,
        'POSITION_DESCRIPTION_EXAMPLE_URL':
        settings.POSITION_DESCRIPTION_EXAMPLE_URL,
        'STATIC_CDN_URL': settings.STATIC_CDN_URL,
        'HEADER_ALERT': settings.HEADER_ALERT,
        'SPONSORS_METADATA': settings.SPONSORS_METADATA,
        'userImgUrl': '',
        'PAYPAL_ENDPOINT': settings.PAYPAL_ENDPOINT,
        'PAYPAL_PAYEE': settings.PAYPAL_PAYEE,
        'PRESS_LINKS': settings.PRESS_LINKS,
        'organizationSnippet':
        loader.render_to_string('scripts/org_snippet.txt')
    }
    if settings.HOTJAR_APPLICATION_ID:
        context['hotjarScript'] = loader.render_to_string(
            'scripts/hotjar_snippet.txt',
            {'HOTJAR_APPLICATION_ID': settings.HOTJAR_APPLICATION_ID})

    GOOGLE_CONVERSION_ID = None
    page = get_page_section(request.get_full_path())
    if page and settings.GOOGLE_CONVERSION_IDS and page in settings.GOOGLE_CONVERSION_IDS:
        GOOGLE_CONVERSION_ID = settings.GOOGLE_CONVERSION_IDS[page]
    if settings.GOOGLE_PROPERTY_ID:
        context['googleScript'] = loader.render_to_string(
            'scripts/google_snippet.txt', {
                'GOOGLE_PROPERTY_ID': settings.GOOGLE_PROPERTY_ID,
                'GOOGLE_ADS_ID': settings.GOOGLE_ADS_ID,
                'GOOGLE_CONVERSION_ID': GOOGLE_CONVERSION_ID
            })

    if request.user.is_authenticated():
        contributor = Contributor.objects.get(id=request.user.id)
        context['userID'] = request.user.id
        context['emailVerified'] = contributor.email_verified
        context['email'] = contributor.email
        context['firstName'] = contributor.first_name
        context['lastName'] = contributor.last_name
        context['isStaff'] = contributor.is_staff
        context[
            'volunteeringUpForRenewal'] = contributor.is_up_for_volunteering_renewal(
            )
        thumbnails = ProjectFile.objects.filter(
            file_user=request.user.id,
            file_category=FileCategory.THUMBNAIL.value)
        if thumbnails:
            context['userImgUrl'] = thumbnails[0].file_url

    return HttpResponse(template.render(context, request))
Beispiel #3
0
 def test_get_page_section(self):
     expected = 'AboutEvent'
     self.assertEqual(
         expected,
         get_page_section('/index/?section=AboutEvent&id=test-slug'))
def index(request):
    template = loader.get_template('new_index.html')
    context = {
        'DLAB_PROJECT_ID': settings.DLAB_PROJECT_ID or '',
        'PROJECT_DESCRIPTION_EXAMPLE_URL': settings.PROJECT_DESCRIPTION_EXAMPLE_URL,
        'POSITION_DESCRIPTION_EXAMPLE_URL': settings.POSITION_DESCRIPTION_EXAMPLE_URL,
        'STATIC_CDN_URL': settings.STATIC_CDN_URL,
        'HEADER_ALERT': settings.HEADER_ALERT,
        'SPONSORS_METADATA': settings.SPONSORS_METADATA,
        'userImgUrl' : '',
        'PAYPAL_ENDPOINT': settings.PAYPAL_ENDPOINT,
        'PAYPAL_PAYEE': settings.PAYPAL_PAYEE,
        'PRESS_LINKS': settings.PRESS_LINKS,
        'organizationSnippet': loader.render_to_string('scripts/org_snippet.txt'),
        'GR_SITEKEY': settings.GR_SITEKEY,
        'FAVICON_PATH': settings.FAVICON_PATH,
        'BLOG_URL': settings.BLOG_URL,
        'EVENT_URL': settings.EVENT_URL,
        'PRIVACY_POLICY_URL': settings.PRIVACY_POLICY_URL
    }
    if settings.HOTJAR_APPLICATION_ID:
        context['hotjarScript'] = loader.render_to_string('scripts/hotjar_snippet.txt',
                                                          {'HOTJAR_APPLICATION_ID': settings.HOTJAR_APPLICATION_ID})

    GOOGLE_CONVERSION_ID = None
    page = get_page_section(request.get_full_path())
    if page and settings.GOOGLE_CONVERSION_IDS and page in settings.GOOGLE_CONVERSION_IDS:
        GOOGLE_CONVERSION_ID = settings.GOOGLE_CONVERSION_IDS[page]
    if settings.GOOGLE_PROPERTY_ID:
        context['googleScript'] = loader.render_to_string('scripts/google_snippet.txt',
                                                          {
                                                              'GOOGLE_PROPERTY_ID': settings.GOOGLE_PROPERTY_ID,
                                                              'GOOGLE_ADS_ID': settings.GOOGLE_ADS_ID,
                                                              'GOOGLE_CONVERSION_ID': GOOGLE_CONVERSION_ID
                                                          })

    if settings.GOOGLE_TAGS_ID:
        google_tag_context = {'GOOGLE_TAGS_ID': settings.GOOGLE_TAGS_ID}
        context['googleTagsHeadScript'] = loader.render_to_string('scripts/google_tag_manager_snippet_head.txt', google_tag_context)
        context['googleTagsBodyScript'] = loader.render_to_string('scripts/google_tag_manager_snippet_body.txt', google_tag_context)

    if hasattr(settings, 'SOCIAL_APPS_VISIBILITY'):
        context['SOCIAL_APPS_VISIBILITY'] = json.dumps(settings.SOCIAL_APPS_VISIBILITY)

    if hasattr(settings, 'HERE_CONFIG'):
        context['HERE_CONFIG'] = settings.HERE_CONFIG

    if request.user.is_authenticated():
        contributor = Contributor.objects.get(id=request.user.id)
        context['userID'] = request.user.id
        context['emailVerified'] = contributor.email_verified
        context['email'] = contributor.email
        context['firstName'] = contributor.first_name
        context['lastName'] = contributor.last_name
        context['isStaff'] = contributor.is_staff
        context['volunteeringUpForRenewal'] = contributor.is_up_for_volunteering_renewal()
        context['QIQO_IFRAME_URL'] = get_user_qiqo_iframe(contributor)

        thumbnail = ProjectFile.objects.filter(file_user=request.user.id,
                                               file_category=FileCategory.THUMBNAIL.value).first()
        if thumbnail:
            context['userImgUrl'] = thumbnail.file_url

    return HttpResponse(template.render(context, request))
 def test_get_page_section(self):
     expected = 'AboutEvent'
     self.assertEqual(expected, get_page_section('/events/test-slug'))