Merge branch 'nathan3d-page_url'

pull/538/head
Matt Westcott 2014-08-12 17:17:39 +01:00
commit 876976fc04
8 zmienionych plików z 100 dodań i 4 usunięć

Wyświetl plik

@ -1,6 +1,10 @@
Changelog
=========
0.6 (xx.xx.20xx)
~~~~~~~~~~~~~~~~
* Fix: Page URL generation now returns correct URLs for sites that have the main 'serve' view rooted somewhere other than '/'
0.5 (01.08.2014)
~~~~~~~~~~~~~~~~
* Added multiple image uploader

Wyświetl plik

@ -30,6 +30,7 @@ Contributors
* Jeffrey Hearn
* Robert Clark
* Tim Heap
* Nathan Brizendine
Translators
===========

Wyświetl plik

@ -0,0 +1,22 @@
==========================================
Wagtail 0.6 release notes - IN DEVELOPMENT
==========================================
.. contents::
:local:
:depth: 1
What's new
==========
Minor features
~~~~~~~~~~~~~~
Bug fixes
~~~~~~~~~
* Page URL generation now returns correct URLs for sites that have the main 'serve' view rooted somewhere other than '/'.
Upgrade considerations
======================

Wyświetl plik

@ -5,6 +5,7 @@ Release notes
:maxdepth: 1
roadmap
0.6
0.5
0.4.1
0.4

Wyświetl plik

@ -0,0 +1,19 @@
"""An alternative urlconf module where Wagtail front-end URLs
are rooted at '/site/' rather than '/'"""
from django.conf.urls import patterns, include, url
from wagtail.wagtailcore import urls as wagtail_urls
from wagtail.wagtailadmin import urls as wagtailadmin_urls
from wagtail.wagtaildocs import urls as wagtaildocs_urls
from wagtail.wagtailimages import urls as wagtailimages_urls
from wagtail.wagtailsearch import urls as wagtailsearch_urls
urlpatterns = patterns('',
url(r'^admin/', include(wagtailadmin_urls)),
url(r'^search/', include(wagtailsearch_urls)),
url(r'^documents/', include(wagtaildocs_urls)),
url(r'^images/', include(wagtailimages_urls)),
url(r'^site/', include(wagtail_urls)),
)

Wyświetl plik

