From b919418fb5fe0d38fda0252ebced79f97dbb32ce Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 26 Mar 2017 10:29:51 +1100 Subject: [PATCH] Added a categorylist page Displays list of all top-level part categories --- InvenTree/part/models.py | 6 +++--- InvenTree/part/templates/part/category.html | 1 + InvenTree/part/templates/part/categorylist.html | 8 ++++++++ InvenTree/part/urls.py | 5 ++++- InvenTree/part/views.py | 7 +++++++ 5 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 InvenTree/part/templates/part/categorylist.html diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index c65fe7500e..fa7ae48968 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -16,10 +16,10 @@ class PartCategory(models.Model): # Return the parent path of this category @property def path(self): - parent_path = [] - if self.parent: - parent_path = self.parent.path + [self.parent] + return self.parent.path + [self.parent] + else: + return [] return parent_path diff --git a/InvenTree/part/templates/part/category.html b/InvenTree/part/templates/part/category.html index 481073fb6a..70d4bd6246 100644 --- a/InvenTree/part/templates/part/category.html +++ b/InvenTree/part/templates/part/category.html @@ -1,4 +1,5 @@ {# Construct the category path #} +Category/ {% for path_item in category.path %} {{ path_item.name }}/ {% endfor %} diff --git a/InvenTree/part/templates/part/categorylist.html b/InvenTree/part/templates/part/categorylist.html new file mode 100644 index 0000000000..c4c62ba58b --- /dev/null +++ b/InvenTree/part/templates/part/categorylist.html @@ -0,0 +1,8 @@ +Top Level Part Categories: + +{% for category in categories %} + +
+{{ category.name }} + +{% endfor %} \ No newline at end of file diff --git a/InvenTree/part/urls.py b/InvenTree/part/urls.py index 8223b87b5d..8102058781 100644 --- a/InvenTree/part/urls.py +++ b/InvenTree/part/urls.py @@ -6,7 +6,10 @@ urlpatterns = [ # Display part detail url(r'^(?P[0-9]+)/$', views.partdetail, name='detail'), - # Display a part category + # Display a list of top-level categories + url(r'^category/$', views.categorylist, name='categorylist'), + + # Display a single part category url(r'^category/(?P[0-9]+)/$', views.category, name='category'), url(r'^$', views.index, name='index') ] \ No newline at end of file diff --git a/InvenTree/part/views.py b/InvenTree/part/views.py index 7e11750500..c3371a4fac 100644 --- a/InvenTree/part/views.py +++ b/InvenTree/part/views.py @@ -13,6 +13,13 @@ def partdetail(request, part_id): return render(request, 'part/detail.html', {'part': part}) +def categorylist(request): + categories = PartCategory.objects.filter(parent = None) + + return render(request, 'part/categorylist.html', + {'categories': categories + }) + def category(request, category_id): # Find the category