-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for 885 and potentially also 493, 770. #912
Changes from 4 commits
234f773
54b2815
dd83195
ba38d2e
e78d9a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,6 +117,16 @@ def __unicode__(self): | |
if title is None: | ||
title = u"" | ||
return u'%s' % (title,) | ||
|
||
def get_absolute_url(self, language=None, fallback=True): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh yeah baby :) |
||
if self.is_home(): | ||
return reverse('pages-root') | ||
if settings.CMS_FLAT_URLS: | ||
path = self.get_slug(language, fallback) | ||
return urlutils.urljoin(reverse('pages-root'), path) | ||
# else | ||
path = self.get_path(language, fallback) | ||
return urlutils.urljoin(reverse('pages-root'), path) | ||
|
||
def move_page(self, target, position='first-child'): | ||
"""Called from admin interface when page is moved. Should be used on | ||
|
@@ -531,37 +541,6 @@ def get_languages(self): | |
self.all_languages = list(self.all_languages) | ||
self.all_languages.sort() | ||
return self.all_languages | ||
|
||
def get_absolute_url(self, language=None, fallback=True): | ||
try: | ||
if self.is_home(): | ||
return reverse('pages-root') | ||
except NoHomeFound: | ||
pass | ||
if settings.CMS_FLAT_URLS: | ||
path = self.get_slug(language, fallback) | ||
else: | ||
path = self.get_path(language, fallback) | ||
if hasattr(self, "home_cut_cache") and self.home_cut_cache: | ||
if not self.get_title_obj_attribute("has_url_overwrite", language, fallback) and path: | ||
path = "/".join(path.split("/")[1:]) | ||
else: | ||
home_pk = None | ||
try: | ||
home_pk = self.home_pk_cache | ||
except NoHomeFound: | ||
pass | ||
""" | ||
this is pain slow! the code fetches all ancestors for all pages | ||
and then checks if the root node is a home_pk, if yes, it cuts off the first path part. | ||
""" | ||
ancestors = self.get_cached_ancestors(ascending=True) | ||
# sometimes there are no ancestors | ||
if len(ancestors) != 0: | ||
if self.parent_id and ancestors[-1].pk == home_pk and not self.get_title_obj_attribute("has_url_overwrite", language, fallback) and path: | ||
path = "/".join(path.split("/")[1:]) | ||
|
||
return urlutils.urljoin(reverse('pages-root'), path) | ||
|
||
def get_cached_ancestors(self, ascending=True): | ||
if ascending: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,19 @@ def update_title_paths(instance, **kwargs): | |
page_moved.connect(update_title_paths, sender=Page, dispatch_uid="cms.title.update_path") | ||
|
||
|
||
def update_title(title): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this have to do with the beans? |
||
parent_page_id = title.page.parent_id | ||
slug = u'%s' % title.slug | ||
|
||
if title.page.is_home(): | ||
title.path = '' | ||
else: | ||
title.path = u'%s' % slug | ||
if parent_page_id: | ||
parent_title = Title.objects.get_title(parent_page_id, language=title.language, language_fallback=True) | ||
if parent_title: | ||
title.path = (u'%s/%s' % (parent_title.path, slug)).lstrip("/") | ||
|
||
def pre_save_title(instance, raw, **kwargs): | ||
"""Save old state to instance and setup path | ||
""" | ||
|
@@ -64,14 +77,7 @@ def pre_save_title(instance, raw, **kwargs): | |
if instance.has_url_overwrite and instance.path: | ||
instance.path = instance.path.strip(" /") | ||
else: | ||
parent_page = instance.page.parent | ||
slug = u'%s' % instance.slug | ||
|
||
instance.path = u'%s' % slug | ||
if parent_page: | ||
parent_title = Title.objects.get_title(parent_page, language=instance.language, language_fallback=True) | ||
if parent_title: | ||
instance.path = (u'%s/%s' % (parent_title.path, slug)).lstrip("/") | ||
update_title(instance) | ||
|
||
signals.pre_save.connect(pre_save_title, sender=Title, dispatch_uid="cms.title.presave") | ||
|
||
|
@@ -198,6 +204,10 @@ def post_save_page(instance, raw, created, **kwargs): | |
# tell moderator something was happen with this page | ||
from cms.utils.moderator import page_changed | ||
page_changed(instance, old_page) | ||
for page in instance.get_descendants(): | ||
for title in page.title_set.all(): | ||
update_title(title) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, nevermind, makes sense now. |
||
title.save() | ||
|
||
|
||
def update_placeholders(instance, **kwargs): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,7 +130,7 @@ def test_details_view(self): | |
""" | ||
with SettingsOverride(**self.render_settings()): | ||
from cms.views import details | ||
response = details(self.get_request(self.test_page), slug=self.test_page.get_slug()) | ||
response = details(self.get_request(self.test_page), '') | ||
r = self.strip_rendered(response.content) | ||
self.assertEqual(r, u'|'+self.test_data['text_main']+u'|'+self.test_data['text_sub']+u'|') | ||
|
||
|
@@ -231,35 +231,38 @@ def test_inherit_placeholder(self): | |
|
||
def test_detail_view_404_when_no_language_is_found(self): | ||
with SettingsOverride(TEMPLATE_CONTEXT_PROCESSORS=[], | ||
CMS_LANGUAGES=[( 'klingon', 'Klingon' ), | ||
( 'elvish', 'Elvish' )]): | ||
CMS_LANGUAGES=[ | ||
('x-klingon', 'Klingon'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit picker ;o) |
||
('x-elvish', 'Elvish') | ||
]): | ||
from cms.views import details | ||
request = AttributeObject( | ||
REQUEST={'language': 'elvish'}, | ||
REQUEST={'language': 'x-elvish'}, | ||
GET=[], | ||
session={}, | ||
path='/', | ||
user=self.test_user, | ||
current_page=None, | ||
method='GET', | ||
) | ||
self.assertRaises(Http404, details, request, slug=self.test_page.get_slug()) | ||
self.assertRaises(Http404, details, request, '') | ||
|
||
def test_detail_view_fallsback_language(self): | ||
def test_detail_view_fallback_language(self): | ||
''' | ||
Ask for a page in elvish (doesn't exist), and assert that it fallsback | ||
to English | ||
''' | ||
with SettingsOverride(TEMPLATE_CONTEXT_PROCESSORS=[], | ||
CMS_LANGUAGE_CONF={ | ||
'elvish': ['klingon', 'en',] | ||
'x-elvish': ['x-klingon', 'en',] | ||
}, | ||
CMS_LANGUAGES=[( 'klingon', 'Klingon' ), | ||
( 'elvish', 'Elvish' ) | ||
CMS_LANGUAGES=[ | ||
('x-klingon', 'Klingon'), | ||
('x-elvish', 'Elvish'), | ||
]): | ||
from cms.views import details | ||
request = AttributeObject( | ||
REQUEST={'language': 'elvish'}, | ||
REQUEST={'language': 'x-elvish'}, | ||
GET=[], | ||
session={}, | ||
path='/', | ||
|
@@ -268,7 +271,7 @@ def test_detail_view_fallsback_language(self): | |
method='GET', | ||
) | ||
|
||
response = details(request, slug=self.test_page.get_slug()) | ||
response = details(request, '') | ||
self.assertTrue(isinstance(response,HttpResponseRedirect)) | ||
|
||
def test_extra_context_isolation(self): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,15 +65,15 @@ def get_page_from_path(path, preview=False): | |
q = Q(title_set__slug=path) | ||
else: | ||
q = Q(title_set__path=path) | ||
if home: | ||
# if we have a home, also search for all paths prefixed with the | ||
# home slug that are on the same tree as home, since home isn't ussually | ||
# called with it's slug, thus it's children don't have the home bit in | ||
# the request either, thus we need to re-add it. | ||
q2 = Q() | ||
q2 = Q(title_set__path='%s/%s' % (home.get_slug(), path)) | ||
q2 &= Q(tree_id=home.tree_id) | ||
q |= q2 | ||
# if home: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not simply delete the block? |
||
# # if we have a home, also search for all paths prefixed with the | ||
# # home slug that are on the same tree as home, since home isn't ussually | ||
# # called with it's slug, thus it's children don't have the home bit in | ||
# # the request either, thus we need to re-add it. | ||
# q2 = Q() | ||
# q2 = Q(title_set__path='%s/%s' % (home.get_slug(), path)) | ||
# q2 &= Q(tree_id=home.tree_id) | ||
# q |= q2 | ||
try: | ||
page = pages.filter(q).distinct().get() | ||
except Page.DoesNotExist: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this means it was only used in get_absolute_url?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed, a short search over the project showed that it was set here and then used by get_absolute_url. It basically does the same I wanted to do for 885
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM :)