2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-26 08:40:52 +00:00

[PUI] subscribe ()

* Add "starred" icon to part category table

* Edit "starred" status for PartCategory in PUI

* Edit "starred" state of part in PUI

* Playground fix
This commit is contained in:
Oliver
2024-10-12 11:55:23 +11:00
committed by GitHub
parent 7443d21854
commit 8aade768c3
9 changed files with 103 additions and 35 deletions

@ -270,7 +270,7 @@ class CategoryDetail(CategoryMixin, CustomRetrieveUpdateDestroyAPI):
if 'starred' in data:
starred = str2bool(data.get('starred', False))
self.get_object().set_starred(request.user, starred)
self.get_object().set_starred(request.user, starred, include_parents=False)
response = super().update(request, *args, **kwargs)
@ -1423,7 +1423,9 @@ class PartDetail(PartMixin, RetrieveUpdateDestroyAPI):
if 'starred' in data:
starred = str2bool(data.get('starred', False))
self.get_object().set_starred(request.user, starred)
self.get_object().set_starred(
request.user, starred, include_variants=False, include_categories=False
)
response = super().update(request, *args, **kwargs)

@ -288,11 +288,10 @@ class PartCategory(InvenTree.models.InvenTreeTree):
def get_subscribers(self, include_parents=True):
"""Return a list of users who subscribe to this PartCategory."""
cats = self.get_ancestors(include_self=True)
subscribers = set()
if include_parents:
cats = self.get_ancestors(include_self=True)
queryset = PartCategoryStar.objects.filter(category__in=cats)
else:
queryset = PartCategoryStar.objects.filter(category=self)
@ -306,12 +305,12 @@ class PartCategory(InvenTree.models.InvenTreeTree):
"""Returns True if the specified user subscribes to this category."""
return user in self.get_subscribers(**kwargs)
def set_starred(self, user, status: bool) -> None:
def set_starred(self, user, status: bool, **kwargs) -> None:
"""Set the "subscription" status of this PartCategory against the specified user."""
if not user:
return
if self.is_starred_by(user) == status:
if self.is_starred_by(user, **kwargs) == status:
return
if status:
@ -1451,13 +1450,13 @@ class Part(
"""Return True if the specified user subscribes to this part."""
return user in self.get_subscribers(**kwargs)
def set_starred(self, user, status):
def set_starred(self, user, status, **kwargs):
"""Set the "subscription" status of this Part against the specified user."""
if not user:
return
# Already subscribed?
if self.is_starred_by(user) == status:
if self.is_starred_by(user, **kwargs) == status:
return
if status: