def concept_saved(message): instance = safe_object(message) if not instance: return for p in instance.favourited_by.all(): if sorted(message['changed_fields']) == ['modified', 'superseded_by_id']: messages.favourite_superseded(recipient=p.user, obj=instance) else: messages.favourite_updated(recipient=p.user, obj=instance) # for status in instance.current_statuses().all(): # for registrar in status.registrationAuthority.registrars.all(): # if sorted(message['changed_fields']) == ['modified', 'superseded_by_id']: # messages.registrar_item_superseded(recipient=registrar, obj=instance) if instance.workgroup: for user in instance.workgroup.viewers.all(): if message['created']: messages.workgroup_item_new(recipient=user, obj=instance) else: messages.workgroup_item_updated(recipient=user, obj=instance) for post in instance.relatedDiscussions.all(): DiscussionComment.objects.create( post=post, body='The item "{name}" (id:{iid}) has been changed.\n\n\ <a href="{url}">View it on the main site.</a>.'.format( name=instance.name, iid=instance.id, url=reverse("aristotle:item", args=[instance.id]) ), author=None, )
def concept_saved(sender, instance, created, **kwargs): if not issubclass(sender, _concept): return if not instance.non_cached_fields_changed: # If the only thing that has changed is a cached public/locked status # then don't notify. return if kwargs.get('raw'): # Don't run during loaddata return for p in instance.favourited_by.all(): messages.favourite_updated(recipient=p.user, obj=instance) if instance.workgroup: for user in instance.workgroup.viewers.all(): if created: messages.workgroup_item_new(recipient=user, obj=instance) else: messages.workgroup_item_updated(recipient=user, obj=instance) try: # This will fail during first load, and if admins delete aristotle. system = User.objects.get(username="******") for post in instance.relatedDiscussions.all(): DiscussionComment.objects.create( post=post, body='The item "{name}" (id:{iid}) has been changed.\n\n\ <a href="{url}">View it on the main site.</a>.'.format( name=instance.name, iid=instance.id, url=reverse("aristotle:item", args=[instance.id])), author=system, ) except: pass
def concept_saved(sender, instance, created, **kwargs): if not issubclass(sender, _concept): return if not instance.non_cached_fields_changed: #If the only thing that has changed is a cached public/locked status then don't notify return if kwargs.get('raw'): # Don't run during loaddata return for p in instance.favourited_by.all(): messages.favourite_updated(recipient=p.user,obj=instance) for user in instance.workgroup.viewers.all(): if created: messages.workgroup_item_new(recipient=user,obj=instance) else: messages.workgroup_item_updated(recipient=user,obj=instance) try: # This will fail during first load, and if admins delete aristotle. system = User.objects.get(username="******") for post in instance.relatedDiscussions.all(): DiscussionComment.objects.create( post = post, body = 'The item "{name}" (id:{iid}) has been changed.\n\n\ <a href="{url}">View it on the main site.</a>.'.format( name=instance.name, iid = instance.id, url = reverse("aristotle:item",args=[instance.id]) ), author = system, ) except: pass
def create_notifications_for_saved_concept(message, **kwargs): user_model = get_user_model() try: user_email = user_model.objects.get(pk=message.get('user_id')).email except user_model.DoesNotExist: user_email = "" version = safe_object(message) object = version.object created = False if Version.objects.get_for_object(object).count() < 2: created = True for user in object.favourited_by: if user.email != user_email: messages.favourite_updated(recipient=user, obj=object) for user in object.editable_by: if not created: if user.email != user_email: messages.items_i_can_edit_updated(recipient=user, obj=object) if object.workgroup: for user in object.workgroup.users_for_role('viewer'): if user.email != user_email: if created: messages.workgroup_item_new(recipient=user, obj=object) else: messages.workgroup_item_updated(recipient=user, obj=object)
def concept_saved(message, **kwargs): instance = safe_object(message) for user in instance.favourited_by: messages.favourite_updated(recipient=user, obj=instance) for user in instance.editable_by: if not message['created']: messages.items_i_can_edit_updated(recipient=user, obj=instance) if instance.workgroup: for user in instance.workgroup.users_for_role('viewer'): if message['created']: messages.workgroup_item_new(recipient=user, obj=instance) else: messages.workgroup_item_updated(recipient=user, obj=instance)
def concept_saved(message): instance = safe_object(message) if not instance: return for user in instance.favourited_by: if sorted(message['changed_fields']) == ['modified', 'superseded_by_id']: messages.favourite_superseded(recipient=user, obj=instance) else: messages.favourite_updated(recipient=user, obj=instance) # for status in instance.current_statuses().all(): # for registrar in status.registrationAuthority.registrars.all(): # if sorted(message['changed_fields']) == ['modified', 'superseded_by_id']: # messages.registrar_item_superseded(recipient=registrar, obj=instance) if instance.workgroup: for user in instance.workgroup.viewers.all(): if message['created']: messages.workgroup_item_new(recipient=user, obj=instance) else: messages.workgroup_item_updated(recipient=user, obj=instance)
def concept_saved(message): instance = safe_object(message) if not instance: return for user in instance.favourited_by: if sorted( message['changed_fields']) == ['modified', 'superseded_by_id']: messages.favourite_superseded(recipient=user, obj=instance) else: messages.favourite_updated(recipient=user, obj=instance) # for status in instance.current_statuses().all(): # for registrar in status.registrationAuthority.registrars.all(): # if sorted(message['changed_fields']) == ['modified', 'superseded_by_id']: # messages.registrar_item_superseded(recipient=registrar, obj=instance) if instance.workgroup: for user in instance.workgroup.viewers.all(): if message['created']: messages.workgroup_item_new(recipient=user, obj=instance) else: messages.workgroup_item_updated(recipient=user, obj=instance)
def concept_saved(message): instance = safe_object(message) if not instance: return for p in instance.favourited_by.all(): if sorted(message["changed_fields"]) == ["modified", "superseded_by_id"]: messages.favourite_superseded(recipient=p.user, obj=instance) else: messages.favourite_updated(recipient=p.user, obj=instance) for status in instance.current_statuses().all(): for registrar in status.registrationAuthority.registrars.all(): if sorted(message["changed_fields"]) == ["modified", "superseded_by_id"]: messages.registrar_item_superseded(recipient=registrar, obj=instance) if instance.workgroup: for user in instance.workgroup.viewers.all(): if message["created"]: messages.workgroup_item_new(recipient=user, obj=instance) else: messages.workgroup_item_updated(recipient=user, obj=instance) try: # This will fail during first load, and if admins delete aristotle. system = User.objects.get(username="******") for post in instance.relatedDiscussions.all(): DiscussionComment.objects.create( post=post, body='The item "{name}" (id:{iid}) has been changed.\n\n\ <a href="{url}">View it on the main site.</a>.'.format( name=instance.name, iid=instance.id, url=reverse("aristotle:item", args=[instance.id]) ), author=system, ) except: pass