コード例 #1
0
ファイル: tests.py プロジェクト: danmorley/nhs-example
    def test_get_latest_live_release_returns_the_newest_published_release(
            self, mock_file_service):
        """
        A published release is one whose release_time is in the past.
        """
        release1_name = 'Old release'
        release1_date = timezone.now() + timedelta(days=-10)
        release1 = create_test_release(release_name=release1_name,
                                       release_date=release1_date)

        release2_name = 'Current release'
        release2_date = timezone.now() + timedelta(days=-1)
        release2 = create_test_release(release_name=release2_name,
                                       release_date=release2_date)

        release3_name = 'Future release'
        release3_date = timezone.now() + timedelta(days=+10)
        release3 = create_test_release(release_name=release3_name,
                                       release_date=release3_date)

        current_release = get_latest_live_release(release1.site_id)

        self.assertIsTrue(release1.release_date_has_passed())
        self.assertIsTrue(release2.release_date_has_passed())
        self.assertIsFalse(release3.release_date_has_passed())

        self.assertEqual(current_release.id, release2.id)
コード例 #2
0
ファイル: views.py プロジェクト: danmorley/nhs-example
def site_view(request, site_identifier):
    site = get_site_or_404(site_identifier)

    current_release = get_latest_live_release(site.site.pk)
    if not current_release:
        return JsonResponse(
            {'message': 'The current site has no live releases'}, status=404)

    populate_release_if_required(current_release)

    json_response = JsonResponse(current_release.get_content_for('site_json'))
    if current_release.content_status == 1:
        json_response['Cache-Control'] = 'max-age=900'
    return json_response
コード例 #3
0
ファイル: views.py プロジェクト: danmorley/nhs-example
def release_view(request, site_identifier, release_uuid):
    site = get_site_or_404(site_identifier)

    if release_uuid == 'current':
        release_object = get_latest_live_release(site.site.pk)
        if not release_object:
            return JsonResponse(
                {'message': 'The current site has no live releases'},
                status=404)
        release_uuid = release_object.uuid
    else:
        # Request is asking for a specific release
        release_object = get_release_object(release_uuid)
        if not release_object:
            return JsonResponse({'message': 'Release not found'}, status=404)

    setattr(site, 'release_uuid', release_uuid)
    serialized_site_data = SiteSerializer(site).data
    json_response = JsonResponse(serialized_site_data)
    if release_object.content_status == 1:
        json_response = JsonResponse(
            release_object.get_content_for('site_json'))
        json_response['Cache-Control'] = 'max-age=3600'
    return json_response
