mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add ability to filter by 'starred' status
This commit is contained in:
parent
c76c93237e
commit
b850beb687
@ -87,7 +87,7 @@ function loadPartTable(table, url, options={}) {
|
|||||||
* buttons: If provided, link buttons to selection status of this table
|
* buttons: If provided, link buttons to selection status of this table
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var params = options.parms || {};
|
var params = options.params || {};
|
||||||
|
|
||||||
var filters = loadTableFilters("parts");
|
var filters = loadTableFilters("parts");
|
||||||
|
|
||||||
|
@ -153,6 +153,7 @@ class PartList(generics.ListCreateAPIView):
|
|||||||
The Part object list can be filtered by:
|
The Part object list can be filtered by:
|
||||||
- category: Filter by PartCategory reference
|
- category: Filter by PartCategory reference
|
||||||
- cascade: If true, include parts from sub-categories
|
- cascade: If true, include parts from sub-categories
|
||||||
|
- starred: Is the part "starred" by the current user?
|
||||||
- is_template: Is the part a template part?
|
- is_template: Is the part a template part?
|
||||||
- variant_of: Filter by variant_of Part reference
|
- variant_of: Filter by variant_of Part reference
|
||||||
- assembly: Filter by assembly field
|
- assembly: Filter by assembly field
|
||||||
@ -295,17 +296,36 @@ class PartList(generics.ListCreateAPIView):
|
|||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
|
|
||||||
# Does the user wish to filter by category?
|
|
||||||
cat_id = self.request.query_params.get('category', None)
|
|
||||||
|
|
||||||
# Start with all objects
|
# Start with all objects
|
||||||
parts_list = Part.objects.all()
|
parts_list = Part.objects.all()
|
||||||
|
|
||||||
cascade = str2bool(self.request.query_params.get('cascade', False))
|
# Filter by 'starred' parts?
|
||||||
|
starred = str2bool(self.request.query_params.get('starred', None))
|
||||||
|
|
||||||
|
if starred is not None:
|
||||||
|
starred_parts = [star.part.pk for star in self.request.user.starred_parts.all()]
|
||||||
|
|
||||||
|
if starred:
|
||||||
|
parts_list = parts_list.filter(pk__in=starred_parts)
|
||||||
|
else:
|
||||||
|
parts_list = parts_list.exclude(pk__in=starred_parts)
|
||||||
|
|
||||||
|
cascade = str2bool(self.request.query_params.get('cascade', None))
|
||||||
|
|
||||||
|
# Does the user wish to filter by category?
|
||||||
|
cat_id = self.request.query_params.get('category', None)
|
||||||
|
|
||||||
if cat_id is None:
|
if cat_id is None:
|
||||||
# Top-level parts
|
# No category filtering if category is not specified
|
||||||
if not cascade:
|
pass
|
||||||
|
|
||||||
|
else:
|
||||||
|
# Category has been specified!
|
||||||
|
if isNull(cat_id):
|
||||||
|
# A 'null' category is the top-level category
|
||||||
|
if cascade is False:
|
||||||
|
# Do not cascade, only list parts in the top-level category
|
||||||
parts_list = parts_list.filter(category=None)
|
parts_list = parts_list.filter(category=None)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
@ -227,9 +227,9 @@
|
|||||||
"#part-table",
|
"#part-table",
|
||||||
"{% url 'api-part-list' %}",
|
"{% url 'api-part-list' %}",
|
||||||
{
|
{
|
||||||
query: {
|
params: {
|
||||||
{% if category %}
|
{% if category %}category: {{ category.id }},
|
||||||
category: {{ category.id }},
|
{% else %}category: "null",
|
||||||
{% endif %}
|
{% endif %}
|
||||||
},
|
},
|
||||||
buttons: ['#part-options'],
|
buttons: ['#part-options'],
|
||||||
|
Loading…
Reference in New Issue
Block a user