Author: batiste.bieler
Date: Mon Mar 2 15:04:33 2009
New Revision: 381
Modified:
trunk/pages/managers.py
trunk/pages/tests.py
Log:
Simplify code
Modified: trunk/pages/managers.py
==============================================================================
--- trunk/pages/managers.py (original)
+++ trunk/pages/managers.py Mon Mar 2 15:04:33 2009
@@ -125,7 +125,7 @@
content_dict = dict([(c['language'], c['body']) for c in content])
if language in content_dict:
return content_dict[language]
- # requested language not found. Try other languages on after
+ # requested language not found. Try other languages one after
# the other
elif language_fallback:
for lang in settings.PAGE_LANGUAGES:
@@ -138,18 +138,11 @@
Returns the latest Content slug object that match the given slug
for
the current site domain.
"""
+ content = self.filter(type='slug', body=slug)
+ if settings.PAGE_USE_SITE_ID:
+ content = content.filter(page__sites__id=settings.SITE_ID)
try:
- if settings.PAGE_USE_SITE_ID:
- content = self.filter(
- type='slug',
- body=slug,
- page__sites__id=settings.SITE_ID,
- ).select_related('page').latest(latest_by)
- else:
- content = self.filter(
- type='slug',
- body=slug,
- ).select_related('page').latest(latest_by)
+ content = content.latest(latest_by)
except self.model.DoesNotExist:
return None
else:
Modified: trunk/pages/tests.py
==============================================================================
--- trunk/pages/tests.py (original)
+++ trunk/pages/tests.py Mon Mar 2 15:04:33 2009
@@ -122,6 +122,7 @@
"""
setattr(settings, "SITE_ID", 2)
setattr(settings, "PAGE_USE_SITE_ID", True)
+
c = Client()
c.login(username= 'batiste', password='b')
page_data = self.get_new_page_data()
@@ -137,8 +138,11 @@
page_data["sites"] = [3]
response = c.post('/admin/pages/page/add/', page_data)
self.assertRedirects(response, '/admin/pages/page/')
+
+ # we cannot get a slug that doesn't exist
+ content = Content.objects.get_content_slug_by_slug("this doesn't
exist")
- # we cannot get the data posted on another site (why not after
all?)
+ # we cannot get the data posted on another site
content =
Content.objects.get_content_slug_by_slug(page_data['slug'])
self.assertEqual(content, None)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pinax-updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/pinax-updates?hl=en
-~----------~----~----~----~------~----~------~--~---