コード例 #4
0
ファイル: views.py プロジェクト: danmorley/nhs-example
def release_html(request, site_name):
    try:
        major_frontend_version = None
        site_setting = SiteSettings.objects.get(uid=site_name)
        current_release = get_latest_live_release(site_setting.site.pk)
        site_id = site_setting.site.id
        release_id = request.GET.get('id')
        if release_id:
            release = Release.objects.get(uuid=release_id)
        else:
            if 'is_preview' in request.GET:
                release = get_latest_release(site_id)
            else:
                if current_release:
                    release = current_release
                else:
                    old_site_setting = SiteSettings.objects.get(
                        uid='{}old'.format(site_name))
                    release = get_latest_live_release(old_site_setting.site.pk)
                    site_id = old_site_setting.site.id
    except ObjectDoesNotExist:
        return HttpResponse('Page Not Found', status=404)

    if getattr(request, 'path', None):
        # This redirection doesn't support multisite on different domain
        url = urlparse(request.get_full_path())
        path = url.path[:-1] if url.path[-1] == '/' else url.path
        site_redirects = Redirect.get_for_site(site_id)
        wagtail_redirect = site_redirects.filter(old_path=path).first()

        if wagtail_redirect:
            if wagtail_redirect.redirect_page:
                url = url._replace(
                    path=wagtail_redirect.redirect_page.specific.link_url)
                redirect_path = urlunparse(url)
            else:
                # Re-direct is to a link
                redirect_path = wagtail_redirect.redirect_link
            return redirect(redirect_path,
                            permanent=wagtail_redirect.is_permanent)

    frontend_name = release.get_frontend_id_display()
    matchObj = re.match(r'V([0-9]+)\..* - .*', frontend_name.replace('\n', ''),
                        re.I | re.M)
    if matchObj:
        try:
            major_frontend_version = int(matchObj.group(1))
        except ValueError:
            pass

    if release:
        frontend_id = release.frontend_id
        uuid = release.uuid
    else:
        # In this sc
        frontend_id = FrontendVersion.get_current_version()
        uuid = 'current'

    host = request.META['HTTP_HOST']
    if settings.CONTENT_STORE_ENDPOINT:
        content_store_endpoint = settings.CONTENT_STORE_ENDPOINT
    else:
        content_store_endpoint = get_protocol() + host + '/api'

    if major_frontend_version and major_frontend_version <= 1:
        # legacy to render frontend index.html before multisite have been implemented
        index = FrontendVersion.get_html_for_version(frontend_id)
        substituted_index = index.replace(
            "/static/css/",
            "/{}/version/css/{}/?file_name=".format(site_name, frontend_id))
        substituted_index = substituted_index.replace(
            "/static/js/",
            "/{}/version/js/{}/?file_name=".format(site_name, frontend_id))
        substituted_index = substituted_index.replace(
            "/manifest", "/{}/public/manifest".format(site_name))
        substituted_index = substituted_index.replace(
            "/favicon", "/{}/public/{}/favicon".format(site_name, frontend_id))
        substituted_index = substituted_index.replace(
            "/webtrends.min.js",
            "/{}/public/{}/webtrends.min.js".format(site_name, frontend_id))

        host = request.META['HTTP_HOST']
        if settings.CONTENT_STORE_ENDPOINT:
            content_store_endpoint = settings.CONTENT_STORE_ENDPOINT
        else:
            content_store_endpoint = get_protocol() + host + "/api"

        substituted_index = substituted_index.replace("%apiurl%",
                                                      content_store_endpoint)
        substituted_index = substituted_index.replace("%releaseid%", uuid)
        substituted_index = substituted_index.replace(
            "%adobe_tracking_url%", settings.ADOBE_TRACKING_URL)
        http_response = HttpResponse(substituted_index)
    else:
        template = Template(FrontendVersion.get_html_for_version(frontend_id))

        context = Context({
            'site_setting':
            site_setting,
            'api_url':
            content_store_endpoint,
            'release_id':
            uuid,
            'public_url':
            '/{}/public/{}'.format(site_name, frontend_id),
            'css_path':
            '/{}/version/css/{}/?file_name='.format(site_name, frontend_id),
            'js_path':
            '/{}/version/js/{}/?file_name='.format(site_name, frontend_id),
        })

        if settings.ENV == 'local':
            context['public_url'] = '/static'

        http_response = HttpResponse(template.render(context))

    if release and release.content_status == 1:
        http_response['Cache-Control'] = 'max-age=900'
    return http_response
コード例 #5
0
ファイル: views.py プロジェクト: danmorley/nhs-example
def release_view(request, release_id):
    release, live_release = None, None
    error_msg = ''
    pages = {}

    try:
        release = Release.objects.get(id=release_id)
    except Release.DoesNotExist:
        error_msg = 'This release id {} doesn\'t exist'.format(release_id)

    if release:
        pages_release = ReleasePage.objects.filter(release__id=release_id)

        # compare with the current live release if release is pending else compare with the previous frozen release
        live_pages_release = None
        if release.content_status == 0:
            # get live release content
            try:
                live_release = get_latest_live_release(release.site.id)
                live_pages_release = ReleasePage.objects.filter(
                    release__id=live_release.id)
            except (Release.DoesNotExist, AttributeError) as e:
                error_msg = 'No live release'
        else:
            live_release = Release.objects.filter(
                release_time__lte=release.release_time,
                site__id=release.site.id,
                content_status=1).exclude(
                    id=release.id).order_by('-release_time').first()
            if not live_release:
                error_msg = 'No live release'

        # Compare release with live release
        for page_release in pages_release:
            page_detail = page_release.get_page_detail_dict('new')

            if live_release:
                try:
                    live_page_release = ReleasePage.objects.get(
                        release__id=live_release.id,
                        revision__page=page_release.revision.page)
                    if live_page_release.revision.id != page_release.revision.id:
                        page_detail['status'] = 'updated'
                    else:
                        page_detail['status'] = 'unchanged'
                except ReleasePage.DoesNotExist:
                    pass

            pages.update({page_release.revision.page.id: page_detail})

        # Check if pages have been removed from live release
        if live_pages_release:
            for live_page_release in live_pages_release:
                if live_page_release.revision.page.id not in pages:
                    pages.update({
                        live_page_release.revision.page.id:
                        live_page_release.get_page_detail_dict('removed')
                    })

    return render(
        request, 'wagtailadmin/release/detail.html', {
            'release': release,
            'live_release': live_release,
            'pages': pages,
            'error_msg': error_msg,
        })