Пример #1
0
def story_post_save(sender, **kwargs):
    """
    A signal for sending push notification to contributors and viewers
    """
    if kwargs.get('created') is False:
        return

    story = kwargs.get('instance')

    update_story_access.delay(story)

    # Queue the task to calculate and update permissions
    story_permission_notifications.delay(story=story)

    # Create an activity for the current user to follow the story
    new_activities = [
        Activity(content_object=story,
                 user=story.author,
                 type=Activity.FOLLOW_STORY)
    ]
    # Story author has already viewed the story
    new_activities.extend([
        Activity(content_object=story, user=story.author, type=Activity.VIEW)
    ])
    Activity.objects.bulk_create(new_activities)
Пример #2
0
def story_pre_save(sender, **kwargs):
    story = kwargs.get('instance')
    if not story.pk:
        """ This is probably a new story """
        """ Don't do anything here """
        return
    """ Get the old instance from the database """
    oldStory = Story.objects.get(pk=story.pk)
    if not oldStory:
        """ 
        There was no copy of old story in the database. This is probably a new story 
        Let the post_save signal handle new signals for now
        """
        return
    """ 
    This is a PUT. Check if the permissions have changed, and if so, invalidate the userPermissions for this story
    """
    old_user_read_permissions = oldStory.readAccess
    new_user_read_permissions = story.readAccess
    old_user_write_permissions = oldStory.writeAccess
    new_user_write_permissions = story.writeAccess
    if not (cmp(old_user_read_permissions, new_user_read_permissions) == 0 and
            cmp(old_user_write_permissions, new_user_write_permissions) == 0):
        update_story_access.delay(story)
        # Queue the task to calculate and update permissions
        story_permission_notifications.delay(story=story)
Пример #3
0
def story_pre_save(sender, **kwargs):
    story = kwargs.get('instance')
    if not story.pk:
        """ This is probably a new story """
        """ Don't do anything here """
        return
    
    """ Get the old instance from the database """
    oldStory = Story.objects.get(pk=story.pk)
    if not oldStory:
        """ 
        There was no copy of old story in the database. This is probably a new story 
        Let the post_save signal handle new signals for now
        """
        return

    """ 
    This is a PUT. Check if the permissions have changed, and if so, invalidate the userPermissions for this story
    """
    old_user_read_permissions = oldStory.readAccess
    new_user_read_permissions = story.readAccess
    old_user_write_permissions = oldStory.writeAccess
    new_user_write_permissions = story.writeAccess
    if not (cmp(old_user_read_permissions, new_user_read_permissions) == 0 and cmp(old_user_write_permissions, new_user_write_permissions) == 0):
        update_story_access.delay(story)
        # Queue the task to calculate and update permissions
        story_permission_notifications.delay(story = story)
Пример #4
0
def story_post_save(sender, **kwargs):
    """
    A signal for sending push notification to contributors and viewers
    """
    if kwargs.get('created') is False:
        return

    story = kwargs.get('instance')
        
    update_story_access.delay(story)

    # Queue the task to calculate and update permissions
    story_permission_notifications.delay(story = story)
    
    # Create an activity for the current user to follow the story
    new_activities = [Activity(content_object = story, user = story.author, type = Activity.FOLLOW_STORY)]
    # Story author has already viewed the story
    new_activities.extend([Activity(content_object = story, user = story.author, type = Activity.VIEW)])
    Activity.objects.bulk_create(new_activities)