From be8b26de6634a4cdf4717224cb488b887f25bfde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20Schr=C3=B6der?= Date: Fri, 22 Nov 2024 20:13:21 +0100 Subject: [PATCH 1/2] fix: remove views if catalog is changed --- rdmo/projects/handlers.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/rdmo/projects/handlers.py b/rdmo/projects/handlers.py index 6f65709cbe..a72cdfa17d 100644 --- a/rdmo/projects/handlers.py +++ b/rdmo/projects/handlers.py @@ -2,7 +2,8 @@ from django.contrib.auth.models import User from django.contrib.sites.models import Site -from django.db.models.signals import m2m_changed +from django.db.models import Q +from django.db.models.signals import m2m_changed, post_save from django.dispatch import receiver from rdmo.projects.models import Membership, Project @@ -58,3 +59,23 @@ def m2m_changed_view_groups_signal(sender, instance, **kwargs): projects = Project.objects.filter(memberships__in=list(memberships), catalog__in=catalogs, views=instance) for project in projects: project.views.remove(instance) + + +@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) From 4c83585f751704522d50a10c45ca0434423fe51a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20Schr=C3=B6der?= Date: Fri, 22 Nov 2024 20:25:43 +0100 Subject: [PATCH 2/2] refactor: cleanup unused import --- rdmo/projects/handlers.py | 1 - 1 file changed, 1 deletion(-) diff --git a/rdmo/projects/handlers.py b/rdmo/projects/handlers.py index a72cdfa17d..194ae15ee8 100644 --- a/rdmo/projects/handlers.py +++ b/rdmo/projects/handlers.py @@ -2,7 +2,6 @@ from django.contrib.auth.models import User from django.contrib.sites.models import Site -from django.db.models import Q from django.db.models.signals import m2m_changed, post_save from django.dispatch import receiver