Tuesday, September 21, 2010

Problems to render a tree in Json - __init__() got an unexpected keyword argument 'use_decimal'

Hello!

I'm new on this list and a newbie in Django. I'm recurring to this list because I'm having a problem to implement a Json Tree using Django. I saw an article at http://www.elfsternberg.com/2009/05/20/fixing-an-omission-from-djangos-simplejson-iterators-generators-functors-and-closures/ and there it has a good implementation to render a tree in Json, so I implemented my code as follow:

on utils/json.py

from django.utils import simplejson
from django.utils.simplejson.encoder import JSONEncoder

class TreeToJson:
   
    def __init__(self, roots):
        self.roots = roots

    def _index(self, nodes):
        def _item(node):
            t = { 'id': node.id,
                  'name': node.name }
                  #'top': node.is_root()}
            if not node.is_leaf():
                t.update({'children': self._index(node.get_children())})
            return t

        return [_item(node) for node in nodes]

    def __call__(self):
        return self._index(self.roots)

def json(s,**kw):
   
    kw.update({'cls': ExtJsonEncoder})
    return simplejson.dumps(s,**kw)

At myapp/views.py

def jsonSiteList(request):
   
    data = json(TreeToJson(Site.get_root_nodes()))
    return HttpResponse(data, mimetype='text/javascript;') 

But I don't know why this error is appearing when calling at browser:

  __init__() got an unexpected keyword argument 'use_decimal'

Sorry for my so novice phase, but I'm dont know all the things on django, so rest to me a only way: ask to the others :)

Can anyone help me with this issue?

Thanks so much!

Rogério Carrasqueira

---
e-mail: rogerio.carrasqueira@gmail.com
skype: rgcarrasqueira
MSN: rcarrasqueira@hotmail.com
ICQ: 50525616
Tel.: (11) 7805-0074

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate