add json feed for bisac heading tree
parent
85284f7fca
commit
1df3cfee79
|
@ -11,6 +11,9 @@ class BisacHeading(MPTTModel):
|
||||||
class MPTTMeta:
|
class MPTTMeta:
|
||||||
order_insertion_by = ['notation']
|
order_insertion_by = ['notation']
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return self.full_label
|
||||||
|
|
||||||
def populate_bisac_headings():
|
def populate_bisac_headings():
|
||||||
for key in bisac.keys():
|
for key in bisac.keys():
|
||||||
full_label = key[0:-10] if key.endswith(' / General') else key
|
full_label = key[0:-10] if key.endswith(' / General') else key
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
from django.conf.urls.defaults import *
|
||||||
|
|
||||||
|
urlpatterns = patterns("",
|
||||||
|
url(r"^tree$", "regluit.bisac.views.tree"),
|
||||||
|
)
|
|
@ -0,0 +1,29 @@
|
||||||
|
import json
|
||||||
|
from django.template import Context, Template
|
||||||
|
from django.http import HttpResponse
|
||||||
|
|
||||||
|
from mptt.templatetags.mptt_tags import cache_tree_children
|
||||||
|
|
||||||
|
from regluit.bisac.models import BisacHeading
|
||||||
|
|
||||||
|
nodes = BisacHeading.objects.all()
|
||||||
|
|
||||||
|
def recursive_node_to_dict(node):
|
||||||
|
result = {
|
||||||
|
'title': node.full_label,
|
||||||
|
'key': node.pk,
|
||||||
|
}
|
||||||
|
children = [recursive_node_to_dict(c) for c in node.get_children()]
|
||||||
|
if children:
|
||||||
|
result['children'] = children
|
||||||
|
result['folder'] = True
|
||||||
|
return result
|
||||||
|
|
||||||
|
root_nodes = cache_tree_children(nodes)
|
||||||
|
dicts = []
|
||||||
|
for n in root_nodes:
|
||||||
|
dicts.append(recursive_node_to_dict(n))
|
||||||
|
|
||||||
|
|
||||||
|
def tree(request):
|
||||||
|
return HttpResponse(json.dumps(dicts, indent=4), content_type="application/json")
|
1
urls.py
1
urls.py
|
@ -18,6 +18,7 @@ urlpatterns = patterns('',
|
||||||
url(r'', include('regluit.payment.urls')),
|
url(r'', include('regluit.payment.urls')),
|
||||||
url(r'', include('regluit.libraryauth.urls')),
|
url(r'', include('regluit.libraryauth.urls')),
|
||||||
url(r'', include('regluit.marc.urls')),
|
url(r'', include('regluit.marc.urls')),
|
||||||
|
url(r'^bisac/', include('regluit.bisac.urls')),
|
||||||
url(r'^selectable/', include('selectable.urls')),
|
url(r'^selectable/', include('selectable.urls')),
|
||||||
url(r'^admin/', include(admin_site.urls)),
|
url(r'^admin/', include(admin_site.urls)),
|
||||||
url(r'^comments/', include('django.contrib.comments.urls')),
|
url(r'^comments/', include('django.contrib.comments.urls')),
|
||||||
|
|
Loading…
Reference in New Issue