diff --git a/geonode/base/models.py b/geonode/base/models.py index 095ad42a2d0..d0cfd84d50c 100644 --- a/geonode/base/models.py +++ b/geonode/base/models.py @@ -881,48 +881,47 @@ def save(self, notify=False, *args, **kwargs): if hasattr(self, 'class_name') and (self.pk is None or notify): if self.pk is None and self.title: # Resource Created + notice_type_label = '%s_created' % self.class_name.lower() recipients = get_notification_recipients(notice_type_label, resource=self) send_notification(recipients, notice_type_label, {'resource': self}) _notification_sent = True - else: + elif self.pk: # Resource Updated - _notification_sent = False - - super(ResourceBase, self).save(*args, **kwargs) - - # Approval Notifications Here - if not _notification_sent and settings.ADMIN_MODERATE_UPLOADS: - if self.is_approved and not self.is_published and \ - self.__is_approved != self.is_approved: - # Set "approved" workflow permissions - self.set_workflow_perms(approved=True) - - # Send "approved" notification - notice_type_label = '%s_approved' % self.class_name.lower() - recipients = get_notification_recipients(notice_type_label, resource=self) - send_notification(recipients, notice_type_label, {'resource': self}) - _notification_sent = True - - # Publishing Notifications Here - if not _notification_sent and settings.RESOURCE_PUBLISHING: - if self.is_approved and self.is_published and \ - self.__is_published != self.is_published: - # Set "published" workflow permissions - self.set_workflow_perms(published=True) - # Send "published" notification - notice_type_label = '%s_published' % self.class_name.lower() - recipients = get_notification_recipients(notice_type_label, resource=self) - send_notification(recipients, notice_type_label, {'resource': self}) - _notification_sent = True + # Approval Notifications Here + if not _notification_sent and settings.ADMIN_MODERATE_UPLOADS: + if not self.__is_approved and self.is_approved: + # Set "approved" workflow permissions + self.set_workflow_perms(approved=True) + + # Send "approved" notification + notice_type_label = '%s_approved' % self.class_name.lower() + recipients = get_notification_recipients(notice_type_label, resource=self) + send_notification(recipients, notice_type_label, {'resource': self}) + _notification_sent = True + + # Publishing Notifications Here + if not _notification_sent and settings.RESOURCE_PUBLISHING: + if not self.__is_published and self.is_published: + # Set "published" workflow permissions + self.set_workflow_perms(published=True) + + # Send "published" notification + notice_type_label = '%s_published' % self.class_name.lower() + recipients = get_notification_recipients(notice_type_label, resource=self) + send_notification(recipients, notice_type_label, {'resource': self}) + _notification_sent = True + + # Updated Notifications Here + if not _notification_sent: + notice_type_label = '%s_updated' % self.class_name.lower() + recipients = get_notification_recipients(notice_type_label, resource=self) + send_notification(recipients, notice_type_label, {'resource': self}) - # Updated Notifications Here - if not _notification_sent: - notice_type_label = '%s_updated' % self.class_name.lower() - recipients = get_notification_recipients(notice_type_label, resource=self) - send_notification(recipients, notice_type_label, {'resource': self}) + _notification_sent = False + super(ResourceBase, self).save(*args, **kwargs) self.__is_approved = self.is_approved self.__is_published = self.is_published diff --git a/geonode/geoserver/tasks.py b/geonode/geoserver/tasks.py index e38db580590..65976c2245e 100644 --- a/geonode/geoserver/tasks.py +++ b/geonode/geoserver/tasks.py @@ -88,7 +88,13 @@ def geoserver_post_save_layers( """ Runs update layers. """ - instance = Layer.objects.get(id=instance_id) + instance = None + try: + instance = Layer.objects.get(id=instance_id) + except Layer.DoesNotExist: + logger.error(f"Layer id {instance_id} does not exist yet!") + return + # Don't run this signal if is a Layer from a remote service if getattr(instance, "remote_service", None) is not None: return