Skip to content

Commit

Permalink
- Fixes "guardian.exceptions.ObjectNotPersisted: Object None needs t…
Browse files Browse the repository at this point in the history
…o be persisted first" exception on "set_workflow_perms" calls

(cherry picked from commit fe35d46)
  • Loading branch information
afabiani committed Nov 23, 2020
1 parent e96f96f commit 72d59d6
Showing 1 changed file with 35 additions and 32 deletions.
67 changes: 35 additions & 32 deletions geonode/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,49 +877,52 @@ def save(self, notify=False, *args, **kwargs):
"""
Send a notification when a resource is created or updated
"""
_notification_sent = False
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:
# Resource Updated
_notification_sent = False

# Approval Notifications Here
if 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

# 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})

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

# 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})

self.__is_approved = self.is_approved
self.__is_published = self.is_published

Expand Down

0 comments on commit 72d59d6

Please sign in to comment.