Skip to content

Commit

Permalink
Merge pull request #1200 from rdmorganiser/fix/1198-views-catalogs-ch…
Browse files Browse the repository at this point in the history
…ange

Fix: remove views from projects if catalog is changed
  • Loading branch information
MyPyDavid authored Jan 20, 2025
2 parents 9065876 + 009d592 commit 88e4583
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions rdmo/projects/handlers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from django.db.models.signals import post_save
from django.dispatch import receiver

from rdmo.projects.models import Project
from rdmo.views.models import View


@receiver(post_save, sender=Project)
def update_views_on_catalog_change(sender, instance, **kwargs):
# remove views that are no longer available
view_candidates = instance.views.exclude(catalogs__in=[instance.catalog]) \
.exclude(catalogs=None)

for view in view_candidates:
instance.views.remove(view)

# add views that are now available
view_candidates = View.objects.exclude(id__in=[v.id for v in instance.views.all()]) \
.filter_current_site() \
.filter_catalog(instance.catalog)
# .filter_group(self.request.user) \
# .filter_availability(self.request.user).exists()

for view in view_candidates:
instance.views.add(view)

0 comments on commit 88e4583

Please sign in to comment.