mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-20 22:06:28 +00:00
Unique parameters names from category makes it to bootstrap table
This commit is contained in:
@ -111,6 +111,20 @@ class PartCategory(InvenTreeTree):
|
||||
""" True if there are any parts in this category """
|
||||
return self.partcount() > 0
|
||||
|
||||
def get_unique_parameters(self, cascade=True):
|
||||
""" Get all parameters for all parts from this category """
|
||||
parameters = []
|
||||
|
||||
parts = self.get_parts(cascade=cascade).prefetch_related('parameters', 'parameters__template')
|
||||
|
||||
for part in parts:
|
||||
for parameter in part.parameters.all():
|
||||
template_name = parameter.template.name
|
||||
if template_name not in parameters:
|
||||
parameters.append(template_name)
|
||||
|
||||
return parameters
|
||||
|
||||
|
||||
@receiver(pre_delete, sender=PartCategory, dispatch_uid='partcategory_delete_log')
|
||||
def before_delete_part_category(sender, instance, using, **kwargs):
|
||||
|
@ -116,10 +116,10 @@
|
||||
</div>
|
||||
|
||||
|
||||
{% block part_list %}
|
||||
{% block category_tables %}
|
||||
<table class='table table-striped table-condensed' data-toolbar='#button-toolbar' id='part-table'>
|
||||
</table>
|
||||
{% endblock part_list %}
|
||||
{% endblock category_tables %}
|
||||
|
||||
{% endblock %}
|
||||
{% block js_load %}
|
||||
@ -245,16 +245,4 @@
|
||||
},
|
||||
);
|
||||
|
||||
loadParametricPartTable(
|
||||
"#parametric-part-table",
|
||||
"{% url 'api-part-list' %}",
|
||||
{
|
||||
params: {
|
||||
{% if category %}category: {{ category.id }},
|
||||
{% else %}category: "null",
|
||||
{% endif %}
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
{% endblock %}
|
@ -2,7 +2,7 @@
|
||||
{% load static %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block part_list %}
|
||||
{% block category_tables %}
|
||||
|
||||
{% include 'part/category_tabs.html' with tab='parametric-table' %}
|
||||
|
||||
@ -10,3 +10,22 @@
|
||||
</table>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block js_ready %}
|
||||
{{ block.super }}
|
||||
|
||||
loadParametricPartTable(
|
||||
"#parametric-part-table",
|
||||
"{% url 'api-part-list' %}",
|
||||
{
|
||||
params: {
|
||||
{% if category %}category: {{ category.id }},
|
||||
{% else %}category: "null",
|
||||
{% endif %}
|
||||
},
|
||||
headers: {{ parameters|safe }},
|
||||
name: 'parametric',
|
||||
},
|
||||
);
|
||||
|
||||
{% endblock %}
|
@ -2,7 +2,7 @@
|
||||
{% load static %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block part_list %}
|
||||
{% block category_tables %}
|
||||
|
||||
{% include 'part/category_tabs.html' with tab='part-list' %}
|
||||
|
||||
|
@ -77,8 +77,8 @@ part_category_urls = [
|
||||
url(r'^edit/?', views.CategoryEdit.as_view(), name='category-edit'),
|
||||
url(r'^delete/?', views.CategoryDelete.as_view(), name='category-delete'),
|
||||
|
||||
url(r'^parametric/?', views.CategoryDetail.as_view(template_name='part/category_parametric.html'), name='category-parametric'),
|
||||
url(r'^.*$', views.CategoryDetail.as_view(template_name='part/category_partlist.html'), name='category-detail'),
|
||||
url(r'^parametric/?', views.CategoryParametric.as_view(), name='category-parametric'),
|
||||
url(r'^.*$', views.CategoryDetail.as_view(), name='category-detail'),
|
||||
]
|
||||
|
||||
part_bom_urls = [
|
||||
|
@ -1889,6 +1889,21 @@ class CategoryDetail(DetailView):
|
||||
return context
|
||||
|
||||
|
||||
class CategoryParametric(CategoryDetail):
|
||||
""" Parametric view for PartCategory """
|
||||
template_name = 'part/category_parametric.html'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
|
||||
context = super(CategoryParametric, self).get_context_data(**kwargs).copy()
|
||||
|
||||
category = kwargs['object']
|
||||
context['parameters'] = category.get_unique_parameters()
|
||||
print(context)
|
||||
|
||||
return context
|
||||
|
||||
|
||||
class CategoryEdit(AjaxUpdateView):
|
||||
""" Update view to edit a PartCategory """
|
||||
model = PartCategory
|
||||
|
Reference in New Issue
Block a user