Beispiel #1
0
    def delete(self):
        from plushcms.treemenus.utils import clean_ranks

        old_parent = self.parent
        super(MenuItem, self).delete()

        if old_parent:
            clean_ranks(old_parent.children())
Beispiel #2
0
    def delete(self):
        from plushcms.treemenus.utils import clean_ranks

        old_parent = self.parent
        super(MenuItem, self).delete()

        if old_parent:
            clean_ranks(old_parent.children())
Beispiel #3
0
    def save(self, force_insert=False, **kwargs):
        from plushcms.treemenus.utils import clean_ranks

        old_level = self.level

        if self.parent:
            self.level = self.parent.level + 1

        else:
            self.level = 0

        if self.pk:
            new_parent = self.parent
            old_parent = MenuItem.objects.get(pk=self.pk).parent

            if old_parent != new_parent:
                if new_parent:
                    clean_ranks(new_parent.children())
                    self.rank = new_parent.children().count()

                super(MenuItem, self).save(force_insert, **kwargs)

                if old_parent:
                    clean_ranks(old_parent.children())

            else:
                super(MenuItem, self).save(force_insert, **kwargs)

        else:
            if not self.has_siblings():
                self.rank = 0

            else:
                siblings = self.siblings().order_by("-rank")
                self.rank = siblings[0].rank + 1

            super(MenuItem, self).save(force_insert, **kwargs)

        if old_level != self.level:
            for child in self.children():
                child.save()
Beispiel #4
0
    def save(self, force_insert=False, **kwargs):
        from plushcms.treemenus.utils import clean_ranks

        old_level = self.level

        if self.parent:
            self.level = self.parent.level + 1

        else:
            self.level = 0

        if self.pk:
            new_parent = self.parent
            old_parent = MenuItem.objects.get(pk=self.pk).parent

            if old_parent != new_parent:
                if new_parent:
                    clean_ranks(new_parent.children())
                    self.rank = new_parent.children().count()

                super(MenuItem, self).save(force_insert, **kwargs)

                if old_parent:
                    clean_ranks(old_parent.children())

            else:
                super(MenuItem, self).save(force_insert, **kwargs)

        else:
            if not self.has_siblings():
                self.rank = 0

            else:
                siblings = self.siblings().order_by("-rank")
                self.rank = siblings[0].rank + 1

            super(MenuItem, self).save(force_insert, **kwargs)

        if old_level != self.level:
            for child in self.children():
                child.save()