From 8b0939ca79069abaedcf9c3c1b46b546129b7cdc Mon Sep 17 00:00:00 2001 From: Skia Date: Mon, 11 Jan 2016 10:01:57 +0100 Subject: [PATCH] Core: rename full_name in _full_name because this attribute is for internal use only --- core/migrations/0003_auto_20160111_0900.py | 19 +++++++++++++++++++ core/models.py | 16 ++++++++-------- 2 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 core/migrations/0003_auto_20160111_0900.py diff --git a/core/migrations/0003_auto_20160111_0900.py b/core/migrations/0003_auto_20160111_0900.py new file mode 100644 index 00000000..e5008001 --- /dev/null +++ b/core/migrations/0003_auto_20160111_0900.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0002_auto_20151215_0827'), + ] + + operations = [ + migrations.RenameField( + model_name='page', + old_name='full_name', + new_name='_full_name', + ), + ] diff --git a/core/models.py b/core/models.py index f1ccf084..ba42b201 100644 --- a/core/models.py +++ b/core/models.py @@ -223,14 +223,14 @@ class Page(models.Model): awkward! Prefere querying pages with Page.get_page_by_full_name() - Be careful with the full_name attribute: this field may not be valid until you call save(). It's made for fast + Be careful with the _full_name attribute: this field may not be valid until you call save(). It's made for fast query, but don't rely on it when playing with a Page object, use get_full_name() instead! """ name = models.CharField(_('page name'), max_length=30, blank=False) parent = models.ForeignKey('self', related_name="children", null=True, blank=True, on_delete=models.SET_NULL) # Attention: this field may not be valid until you call save(). It's made for fast query, but don't rely on it when # playing with a Page object, use get_full_name() instead! - full_name = models.CharField(_('page name'), max_length=255, blank=True) + _full_name = models.CharField(_('page name'), max_length=255, blank=True) owner_group = models.ForeignKey(Group, related_name="owned_page", default=settings.AE_GROUPS['root']['id']) edit_group = models.ManyToManyField(Group, related_name="editable_page", blank=True) @@ -250,7 +250,7 @@ class Page(models.Model): """ Quicker to get a page with that method rather than building the request every time """ - return Page.objects.filter(full_name=name).first() + return Page.objects.filter(_full_name=name).first() def __init__(self, *args, **kwargs): super(Page, self).__init__(*args, **kwargs) @@ -261,7 +261,7 @@ class Page(models.Model): """ if '/' in self.name: self.name = self.name.split('/')[-1] - if Page.objects.exclude(pk=self.pk).filter(full_name=self.get_full_name()).exists(): + if Page.objects.exclude(pk=self.pk).filter(_full_name=self.get_full_name()).exists(): raise ValidationError( _('Duplicate page'), code='duplicate', @@ -288,10 +288,10 @@ class Page(models.Model): if not self.is_locked(): raise NotLocked("The page is not locked and thus can not be saved") self.full_clean() - # This reset the full_name just before saving to maintain a coherent field quicker for queries than the + # This reset the _full_name just before saving to maintain a coherent field quicker for queries than the # recursive method # It also update all the children to maintain correct names - self.full_name = self.get_full_name() + self._full_name = self.get_full_name() for c in self.children.all(): c.save() super(Page, self).save(*args, **kwargs) @@ -347,7 +347,7 @@ class Page(models.Model): """ This is needed for black magic powered UpdateView's children """ - return reverse('core:page', kwargs={'page_name': self.full_name}) + return reverse('core:page', kwargs={'page_name': self._full_name}) def __str__(self): return self.get_full_name() @@ -386,7 +386,7 @@ class PageRev(models.Model): """ This is needed for black magic powered UpdateView's children """ - return reverse('core:page', kwargs={'page_name': self.page.full_name}) + return reverse('core:page', kwargs={'page_name': self.page._full_name}) def __str__(self): return str(self.__dict__)