From 92930766c6a49a643ea91f88b6fe12cb480456f3 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 9 May 2019 22:23:56 +1000 Subject: [PATCH] Tree view now supports root URL link --- InvenTree/InvenTree/views.py | 10 ++++++++++ InvenTree/part/api.py | 5 +++++ InvenTree/stock/api.py | 5 +++++ 3 files changed, 20 insertions(+) diff --git a/InvenTree/InvenTree/views.py b/InvenTree/InvenTree/views.py index 967b3b16c4..bf14b6f349 100644 --- a/InvenTree/InvenTree/views.py +++ b/InvenTree/InvenTree/views.py @@ -28,6 +28,15 @@ class TreeSerializer(views.APIView): Ref: https://github.com/jonmiles/bootstrap-treeview """ + @property + def root_url(self): + """ Return the root URL for the tree. Implementation is class dependent. + + Default implementation returns # + """ + + return '#' + def itemToJson(self, item): data = { @@ -60,6 +69,7 @@ class TreeSerializer(views.APIView): top = { 'text': self.title, + 'href': self.root_url, 'nodes': nodes, 'tags': [top_count], } diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py index 26dbc2e492..0a2bdbfef6 100644 --- a/InvenTree/part/api.py +++ b/InvenTree/part/api.py @@ -14,6 +14,7 @@ from rest_framework import generics, permissions from django.db.models import Q from django.conf.urls import url, include +from django.urls import reverse from .models import Part, PartCategory, BomItem, PartStar from .models import SupplierPart, SupplierPriceBreak @@ -30,6 +31,10 @@ class PartCategoryTree(TreeSerializer): title = "Parts" model = PartCategory + + @property + def root_url(self): + return reverse('part-index') class CategoryList(generics.ListCreateAPIView): diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index 2690207f05..070e7657a6 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -6,6 +6,7 @@ from django_filters.rest_framework import FilterSet, DjangoFilterBackend from django_filters import NumberFilter from django.conf.urls import url, include +from django.urls import reverse from django.db.models import Q from .models import StockLocation, StockItem @@ -27,6 +28,10 @@ class StockCategoryTree(TreeSerializer): title = 'Stock' model = StockLocation + @property + def root_url(self): + return reverse('stock-index') + class StockDetail(generics.RetrieveUpdateDestroyAPIView): """ API detail endpoint for Stock object