Author: batiste.bieler
Date: Wed Mar 11 01:42:56 2009
New Revision: 399
Modified:
trunk/pages/admin/__init__.py
trunk/pages/admin/forms.py
trunk/pages/admin/utils.py
trunk/pages/models.py
trunk/pages/tests.py
Log:
Make all the tests pass again
Modified: trunk/pages/admin/__init__.py
==============================================================================
--- trunk/pages/admin/__init__.py (original)
+++ trunk/pages/admin/__init__.py Wed Mar 11 01:42:56 2009
@@ -28,7 +28,7 @@
exclude = ['author', 'parent']
# these mandatory fields are not versioned
mandatory_placeholders = ('title', 'slug')
- general_fields = ['title', 'slug', 'status']
+ general_fields = ['title', 'slug', 'status', 'target', 'position']
# TODO: find solution to do this dynamically
#if getattr(settings, 'PAGE_USE_SITE_ID'):
@@ -113,16 +113,16 @@
def save_model(self, request, obj, form, change):
"""
- Move the page in the tree if neccesary and save every placeholder
+ Move the page in the tree if necessary and save every placeholder
Content object.
"""
- obj.save()
language = form.cleaned_data['language']
- target = request.GET.get('target', None)
- position = request.GET.get('position', None)
-
- if target is not None and position is not None:
+ target = form.data.get('target', None)
+ position = form.data.get('position', None)
+ obj.save()
+
+ if target and position:
try:
target = self.model.objects.get(pk=target)
except self.model.DoesNotExist:
@@ -150,7 +150,7 @@
else:
Content.objects.set_or_create_content(obj, language,
placeholder.name,
form.cleaned_data[placeholder.name])
-
+
obj.invalidate()
def get_fieldsets(self, request, obj=None):
Modified: trunk/pages/admin/forms.py
==============================================================================
--- trunk/pages/admin/forms.py (original)
+++ trunk/pages/admin/forms.py Wed Mar 11 01:42:56 2009
@@ -28,6 +28,10 @@
choices=settings.PAGE_TEMPLATES,
help_text=_('The template used to render the content.')
)
+
+ target = forms.IntegerField(required=False)
+ position = forms.CharField(required=False)
+
if settings.PAGE_TAGGING:
from tagging.forms import TagField
from pages.admin.widgets import AutoCompleteTagInput
@@ -37,7 +41,11 @@
model = Page
def clean_slug(self):
+
slug = slugify(self.cleaned_data['slug'])
+ target = self.data.get('target', None)
+ position = self.data.get('position', None)
+
if settings.PAGE_UNIQUE_SLUG_REQUIRED:
if self.instance.id:
if
Content.objects.exclude(page=self.instance).filter(body=slug,
type="slug").count():
@@ -45,6 +53,29 @@
elif Content.objects.filter(body=slug, type="slug").count():
raise forms.ValidationError(_('Another page with this slug
already exists'))
elif self.instance.id:
- if slug in [sibling.slug() for sibling in
self.instance.get_siblings()]:
- raise forms.ValidationError(_('A sbiling with this slug
already exists'))
+ if slug in [sibling.slug() for sibling in
self.instance.get_siblings().exclude(id=self.instance.id)]:
+ raise forms.ValidationError(_('A sibiling with this slug
already exists'))
+
+ if not settings.PAGE_UNIQUE_SLUG_REQUIRED:
+ if target and position:
+ try:
+ target = Page.objects.get(pk=target)
+ except self.model.DoesNotExist:
+ if slug in [sibling.slug() for sibling in
Page.objects.root()]:
+ raise forms.ValidationError(_('A sibiling with
this slug already exists at the root level'))
+ else:
+ if position in ['right-sibling', 'left-sibling']:
+ if slug in [sibling.slug() for sibling in
target.get_siblings()]:
+ raise forms.ValidationError(_('A sibiling with
this slug already exists at the targeted position'))
+ if position == 'first-child':
+ if slug in [sibling.slug() for sibling in
target.get_children()]:
+ raise forms.ValidationError(_('A children with
this slug already exists at the targeted position'))
+ else:
+ if self.instance.id:
+ if slug in [sibling.slug() for sibling in
Page.objects.root().exclude(id=self.instance.id)]:
+ raise forms.ValidationError(_('A sibiling with
this slug already exists at the root level'))
+ else:
+ if slug in [sibling.slug() for sibling in
Page.objects.root()]:
+ raise forms.ValidationError(_('A sibiling with
this slug already exists at the root level'))
+
return slug
Modified: trunk/pages/admin/utils.py
==============================================================================
--- trunk/pages/admin/utils.py (original)
+++ trunk/pages/admin/utils.py Wed Mar 11 01:42:56 2009
@@ -59,7 +59,6 @@
model = {}
mod_name, form_name = get_mod_func(capp['form'])
f = getattr(__import__(mod_name, {}, {}, ['']), form_name)
- #print f.Meta
model['form'] = f
mod_name, model_name = get_mod_func(capp['model'])
model['model_name'] = model_name
Modified: trunk/pages/models.py
==============================================================================
--- trunk/pages/models.py (original)
+++ trunk/pages/models.py Wed Mar 11 01:42:56 2009
@@ -146,7 +146,7 @@
url = u'%s/' % self.slug(language)
for ancestor in self.get_ancestors(ascending=True):
url = ancestor.slug(language) + u'/' + url
-
+
cache.set(self.PAGE_URL_KEY % (self.id, language), url)
return url
@@ -159,13 +159,14 @@
if slug:
return slug
- if not language:
- language = settings.PAGE_DEFAULT_LANGUAGE
-
slug = Content.objects.get_content(self, language, 'slug',
language_fallback=fallback)
- cache.set(self.PAGE_URL_KEY % (self.id, language), slug)
+ if not language:
+ language = settings.PAGE_DEFAULT_LANGUAGE
+
+ # Seems to trigger errors with the new slug dup
+ #cache.set(self.PAGE_URL_KEY % (self.id, language), slug)
return slug
Modified: trunk/pages/tests.py
==============================================================================
--- trunk/pages/tests.py (original)
+++ trunk/pages/tests.py Wed Mar 11 01:42:56 2009
@@ -55,12 +55,14 @@
response = c.post('/admin/pages/page/add/', page_data)
self.assertRedirects(response, '/admin/pages/page/')
- page1 =
Content.objects.get_content_slug_by_slug(page_data['slug']).page
-
+ setattr(settings, "PAGE_UNIQUE_SLUG_REQUIRED", False)
+
response = c.post('/admin/pages/page/add/', page_data)
self.assertEqual(response.status_code, 200)
- settings.PAGE_UNIQUE_SLUG_REQUIRED = False
+ page1 =
Content.objects.get_content_slug_by_slug(page_data['slug']).page
+ page_data['position'] = 'first-child'
+ page_data['target'] = page1.id
response = c.post('/admin/pages/page/add/', page_data)
self.assertRedirects(response, '/admin/pages/page/')
page2 =
Content.objects.get_content_slug_by_slug(page_data['slug']).page
@@ -291,6 +293,7 @@
page_data = self.get_new_page_data()
page_data['title'] = 'parent title'
+ page_data['slug'] = 'same-slug'
response = c.post('/admin/pages/page/add/', page_data)
# the redirect tell that the page has been create correctly
self.assertRedirects(response, '/admin/pages/page/')
@@ -300,19 +303,20 @@
# this assert test that the creation fail as attended
self.assertEqual(response.status_code, 200)
- response = c.get('/pages/test-page-1/')
+ response = c.get('/pages/same-slug/')
page1 =
Content.objects.get_content_slug_by_slug(page_data['slug']).page
self.assertEqual(page1.id, 1)
page_data['title'] = 'children title'
- # raise a bug with django 1.0.2
- response =
c.post('/admin/pages/page/add/?target=1&position=first-child', page_data)
+ page_data['target'] = 1
+ page_data['position'] = 'first-child'
+ response = c.post('/admin/pages/page/add/', page_data)
self.assertRedirects(response, '/admin/pages/page/')
# finaly test that we can get every page according the path
- response = c.get('/pages/test-page/')
- self.assertContains(response, "parent title", status_code == 200)
+ response = c.get('/pages/same-slug/')
+ self.assertContains(response, "parent title", 2)
- response = c.get('/pages/test-page-1/test-page-1/')
- self.assertContains(response, "children title", status_code == 200)
+ response = c.get('/pages/same-slug/same-slug/')
+ self.assertContains(response, "children title", 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
-~----------~----~----~----~------~----~------~--~---