def test_sharing_site_post_uses_wagtail_serve(self): self.create_sharing_site(hostname='hostname') request = self.make_request('/', HTTP_HOST='hostname', method='post') with patch('wagtailsharing.views.wagtail_serve') as wagtail_serve: ServeView.as_view()(request, request.path) wagtail_serve.assert_called_once_with(request, request.path)
def test_default_site_unpublished_page_raises_404(self): self.create_sharing_site(hostname="hostname") create_draft_page(self.default_site, title="unpublished") request = self.make_request("/unpublished/") with self.assertRaises(Http404): ServeView.as_view()(request, request.path)
def test_sharing_site_post_uses_wagtail_serve(self): self.create_sharing_site(hostname="hostname") request = self.make_request("/", HTTP_HOST="hostname", method="post") with patch("wagtailsharing.views.wagtail_serve") as wagtail_serve: ServeView.as_view()(request, request.path) wagtail_serve.assert_called_once_with(request, request.path)
def test_routable_page_index_route(self): self.create_sharing_site(hostname="hostname") create_draft_routable_page(self.default_site, title="routable") request = self.make_request("/routable/", HTTP_HOST="hostname") response = ServeView.as_view()(request, request.path) self.assertEqual(response.status_code, 200)
def test_sharing_site_unpublished_page_returns_200(self): self.create_sharing_site(hostname="hostname") create_draft_page(self.default_site, title="draft") request = self.make_request("/draft/", HTTP_HOST="hostname") response = ServeView.as_view()(request, request.path) self.assertEqual(response.status_code, 200)
def test_before_serve_page_hook_called(self): self.create_sharing_site(hostname='hostname') create_draft_page(self.default_site, title='page') with self.register_hook('before_serve_page', before_serve_page): request = self.make_request('/page/', HTTP_HOST='hostname') response = ServeView.as_view()(request, request.path) self.assertContains(response, 'before serve page hook')
def test_default_site_published_page_returns_200(self): self.create_sharing_site(hostname="hostname") page = create_draft_page(self.default_site, title="published") page.save_revision().publish() request = self.make_request("/published/") response = ServeView.as_view()(request, request.path) self.assertEqual(response.status_code, 200)
def test_routable_page_sub_route(self): self.create_sharing_site(hostname="hostname") create_draft_routable_page(self.default_site, title="routable") request = self.make_request("/routable/archive/year/2000/", HTTP_HOST="hostname") response = ServeView.as_view()(request, request.path) self.assertContains(response, "ARCHIVE BY YEAR: 2000")
def test_after_serve_shared_page_hook_called(self): self.create_sharing_site(hostname='hostname') create_draft_page(self.default_site, title='page') with self.register_hook('after_serve_shared_page', after_serve_shared_page): request = self.make_request('/page/', HTTP_HOST='hostname') response = ServeView.as_view()(request, request.path) self.assertEqual(response['test-hook-header'], 'foo')
def test_after_serve_shared_page_hook_returns_http_response(self): self.create_sharing_site(hostname='hostname') create_draft_page(self.default_site, title='page') with self.register_hook('after_serve_shared_page', after_hook_returns_http_response): request = self.make_request('/page/', HTTP_HOST='hostname') response = ServeView.as_view()(request, request.path) self.assertContains(response, 'returned by hook')
def test_after_serve_shared_page_hook_returns_http_response(self): self.create_sharing_site(hostname="hostname") create_draft_page(self.default_site, title="page") with self.register_hook("after_serve_shared_page", after_hook_returns_http_response): request = self.make_request("/page/", HTTP_HOST="hostname") response = ServeView.as_view()(request, request.path) self.assertContains(response, "returned by hook")
def test_after_serve_shared_page_hook_called(self): self.create_sharing_site(hostname="hostname") create_draft_page(self.default_site, title="page") with self.register_hook("after_serve_shared_page", after_hook_sets_response_header): request = self.make_request("/page/", HTTP_HOST="hostname") response = ServeView.as_view()(request, request.path) self.assertEqual(response["test-hook-header"], "foo")
def test_before_serve_shared_page_hook_called(self): self.create_sharing_site(hostname="hostname") create_draft_page(self.default_site, title="page") with self.register_hook("before_serve_shared_page", before_hook_changes_page_title): request = self.make_request("/page/", HTTP_HOST="hostname") response = ServeView.as_view()(request, request.path) self.assertContains(response, "hook changed title")
def test_sharing_site_draft_version_returns_draft_version(self): self.create_sharing_site(hostname="hostname") page = create_draft_page(self.default_site, title="original") page.save_revision().publish() page.title = "changed" page.save_revision() request = self.make_request("/original/", HTTP_HOST="hostname") response = ServeView.as_view()(request, request.path) self.assert_title_matches(response, "changed")
def test_default_site_draft_version_returns_published_version(self): self.create_sharing_site(hostname='hostname') page = create_draft_page(self.default_site, title='original') page.save_revision().publish() page.title = 'changed' page.save_revision() request = self.make_request('/original/') response = ServeView.as_view()(request, request.path) self.assert_title_matches(response, 'original')
def flagged_wagtail_template_view(flag_name, template_name): """View that serves Wagtail if a flag is set, and a template if not. This uses the wagtail-sharing ServeView to ensure that sharing works properly when viewing the page in Wagtail behind a flag. """ return FlaggedTemplateView.as_view( fallback=lambda request: ServeView.as_view()(request, request.path), flag_name=flag_name, template_name=template_name, condition=False)
def flagged_wagtail_only_view(flag_name, regex_path, url_name=None): """If flag is set, serve page from Wagtail, otherwise raise 404.""" def this_view_always_raises_http404(request, *args, **kwargs): raise Http404('flag {} not set'.format(flag_name)) return flagged_url( flag_name, regex_path, lambda request: ServeView.as_view()(request, request.path), fallback=this_view_always_raises_http404, name=url_name, )
def flagged_wagtail_template_view(flag_name, template_name): """View that serves Wagtail if a flag is set, and a template if not. This uses the wagtail-sharing ServeView to ensure that sharing works properly when viewing the page in Wagtail behind a flag. """ return FlaggedTemplateView.as_view( fallback=lambda request: ServeView.as_view()(request, request.path), flag_name=flag_name, template_name=template_name, condition=False )
template_name='owning-a-home/closing-disclosure/index.html'), name='closing-disclosure'), url(r'^owning-a-home/explore-rates/', TemplateView.as_view( template_name='owning-a-home/explore-rates/index.html'), name='explore-rates'), url(r'^owning-a-home/loan-estimate/$', TemplateView.as_view( template_name='owning-a-home/loan-estimate/index.html'), name='loan-estimate'), # Temporarily serve Wagtail OAH journey pages at `/process/` urls. # TODO: change to redirects after 2018 homebuying campaign. url( r'^owning-a-home/process/(?P<path>.*)$', lambda req, path: ServeView.as_view() (req, 'owning-a-home/{}'.format(path or 'prepare/')), ), # END TODO url(r'^know-before-you-owe/$', TemplateView.as_view(template_name='know-before-you-owe/index.html'), name='know-before-you-owe'), url(r'^know-before-you-owe/timeline/$', TemplateView.as_view( template_name='know-before-you-owe/timeline/index.html'), name='kbyo-timeline'), url(r'^know-before-you-owe/compare/$', TemplateView.as_view( template_name='know-before-you-owe/compare/index.html'), name='kbyo-compare'), url(r'^your-story/$', TemplateView.as_view(template_name='/your-story/index.html')),
def test_sharing_site_missing_page_raises_404(self): self.create_sharing_site(hostname="hostname") request = self.make_request("/missing/", HTTP_HOST="hostname") with self.assertRaises(Http404): ServeView.as_view()(request, request.path)
def test_no_sharing_site_exists_uses_wagtail_serve(self): request = self.make_request('/') with patch('wagtailsharing.views.wagtail_serve') as wagtail_serve: ServeView.as_view()(request, request.path) wagtail_serve.assert_called_once_with(request, request.path)
def test_no_sharing_site_exists_post_uses_wagtail_serve(self): request = self.make_request("/", method="post") with patch("wagtailsharing.views.wagtail_serve") as wagtail_serve: ServeView.as_view()(request, request.path) wagtail_serve.assert_called_once_with(request, request.path)
def test_default_site_missing_page_raises_404(self): self.create_sharing_site(hostname='hostname') request = self.make_request('/missing/') with self.assertRaises(Http404): ServeView.as_view()(request, request.path)
from django.urls import re_path from django.views.generic import TemplateView from wagtailsharing.views import ServeView urlpatterns = [ re_path( r'^journey', TemplateView.as_view( template_name='teachers_digital_platform/bb-tool.html' ) ), re_path( r'^$', lambda request: ServeView.as_view()(request, request.path) ) ]
include(fin_ed.urls_for_prefix('library-resources'))), url( r'^parents/(?P<path>.*)$', RedirectView.as_view(url='/money-as-you-grow/%(path)s', permanent=True)), url(r'fin-ed/privacy-act-statement/', include(fin_ed.urls_for_prefix('privacy-act-statement'))), url(r'^blog/(?P<path>.*)$', RedirectView.as_view(url='/about-us/blog/%(path)s', permanent=True)), url( r'^newsroom/(?P<path>.*)$', RedirectView.as_view(url='/about-us/newsroom/%(path)s', permanent=True)), flagged_url('WAGTAIL_ABOUT_US', r'^about-us/newsroom/press-resources/$', lambda req: ServeView.as_view()(req, req.path), fallback=TemplateView.as_view( template_name='newsroom/press-resources/index.html'), name='press-resources'), url( r'^the-bureau/(?P<path>.*)$', RedirectView.as_view(url='/about-us/the-bureau/%(path)s', permanent=True)), url( r'^about-us/leadership-calendar/(?P<path>.*)$', RedirectView.as_view( url='/about-us/the-bureau/leadership-calendar/%(path)s', permanent=True)), url( r'^doing-business-with-us/(?P<path>.*)$', RedirectView.as_view(url='/about-us/doing-business-with-us/%(path)s',
from wagtail.core.urls import ( serve_pattern, urlpatterns as wagtailcore_urlpatterns, ) from wagtailsharing.views import ServeView try: from django.urls import re_path except ImportError: from django.conf.urls import url as re_path urlpatterns = [ re_path(serve_pattern, ServeView.as_view(), name="wagtail_serve") if urlpattern.name == "wagtail_serve" else urlpattern for urlpattern in wagtailcore_urlpatterns ]
url(r'^parents/(?P<path>.*)$', RedirectView.as_view( url='/money-as-you-grow/%(path)s', permanent=True)), url(r'fin-ed/privacy-act-statement/', include(fin_ed.urls_for_prefix('privacy-act-statement'))), url(r'^blog/(?P<path>.*)$', RedirectView.as_view( url='/about-us/blog/%(path)s', permanent=True)), url(r'^newsroom/(?P<path>.*)$', RedirectView.as_view( url='/about-us/newsroom/%(path)s', permanent=True)), flagged_url( 'WAGTAIL_ABOUT_US', r'^about-us/newsroom/press-resources/$', lambda req: ServeView.as_view()(req, req.path), fallback=TemplateView.as_view( template_name='newsroom/press-resources/index.html'), name='press-resources'), url(r'^the-bureau/(?P<path>.*)$', RedirectView.as_view(url='/about-us/the-bureau/%(path)s', permanent=True) ), url(r'^about-us/leadership-calendar/(?P<path>.*)$', RedirectView.as_view( url='/about-us/the-bureau/leadership-calendar/%(path)s', permanent=True)), url(r'^doing-business-with-us/(?P<path>.*)$', RedirectView.as_view( url='/about-us/doing-business-with-us/%(path)s', permanent=True)),
name='mortgage-closing'), url(r'^owning-a-home/mortgage-estimate/', TemplateView.as_view( template_name='owning-a-home/mortgage-estimate/index.html', ), name='mortgage-estimate'), # Temporarily serve sheer version of OAH Journey sources page. # TODO: remove once page is migrated into Wagtail. flagged_url( 'OAH_JOURNEY_SHEER_SOURCE_PAGE', r'^owning-a-home/process/sources(?P<path>.*)$', lambda req, path: SheerTemplateView.as_view( template_engine='owning-a-home', template_name='process/sources{}index.html'.format(path or '/')) (req), fallback=lambda req, path: ServeView.as_view() (req, 'owning-a-home/sources{}'.format(path or '/')), ), # END TODO # Temporarily serve Wagtail OAH journey pages at `/process/` urls. # TODO: change to redirects after 2018 homebuying campaign. flagged_url( 'OAH_JOURNEY', r'^owning-a-home/process/(?P<path>.*)$', lambda req, path: ServeView.as_view() (req, 'owning-a-home/{}'.format(path or 'prepare/')), fallback=lambda req, path: SheerTemplateView.as_view( template_engine='owning-a-home', template_name='process/{}/index.html'.format(path or 'prepare')) (req)), # END TODO
from __future__ import absolute_import, unicode_literals from django.conf.urls import url try: from wagtail.core.urls import (serve_pattern, urlpatterns as wagtailcore_urlpatterns) except ImportError: # pragma: no cover; fallback for Wagtail <2.0 from wagtail.wagtailcore.urls import (serve_pattern, urlpatterns as wagtailcore_urlpatterns) from wagtailsharing.views import ServeView urlpatterns = [ url(serve_pattern, ServeView.as_view(), name='wagtail_serve') if urlpattern.name == 'wagtail_serve' else urlpattern for urlpattern in wagtailcore_urlpatterns ]
url(r'^owning-a-home/explore-rates/', TemplateView.as_view( template_name='owning-a-home/explore-rates/index.html'), name='explore-rates' ), url(r'^owning-a-home/loan-estimate/$', TemplateView.as_view( template_name='owning-a-home/loan-estimate/index.html'), name='loan-estimate' ), # Temporarily serve Wagtail OAH journey pages at `/process/` urls. # TODO: change to redirects after 2018 homebuying campaign. url(r'^owning-a-home/process/(?P<path>.*)$', lambda req, path: ServeView.as_view()( req, 'owning-a-home/{}'.format(path or 'prepare/') ), ), # END TODO url(r'^know-before-you-owe/$', TemplateView.as_view( template_name='know-before-you-owe/index.html'), name='know-before-you-owe'), url(r'^know-before-you-owe/timeline/$', TemplateView.as_view( template_name='know-before-you-owe/timeline/index.html'), name='kbyo-timeline'), url(r'^know-before-you-owe/compare/$', TemplateView.as_view( template_name='know-before-you-owe/compare/index.html'),