Author: batiste.bieler
Date: Mon Mar 2 15:53:58 2009
New Revision: 383
Modified:
trunk/pages/managers.py
trunk/pages/tests.py
Log:
Change the way the content are fetched with a custom SQL request. I have
not tested this with MySQL.
Modified: trunk/pages/managers.py
==============================================================================
--- trunk/pages/managers.py (original)
+++ trunk/pages/managers.py Mon Mar 2 15:53:58 2009
@@ -1,8 +1,7 @@
# -*- coding: utf-8 -*-
import itertools
from datetime import datetime
-
-from django.db import models
+from django.db import models, connection
from django.contrib.sites.managers import CurrentSiteManager
from django.contrib.sites.models import Site
from django.db.models import Q
@@ -115,14 +114,19 @@
pass
content = self.create(page=page, language=language, body=body,
type=cnttype)
- def get_content(self, page, language, cnttype, language_fallback=False,
- latest_by='creation_date'):
+ def get_content(self, page, language, cnttype,
language_fallback=False):
"""
Gets the latest content for a particular page and language. Falls
back
to another language if wanted.
"""
- content = self.filter(page=page,
type=cnttype).order_by(latest_by).values('language', 'body')
- content_dict = dict([(c['language'], c['body']) for c in content])
+ # used for the DISTINCT on the language. Should be nicer with a
lot of revision
+ sql = '''SELECT DISTINCT(pages_content.language),
pages_content.body
+ FROM pages_content WHERE (pages_content.type = %s
+ AND pages_content.page_id = %s )
+ ORDER BY pages_content.creation_date ASC'''
+ cursor = connection.cursor()
+ cursor.execute(sql, (cnttype, page.id))
+ content_dict = dict([(c[0], c[1]) for c in cursor.fetchall()])
if language in content_dict:
return content_dict[language]
# requested language not found. Try other languages one after
@@ -133,7 +137,7 @@
return content_dict[lang[0]]
return None
- def get_content_slug_by_slug(self, slug, site_id=None,
latest_by='creation_date'):
+ def get_content_slug_by_slug(self, slug):
"""
Returns the latest Content slug object that match the given slug
for
the current site domain.
@@ -142,7 +146,7 @@
if settings.PAGE_USE_SITE_ID:
content = content.filter(page__sites__id=settings.SITE_ID)
try:
- content = content.latest(latest_by)
+ content = content.latest('creation_date')
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:53:58 2009
@@ -226,5 +226,25 @@
self.assertContains(response, 'lang="fr"')
self.assertNotContains(response, 'english title')
+ def test_08_revision(self):
+ """
+ Test that a page can edited several times
+ """
+ c = Client()
+ c.login(username= 'batiste', password='b')
+ page_data = self.get_new_page_data()
+ response = c.post('/admin/pages/page/add/', page_data)
+ page = Page.objects.get(id=1)
+ page_data['body'] = 'changed body'
+ response = c.post('/admin/pages/page/1/', page_data)
+
self.assertEqual(Content.objects.get_content(page, 'en', 'body'), 'changed
body')
+
+ page_data['body'] = 'changed body 2'
+ response = c.post('/admin/pages/page/1/', page_data)
+
self.assertEqual(Content.objects.get_content(page, 'en', 'body'), 'changed
body 2')
+
+ setattr(settings, "PAGE_CONTENT_REVISION", False)
+
+
self.assertEqual(Content.objects.get_content(page, 'en', 'body'), 'changed
body 2')
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---