8000 Fixes/use svg icons by jrief · Pull Request #6457 · django-cms/django-cms · GitHub
[go: up one dir, main page]

Skip to content

Fixes/use svg icons #6457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed #6340 -- Reorder models to support dumpdata (#6341)
  • Loading branch information
heppstux authored and czpython committed Apr 25, 2018
commit 9e60ff11dfa32fb3324ad057c9cf1f50c1df2d1f
6 changes: 6 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
=== 3.5.3 (unreleased) ===

* Fixed ``TreeNode.DoesNotExist`` exception raised when exporting
and loading database contents via ``dumpdata`` and ``loaddata``.


=== 3.5.2 (2018-04-11) ===

* Fixed a bug where shortcuts menu entry would stop working after toolbar reload
Expand Down
218 changes: 109 additions & 109 deletions cms/models/pagemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,115 @@
logger = getLogger(__name__)


@python_2_unicode_compatible
class TreeNode(MP_Node):

parent = models.ForeignKey(
'self',
on_delete=models.CASCADE,
blank=True,
null=True,
related_name='children',
db_index=True,
)
site = models.ForeignKey(
Site,
on_delete=models.CASCADE,
verbose_name=_("site"),
related_name='djangocms_nodes',
db_index=True,
)

objects = PageNodeManager()

class Meta:
app_label = 'cms'
ordering = ('path',)
default_permissions = []

def __str__(self):
return self.path

@cached_property
def item(self):
return self.get_item()

def get_item(self):
# Paving the way...
return Page.objects.get(node=self, publisher_is_draft=True)

@property
def is_branch(self):
return bool(self.numchild)

def get_ancestor_paths(self):
paths = frozenset(
self.path[0:pos]
for pos in range(0, len(self.path), self.steplen)[1:]
)
return paths

def add_child(self, **kwargs):
if len(kwargs) == 1 and 'instance' in kwargs:
kwargs['instance'].parent = self
else:
kwargs['parent'] = self
return super(TreeNode, self).add_child(**kwargs)

def add_sibling(self, pos=None, *args, **kwargs):
if len(kwargs) == 1 and 'instance' in kwargs:
kwargs['instance'].parent_id = self.parent_id
else:
kwargs['parent_id'] = self.parent_id
return super(TreeNode, self).add_sibling(*args, **kwargs)

def update(self, **data):
cls = self.__class__
cls.objects.filter(pk=self.pk).update(**data)

for field, value in data.items():
setattr(self, field, value)
return

def get_cached_ancestors(self):
if self._has_cached_hierarchy():
return self._ancestors
return []

def get_cached_descendants(self):
if self._has_cached_hierarchy():
return self._descendants
return []

def _reload(self):
"""
Reload a page node from the database
"""
return self.__class__.objects.get(pk=self.pk)

def _has_cached_hierarchy(self):
return hasattr(self, '_descendants') and hasattr(self, '_ancestors')

def _set_hierarchy(self, nodes, ancestors=None):
if self.is_branch:
self._descendants = [node for node in nodes
if node.path.startswith(self.path)
and node.depth > self.depth]
else:
self._descendants = []

if self.is_root():
self._ancestors = []
else:
self._ancestors = ancestors

children = (node for node in self._descendants
if node.depth == self.depth + 1)

for child in children:
child._set_hierarchy(self._descendants, ancestors=([self] + self._ancestors))


@python_2_unicode_compatible
class Page(models.Model):
"""
Expand Down Expand Up @@ -1586,112 +1695,3 @@ def get_root_page(cls, site):

def is_potential_home(self):
return False


@python_2_unicode_compatible
class TreeNode(MP_Node):

parent = models.ForeignKey(
'self',
on_delete=models.CASCADE,
blank=True,
null=True,
related_name='children',
db_index=True,
)
site = models.ForeignKey(
Site,
on_delete=models.CASCADE,
verbose_name=_("site"),
related_name='djangocms_nodes',
db_index=True,
)

objects = PageNodeManager()

class Meta:
app_label = 'cms'
ordering = ('path',)
default_permissions = []

def __str__(self):
return self.path

@cached_property
def item(self):
return self.get_item()

def get_item(self):
# Paving the way...
return Page.objects.get(node=self, publisher_is_draft=True)

@property
def is_branch(self):
return bool(self.numchild)

def get_ancestor_paths(self):
paths = frozenset(
self.path[0:pos]
for pos in range(0, len(self.path), self.steplen)[1:]
)
return paths

def add_child(self, **kwargs):
if len(kwargs) == 1 and 'instance' in kwargs:
kwargs['instance'].parent = self
else:
kwargs['parent'] = self
return super(TreeNode, self).add_child(**kwargs)

def add_sibling(self, pos=None, *args, **kwargs):
if len(kwargs) == 1 and 'instance' in kwargs:
kwargs['instance'].parent_id = self.parent_id
else:
kwargs['parent_id'] = self.parent_id
return super(TreeNode, self).add_sibling(*args, **kwargs)

def update(self, **data):
cls = self.__class__
cls.objects.filter(pk=self.pk).update(**data)

for field, value in data.items():
setattr(self, field, value)
return

def get_cached_ancestors(self):
if self._has_cached_hierarchy():
return self._ancestors
return []

def get_cached_descendants(self):
if self._has_cached_hierarchy():
return self._descendants
return []

def _reload(self):
"""
Reload a page node from the database
"""
return self.__class__.objects.get(pk=self.pk)

def _has_cached_hierarchy(self):
return hasattr(self, '_descendants') and hasattr(self, '_ancestors')

def _set_hierarchy(self, nodes, ancestors=None):
if self.is_branch:
self._descendants = [node for node in nodes
if node.path.startswith(self.path)
and node.depth > self.depth]
else:
self._descendants = []

if self.is_root():
self._ancestors = []
else:
self._ancestors = ancestors

children = (node for node in self._descendants
if node.depth == self.depth + 1)

for child in children:
child._set_hierarchy(self._descendants, ancestors=([self] + self._ancestors))
7 changes: 6 additions & 1 deletion cms/tests/test_fixture_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

from django.core.management import call_command

from cms.models import CMSPlugin, Page, Placeholder, TreeNode
from cms.test_utils.fixtures.navextenders import NavextendersFixture
from cms.test_utils.testcases import CMSTestCase
from cms.models import Page, Placeholder, CMSPlugin


class FixtureTestCase(NavextendersFixture, CMSTestCase):
Expand All @@ -27,19 +27,24 @@ def test_fixture_load(self):
call_command('dumpdata', 'cms', indent=3, stdout=output)
original_ph = Placeholder.objects.count()
original_pages = Page.objects.count()
original_tree_nodes = TreeNode.objects.count()
original_plugins = CMSPlugin.objects.count()
Page.objects.all().delete()
TreeNode.objects.all().delete()
output.seek(0)
with codecs.open(dump[1], 'w', 'utf-8') as dumpfile:
dumpfile.write(output.read())

self.assertEqual(0, TreeNode.objects.count())
self.assertEqual(0, Page.objects.count())
self.assertEqual(0, Placeholder.objects.count())
# Transaction disable, otherwise the connection it the test would be
# isolated from the data loaded in the different command connection
call_command('loaddata', dump[1], commit=False, stdout=output)
self.assertEqual(10, Page.objects.count())
self.assertEqual(original_pages, Page.objects.count())
self.assertEqual(5, TreeNode.objects.count())
self.assertEqual(original_tree_nodes, TreeNode.objects.count())
# Placeholder number may differ if signals does not correctly handle
# load data command
self.assertEqual(original_ph, Placeholder.objects.count())
Expand Down
0