Example #1
0
def item_superseded(message, **kwargs):
    new_super_rel = safe_object(message)
    concept = new_super_rel.older_item

    for user in concept.favourited_by.all():
        if concept.can_view(user) and new_super_rel.newer_item.can_view(user):
            messages.favourite_superseded(recipient=user, obj=concept)

    for status in concept.current_statuses().all():
        for registrar in status.registrationAuthority.registrars.all():
            if concept.can_view(registrar) and new_super_rel.newer_item.can_view(registrar):
                messages.registrar_item_superseded(recipient=registrar, obj=concept)
def item_superseded(message, **kwargs):
    new_super_rel = safe_object(message)
    concept = new_super_rel.older_item

    for user in concept.favourited_by.all():
        if concept.can_view(user) and new_super_rel.newer_item.can_view(user):
            messages.favourite_superseded(recipient=user, obj=concept)

    for status in concept.current_statuses().all():
        for registrar in status.registrationAuthority.registrars.all():
            if concept.can_view(registrar) and new_super_rel.newer_item.can_view(registrar):
                messages.registrar_item_superseded(recipient=registrar, obj=concept)
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 = get_user_model().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 item_superseded(message, **kwargs):
    new_super_rel = safe_object(message)
    concept = new_super_rel.older_item

    for user in concept.favourited_by.all():
        if concept.can_view(user) and new_super_rel.newer_item.can_view(user):
            messages.favourite_superseded(recipient=user, obj=concept)

    for user in concept.editable_by:
        if concept.can_view(user) and new_super_rel.newer_item.can_view(user):
            messages.items_i_can_edit_superseded(recipient=user, obj=concept)

    if concept.workgroup:
        for user in concept.workgroup.users_for_role('viewer'):
            if concept.can_view(user) and new_super_rel.newer_item.can_view(user):
                messages.workgroup_item_superseded(recipient=user, obj=concept)

    for status in concept.current_statuses().all():
        for registrar in status.registrationAuthority.registrars.all():
            if concept.can_view(registrar) and new_super_rel.newer_item.can_view(registrar):
                messages.registrar_item_superseded(recipient=registrar, obj=concept, ra=status.registrationAuthority)
Example #5
0
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