2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-16 01:36:29 +00:00

Implemented tree view

Using library bootstrap-treeview
- part category tree
- stock location tree
- Currenly is functional but looks terrible
This commit is contained in:
Oliver
2018-04-28 23:22:12 +10:00
parent 095492203f
commit 8d0789c37c
13 changed files with 1471 additions and 9 deletions

View File

@@ -12,6 +12,7 @@ from build.urls import build_urls
from part.api import part_api_urls
from company.api import company_api_urls
from stock.api import stock_api_urls
from django.conf import settings
from django.conf.urls.static import static
@@ -25,6 +26,7 @@ admin.site.site_header = "InvenTree Admin"
apipatterns = [
url(r'^part/', include(part_api_urls)),
url(r'^company/', include(company_api_urls)),
url(r'^stock/', include(stock_api_urls)),
# User URLs
url(r'^user/', include(user_urls)),

View File

@@ -5,6 +5,48 @@ from django.template.loader import render_to_string
from django.http import JsonResponse
from django.views.generic import UpdateView, CreateView, DeleteView
from rest_framework import views
from django.http import JsonResponse
class TreeSerializer(views.APIView):
def itemToJson(self, item):
data = {
'text': item.name,
'href': item.get_absolute_url(),
}
if item.has_children:
nodes = []
for child in item.children.all().order_by('name'):
nodes.append(self.itemToJson(child))
data['nodes'] = nodes
return data
def get(self, request, *args, **kwargs):
top_items = self.model.objects.filter(parent=None).order_by('name')
nodes = []
for item in top_items:
nodes.append(self.itemToJson(item))
top = {
'text': self.title,
'nodes': nodes,
}
response = {
'tree': [top]
}
return JsonResponse(response, safe=False)
class AjaxView(object):