Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: radiosilence/django-suave
base: 1ed2f4244a
...
head fork: radiosilence/django-suave
compare: f676f8308a
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Commits on May 22, 2012
James Cleveland sql optimisation 57447f4
James Cleveland make page urls be properties and only calculated on save f676f83
View
92 suave/migrations/0003_auto__add_field_page_url.py
@@ -0,0 +1,92 @@
+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+ # Adding field 'Page.url'
+ db.add_column('suave_page', 'url',
+ self.gf('django.db.models.fields.CharField')(max_length=255, null=True, blank=True),
+ keep_default=False)
+
+ def backwards(self, orm):
+ # Deleting field 'Page.url'
+ db.delete_column('suave_page', 'url')
+
+ models = {
+ 'suave.attachment': {
+ 'Meta': {'ordering': "['order']", 'object_name': 'Attachment'},
+ 'added': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'identifier': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'image': ('sorl.thumbnail.fields.ImageField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
+ 'order': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'status': ('model_utils.fields.StatusField', [], {'default': "'draft'", 'max_length': '100', 'no_check_for_status': 'True'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'type': ('django.db.models.fields.CharField', [], {'default': "'image'", 'max_length': '45'}),
+ 'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'})
+ },
+ 'suave.carousel': {
+ 'Meta': {'ordering': "['order']", 'object_name': 'Carousel'},
+ 'added': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'identifier': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'order': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'status': ('model_utils.fields.StatusField', [], {'default': "'draft'", 'max_length': '100', 'no_check_for_status': 'True'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'})
+ },
+ 'suave.carouselimage': {
+ 'Meta': {'object_name': 'CarouselImage'},
+ 'carousel': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['suave.Carousel']"}),
+ 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'image': ('sorl.thumbnail.fields.ImageField', [], {'max_length': '100'}),
+ 'order': ('django.db.models.fields.IntegerField', [], {'default': '0'})
+ },
+ 'suave.nav': {
+ 'Meta': {'ordering': "['order']", 'object_name': 'Nav'},
+ 'added': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'identifier': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'items': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'navs'", 'symmetrical': 'False', 'through': "orm['suave.NavItem']", 'to': "orm['suave.Page']"}),
+ 'order': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'status': ('model_utils.fields.StatusField', [], {'default': "'draft'", 'max_length': '100', 'no_check_for_status': 'True'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'})
+ },
+ 'suave.navitem': {
+ 'Meta': {'ordering': "['order']", 'object_name': 'NavItem'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'nav': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'navitems'", 'to': "orm['suave.Nav']"}),
+ 'order': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+ 'page': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'navitems'", 'to': "orm['suave.Page']"}),
+ 'show_children': ('django.db.models.fields.BooleanField', [], {'default': 'True'})
+ },
+ 'suave.page': {
+ 'Meta': {'ordering': "['order']", 'object_name': 'Page'},
+ 'added': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'body': ('tinymce.models.HTMLField', [], {'null': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'identifier': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'order': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'parent': ('mptt.fields.TreeForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['suave.Page']"}),
+ 'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '255'}),
+ 'status': ('model_utils.fields.StatusField', [], {'default': "'draft'", 'max_length': '100', 'no_check_for_status': 'True'}),
+ 'template_override': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'url': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'})
+ }
+ }
+
+ complete_apps = ['suave']
View
17 suave/models.py
@@ -1,3 +1,4 @@
+from copy import copy
from django.db import models
from django.db.models.query import QuerySet
from django.core.urlresolvers import reverse
@@ -83,11 +84,23 @@ class Page(MPTTModel, Displayable):
parent = TreeForeignKey('self', null=True, blank=True,
related_name='children')
-
+ url = models.CharField(max_length=255, null=True, blank=True)
objects = PassThroughManager.for_queryset_class(SiteEntityQuerySet)()
+ def save(self, *args, **kwargs):
+ old_url = copy(self.url)
+ self.update_url()
+ if self.url != old_url:
+ for child in self.children.all():
+ child.save()
+
+ return super(SiteEntity, self).save(*args, **kwargs)
+
+ def update_url(self, save=True):
+ self.url = self._url
+
@property
- def url(self):
+ def _url(self):
if self.is_root_node():
return reverse('suave:page')
View
15 suave/utils.py
@@ -6,10 +6,15 @@ def get_page_from_url(url):
key = 'suave:page_at_url:%s' % url
page = cache.get(key)
if page == None:
- page = False
- for attempt in Page.objects.live().all():
- if attempt.url.strip('/') == url.strip('/'):
- page = attempt
- break
+ if url[-1] != '/':
+ url = url + '/'
+
+ if url[0] != '/':
+ url = '/' + url
+ try:
+ page = Page.objects.live().get(url=url)
+ except Page.DoesNotExist:
+ page = False
+
cache.set(key, page, 60)
return page

No commit comments for this range

Something went wrong with that request. Please try again.