@ -13,6 +13,7 @@ from django.http import Http404
from django.core.cache import cache
from django.core.handlers.wsgi import WSGIRequest
from django.core.handlers.base import BaseHandler
from django.core.urlresolvers import reverse
from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.models import Group
from django.conf import settings
@ -488,7 +489,7 @@ class Page(six.with_metaclass(PageBase, MP_Node, ClusterableModel, indexed.Index
"""Return the full URL (including protocol / domain) to this page, or None if it is not routable"""
for (id, root_path, root_url) in Site.get_site_root_paths():
if self.url_path.startswith(root_path):
return root_url + self.url_path[len(root_path) - 1:]
return root_url + reverse('wagtail_serve', args=(self.url_path[len(root_path):],))
@property
def url(self):
@ -503,7 +504,7 @@ class Page(six.with_metaclass(PageBase, MP_Node, ClusterableModel, indexed.Index
root_paths = Site.get_site_root_paths()
for (id, root_path, root_url) in Site.get_site_root_paths():
if self.url_path.startswith(root_path):
return ('' if len(root_paths) == 1 else root_url) + self.url_path[len(root_path) - 1:]
return ('' if len(root_paths) == 1 else root_url) + reverse('wagtail_serve', args=(self.url_path[len(root_path):],))
def relative_url(self, current_site):
"""
@ -513,7 +514,7 @@ class Page(six.with_metaclass(PageBase, MP_Node, ClusterableModel, indexed.Index
"""
for (id, root_path, root_url) in Site.get_site_root_paths():
if self.url_path.startswith(root_path):
return ('' if current_site.id == id else root_url) + self.url_path[len(root_path) - 1:]
return ('' if current_site.id == id else root_url) + reverse('wagtail_serve', args=(self.url_path[len(root_path):],))
@classmethod
def search(cls, query_string, show_unpublished=False, search_title_only=False, extra_filters={}, prefetch_related=[], path=None):

Wyświetl plik

@ -1,6 +1,7 @@
import warnings
from django.test import TestCase, Client
from django.test.utils import override_settings
from django.http import HttpRequest, Http404
from wagtail.utils.deprecation import RemovedInWagtail06Warning
@ -100,6 +101,16 @@ class TestSiteRouting(TestCase):
class TestRouting(TestCase):
fixtures = ['test.json']
# need to clear urlresolver caches before/after tests, because we override ROOT_URLCONF
# in some tests here
def setUp(self):
from django.core.urlresolvers import clear_url_caches
clear_url_caches()
def tearDown(self):
from django.core.urlresolvers import clear_url_caches
clear_url_caches()
def test_urls(self):
default_site = Site.objects.get(is_default_site=True)
homepage = Page.objects.get(url_path='/home/')
@ -134,6 +145,21 @@ class TestRouting(TestCase):
self.assertEqual(christmas_page.relative_url(default_site), 'http://events.example.com/christmas/')
self.assertEqual(christmas_page.relative_url(events_site), '/christmas/')
@override_settings(ROOT_URLCONF='wagtail.tests.non_root_urls')
def test_urls_with_non_root_urlconf(self):
default_site = Site.objects.get(is_default_site=True)
homepage = Page.objects.get(url_path='/home/')
christmas_page = Page.objects.get(url_path='/home/events/christmas/')
# Basic installation only has one site configured, so page.url will return local URLs
self.assertEqual(homepage.full_url, 'http://localhost/site/')
self.assertEqual(homepage.url, '/site/')
self.assertEqual(homepage.relative_url(default_site), '/site/')
self.assertEqual(christmas_page.full_url, 'http://localhost/site/events/christmas/')
self.assertEqual(christmas_page.url, '/site/events/christmas/')
self.assertEqual(christmas_page.relative_url(default_site), '/site/events/christmas/')
def test_request_routing(self):
homepage = Page.objects.get(url_path='/home/')
christmas_page = EventPage.objects.get(url_path='/home/events/christmas/')
@ -179,6 +205,16 @@ class TestServeView(TestCase):
from django.core.cache import cache
cache.delete('wagtail_site_root_paths')
# also need to clear urlresolver caches before/after tests, because we override
# ROOT_URLCONF in some tests here
from django.core.urlresolvers import clear_url_caches
clear_url_caches()
def tearDown(self):
from django.core.urlresolvers import clear_url_caches
clear_url_caches()
def test_serve(self):
response = self.client.get('/events/christmas/')
@ -190,6 +226,18 @@ class TestServeView(TestCase):
self.assertContains(response, '<h1>Christmas</h1>')
self.assertContains(response, '<h2>Event</h2>')
@override_settings(ROOT_URLCONF='wagtail.tests.non_root_urls')
def test_serve_with_non_root_urls(self):
response = self.client.get('/site/events/christmas/')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.templates[0].name, 'tests/event_page.html')
christmas_page = EventPage.objects.get(url_path='/home/events/christmas/')
self.assertEqual(response.context['self'], christmas_page)
self.assertContains(response, '<h1>Christmas</h1>')
self.assertContains(response, '<h2>Event</h2>')
def test_serve_unknown_page_returns_404(self):
response = self.client.get('/events/quinquagesima/')
self.assertEqual(response.status_code, 404)

Wyświetl plik

@ -10,5 +10,5 @@ urlpatterns = [
# a '/'. If a trailing slash is not present, we leave CommonMiddleware to
# handle it as usual (i.e. redirect it to the trailing slash version if
# settings.APPEND_SLASH is True)
url(r'^((?:[\w\-]+/)*)$', views.serve)
url(r'^((?:[\w\-]+/)*)$', views.serve, name='wagtail_serve')
]