Example #1
0
    def clean_parent(self):    
        new_parent = self.cleaned_data['parent']

        if Node.is_parent_relationship_circular(self.instance, new_parent=new_parent):
            raise forms.ValidationError("The Parent relationship is circular!  Please choose another parent!  (Or no parent for a root node)")

        if Node.does_root_node_already_exist(self.instance) and not new_parent:
            raise forms.ValidationError("Please choose a parent.  (A home/root node already exists.)")
        return new_parent        
Example #2
0
    def clean_parent(self):
        new_parent = self.cleaned_data['parent']

        if Node.is_parent_relationship_circular(self.instance,
                                                new_parent=new_parent):
            raise forms.ValidationError(
                "The Parent relationship is circular!  Please choose another parent!  (Or no parent for a root node)"
            )

        if Node.does_root_node_already_exist(self.instance) and not new_parent:
            raise forms.ValidationError(
                "Please choose a parent.  (A home/root node already exists.)")
        return new_parent
Example #3
0
 def __init__(self, *args, **kwargs):
     super(PageDirectLinkAdminForm, self).__init__(*args, **kwargs)
     self.fields['parent'].choices = Node.get_admin_parent_choices()
Example #4
0
    def runTest(self):
        show_loaded_nodes()
        #--------------------------------------------
        msgt('Should be 22 test nodes')
        self.assertEqual(Node.objects.all().count(), 22)
        msg('ok')
        
        #--------------------------------------------
        msgt('Hide Vegetable node--its children should not be visible in the breadcrumb')
        node_to_hide = Node.objects.get(name='vegetable')
        node_to_hide.visible=False
        node_to_hide.save()
        show_loaded_nodes()
        
        # This node and it's children should not be visible (visible not set, but appears in breadcrumb)
        for child_node in Node.objects.filter(left_val__gt=node_to_hide.left_val \
                                            ,right_val__lt=node_to_hide.left_val):
            self.assertGreaterEqual(child_node.breadcrumb.find(STR_NOT_VISIBLE), 0)
        msg('ok')
        
        #--------------------------------------------
        msgt('Make vegetable node visible again, children should also be visible in breadcrumb')
        node_to_hide.visible=True
        node_to_hide.save()
        for child_node in Node.objects.filter(left_val__gt=node_to_hide.left_val \
                                            ,right_val__lt=node_to_hide.left_val):
            self.assertEqual(child_node.breadcrumb.find(STR_NOT_VISIBLE), -1)
        msg('ok')
        
        
        #--------------------------------------------
        msgt('Delete "yellow" node.  Its child, "banana" should now have the parent "fruit"')
        Node.objects.get(name='yellow').delete()
        banana_node = get_node('banana')
        self.assertEqual(banana_node.parent.name, 'fruit')
        msg('ok')
        
        #--------------------------------------------
        msgt('Add "kiwi" as a "tropical" fruit')
        Node.objects.create(name='kiwi'\
                        , parent=get_node('tropical'))
        kiwi = Node.objects.get(name='kiwi')
        sep = ' %s ' % BREADCRUMB_SEPARATOR
        self.assertEqual(kiwi.breadcrumb(), sep.join("""food fruit tropical kiwi""".split()))
        print kiwi.breadcrumb()
        msg('ok')
        #show_loaded_nodes()

        #--------------------------------------------
        msgt('put "kiwi" after siblings: "papaya" and "pineapple"')
        kiwi.sibling_order= 999
        kiwi.save()
        self.assertEqual(get_node('kiwi').left_val > get_node('papaya').left_val, True )
        self.assertEqual(get_node('kiwi').left_val > get_node('pineapple').left_val, True )
        msg('ok')

        #--------------------------------------------
        msgt('Try to create circular relationship and raise error')
        # food -> vegetable -> root -> yam
        yam = get_node('yam')
        veg = get_node('vegetable')
        veg.parent = yam
        try:
            veg.save()
        except ParentRelationshipCircular as e:
            print str(e)
            self.assertEquals(str(e), str(ParentRelationshipCircular(veg)) )
        msg('ok')
        
        show_loaded_nodes()
        
        #--------------------------------------------
        msgt('Add a new root')
        things = Node(name='things (new root)', parent=None)
        things.save()
        self.assertEquals(Node.objects.filter(is_root=True, visible=True ).count(), 1)
        self.assertEquals(get_node('things (new root)').left_val, 1)
        msg('ok')

        #--------------------------------------------
        msgt('Is old root a child of the new root?')
        self.assertEquals(get_node('food').parent, things)
        msg('ok')
        show_loaded_nodes()

        #--------------------------------------------
        msgt('delete new root: "food" should be replacement root')
        get_node('things (new root)').delete()   # new root deleted
        food = get_node('food')
        self.assertEquals(food.left_val, 1)
        self.assertEquals(food.is_root, True)
        self.assertEquals(food.visible, True)
        msg('ok')

        show_loaded_nodes()
        
        #--------------------------------------------
        msgt('Make root visible=False -> should fail, reverting back to visible=True')
        food = get_node('food')
        food.visible=False
        food.save()
        self.assertEquals(get_node('food').visible, True)
        msg('ok')

        #--------------------------------------------
        msgt("delete root again.  'food' should be replaced by child 'fruit'")
        get_node('food').delete()
        fruit = get_node('fruit')
        self.assertEquals(fruit.left_val, 1)
        self.assertEquals(fruit.is_root, True)
        self.assertEquals(fruit.visible, True)
        msg('ok')
        msg("tree is messed up, but there's still a root:)")
        show_loaded_nodes()
Example #5
0
 def __init__(self, *args, **kwargs):
     super(PageDirectLinkAdminForm, self).__init__(*args, **kwargs)
     self.fields['parent'].choices = Node.get_admin_parent_choices()