sitetree/admin.py
def get_form(self, request, obj=None, **kwargs):
        """Returns modified form for TreeItem model.
        'Parent' field choices are built by sitetree itself.

        """
        if obj is not None and obj.parent is not None:
            self.previous_parent = obj.parent
            previous_parent_id = self.previous_parent.id
        else:
            previous_parent_id = None

        my_choice_field = TreeItemChoiceField(self.tree, initial=previous_parent_id)
        form = super(TreeItemAdmin, self).get_form(request, obj, **kwargs)
        my_choice_field.label = form.base_fields['parent'].label
        my_choice_field.help_text = form.base_fields['parent'].help_text
        my_choice_field.widget = form.base_fields['parent'].widget
        # Replace 'parent' TreeItem field with new appropriate one
        form.base_fields['parent'] = my_choice_field

        # Try to resolve all currently registered url names including those in namespaces.
        if not getattr(self, 'known_url_names', False):
            self.known_url_names = []
            self.known_url_rules = []
            resolver = get_resolver(get_urlconf())
            for ns, (url_prefix, ns_resolver) in resolver.namespace_dict.items():
                if ns != 'admin':
                    self._stack_known_urls(ns_resolver.reverse_dict, ns)
            self._stack_known_urls(resolver.reverse_dict)
            self.known_url_rules = sorted(self.known_url_rules)

        form.known_url_names_hint = _(
            'You are seeing this warning because "URL as Pattern" option is active and pattern entered above '
            'seems to be invalid. Currently registered URL pattern names and parameters: ')
        form.known_url_names = self.known_url_names
        form.known_url_rules = self.known_url_rules
        return form
def get_form(self, request, obj=None, **kwargs):
        if obj is not None and obj.parent is not None:
            self.previous_parent = obj.parent
            previous_parent_id = self.previous_parent.id
        else:
            previous_parent_id = None

        my_choice_field = TreeItemChoiceField(self.tree, initial=previous_parent_id)
        form = super(TreeItemAdmin, self).get_form(request, obj, **kwargs)
        my_choice_field.label = form.base_fields['parent'].label
        my_choice_field.help_text = form.base_fields['parent'].help_text
        my_choice_field.widget = form.base_fields['parent'].widget
        # Replace 'parent' TreeItem field with new appropriate one
        form.base_fields['parent'] = my_choice_field

        # Try to resolve all currently registered url names including those in namespaces.
        if not getattr(self, 'known_url_names', False):
            self.known_url_names = []
            self.known_url_rules = []
            resolver = get_resolver(get_urlconf())
            for ns, (url_prefix, ns_resolver) in resolver.namespace_dict.items():
                if ns != 'admin':
                    self._stack_known_urls(ns_resolver.reverse_dict, ns)
            self._stack_known_urls(resolver.reverse_dict)
            self.known_url_rules = sorted(self.known_url_rules)

        form.known_url_names_hint = _(
            'You are seeing this warning because "URL as Pattern" option is active and pattern entered above '
            'seems to be invalid. Currently registered URL pattern names and parameters: ')
        form.known_url_names = self.known_url_names
        form.known_url_rules = self.known_url_rules
        return form
def get_form ( self , request , obj = None , * * kwargs ) : if obj is not None and obj . parent is not None : self . previous_parent = obj . parent previous_parent_id = self . previous_parent . id else : previous_parent_id = None my_choice_field = TreeItemChoiceField ( self . tree , initial = previous_parent_id ) form = super ( TreeItemAdmin , self ) . get_form ( request , obj , * * kwargs ) my_choice_field . label = form . base_fields [ 'parent' ] . label my_choice_field . help_text = form . base_fields [ 'parent' ] . help_text my_choice_field . widget = form . base_fields [ 'parent' ] . widget # Replace 'parent' TreeItem field with new appropriate one form . base_fields [ 'parent' ] = my_choice_field # Try to resolve all currently registered url names including those in namespaces. if not getattr ( self , 'known_url_names' , False ) : self . known_url_names = [ ] self . known_url_rules = [ ] resolver = get_resolver ( get_urlconf ( ) ) for ns , ( url_prefix , ns_resolver ) in resolver . namespace_dict . items ( ) : if ns != 'admin' : self . _stack_known_urls ( ns_resolver . reverse_dict , ns ) self . _stack_known_urls ( resolver . reverse_dict ) self . known_url_rules = sorted ( self . known_url_rules ) form . known_url_names_hint = _ ( 'You are seeing this warning because "URL as Pattern" option is active and pattern entered above ' 'seems to be invalid. Currently registered URL pattern names and parameters: ' ) form . known_url_names = self . known_url_names form . known_url_rules = self . known_url_rules return form
Returns modified form for TreeItem model.
        'Parent' field choices are built by sitetree itself.
Returns modified form for TreeItem model . Parent field choices are built by sitetree itself .