def render(self, context):
        provider = Variable(self.provider).resolve(context)
        media = forms.Media(css = widgets.CategorySelectWidget.Media.css, \
                            js = widgets.CategorySelectWidget.Media.js)
        context[self.media_key] = media
        attrs = {
            'id': 'category-tree-{0}'.format(slugify(provider)),
            'class' : 'category-tree',
        }
        for key, value in self.attrs.items():
            if self.attrs[key] == True:
                attrs[key] = True
            else:
                attrs[key] = Variable(value).resolve(context)
        root = None
        if self.root:
            root = Variable(self.root).resolve(context)
        if self.template_name is None:
            template_name = 'category/render-tree.html'
        else:
            template_name = Variable(self.template_name).resolve(context)

        provider = cache.get_object(provider)
        if root:
            if isinstance(root, Category):
                if root.is_root:
                    root = root
                else:
                    root = root.root
            else:
                root = get_root(name = root)
        else:
            root = provider.get_root_category()
        cache.add_object(provider, root.pk)
        kw = {
            'template_name':template_name,
            'context': context,
            'collapse': self.collapse,
            'attrs' : attrs,
        }
        return do_render_tree(provider, root, **kw)
 def get_root_category(self):
     if self.root is None:
         self.root = get_root(name = self.root_name)
     return self.root