Esempio n. 1
0
def action_handler(verb, **kwargs):
    """
    Handler function to create Action instance upon action signal call.
    """
    from actstream.models import Action

    kwargs.pop("signal", None)
    actor = kwargs.pop("sender")
    if actor is None:
        ctype, oid = None, None
    else:
        check_actionable_model(actor)
        ctype = ContentType.objects.get_for_model(actor)
        oid = actor.pk
    newaction = Action(
        actor_content_type=ctype,
        actor_object_id=oid,
        verb=unicode(verb),
        public=bool(kwargs.pop("public", True)),
        description=kwargs.pop("description", None),
        timestamp=kwargs.pop("timestamp", datetime.now()),
    )

    for opt in ("target", "action_object"):
        obj = kwargs.pop(opt, None)
        if not obj is None:
            check_actionable_model(obj)
            setattr(newaction, "%s_object_id" % opt, obj.pk)
            setattr(newaction, "%s_content_type" % opt, ContentType.objects.get_for_model(obj))

    newaction.save()
Esempio n. 2
0
def action_handler(verb, **kwargs):
    """
    Handler function to create Action instance upon action signal call.
    """
    from actstream.models import Action

    kwargs.pop('signal', None)
    actor = kwargs.pop('sender')
    check_actionable_model(actor)

    # We must store the unstranslated string
    # If verb is an ugettext_lazyed string, fetch the original string
    if hasattr(verb, '_proxy____args'):
        verb = verb._proxy____args[0]

    newaction = Action(
        actor_content_type=ContentType.objects.get_for_model(actor),
        actor_object_id=actor.pk,
        verb=unicode(verb),
        public=bool(kwargs.pop('public', True)),
        description=kwargs.pop('description', None),
        timestamp=kwargs.pop('timestamp', now())
    )

    for opt in ('target', 'action_object'):
        obj = kwargs.pop(opt, None)
        if not obj is None:
            check_actionable_model(obj)
            setattr(newaction, '%s_object_id' % opt, obj.pk)
            setattr(newaction, '%s_content_type' % opt,
                    ContentType.objects.get_for_model(obj))
    if settings.USE_JSONFIELD and len(kwargs):
        newaction.data = kwargs
    newaction.save()
    return newaction
Esempio n. 3
0
def action_handler(verb, **kwargs):
    """
    Handler function to create Action instance upon action signal call.
    """
    from actstream.models import Action

    kwargs.pop('signal', None)
    actor = kwargs.pop('sender')
    check_actionable_model(actor)
    newaction = Action(
        actor_content_type=ContentType.objects.get_for_model(actor),
        actor_object_id=actor.pk,
        verb=unicode(verb),
        public=bool(kwargs.pop('public', True)),
        description=kwargs.pop('description', None),
        timestamp=kwargs.pop('timestamp', now()),
        data=kwargs.pop('data', None),
    )

    for opt in ('target', 'action_object'):
        obj = kwargs.pop(opt, None)
        if not obj is None:
            check_actionable_model(obj)
            setattr(newaction, '%s_object_id' % opt, obj.pk)
            setattr(newaction, '%s_content_type' % opt,
                    ContentType.objects.get_for_model(obj))

    newaction.save()
Esempio n. 4
0
def action_handler(verb, **kwargs):
    """
    Handler function to create Action instance upon action signal call.
    """
    from actstream.models import Action

    kwargs.pop('signal', None)
    actor = kwargs.pop('sender')
    check_actionable_model(actor)

    # We must store the unstranslated string
    # If verb is an ugettext_lazyed string, fetch the original string
    if hasattr(verb, '_proxy____args'):
        verb = verb._proxy____args[0]

    newaction = Action(
        actor_content_type=ContentType.objects.get_for_model(actor),
        actor_object_id=actor.pk,
        verb=unicode(verb),
        public=bool(kwargs.pop('public', True)),
        description=kwargs.pop('description', None),
        timestamp=kwargs.pop('timestamp', now())
    )

    for opt in ('target', 'action_object'):
        obj = kwargs.pop(opt, None)
        if not obj is None:
            check_actionable_model(obj)
            setattr(newaction, '%s_object_id' % opt, obj.pk)
            setattr(newaction, '%s_content_type' % opt,
                    ContentType.objects.get_for_model(obj))
    if settings.USE_JSONFIELD and len(kwargs):
        newaction.data = kwargs
    newaction.save()
Esempio n. 5
0
def action_create(actor,
                  verb,
                  action_object,
                  target,
                  description=None,
                  public=True):
    """
    Handler function to create Action instance upon action signal call.
    """
    # Prevent AnonymousUser from not passing the checks
    if actor.is_anonymous():
        actor = User.objects.get(id=settings.ANONYMOUS_USER_ID)

    check_actionable_model(actor)
    check_actionable_model(action_object)
    check_actionable_model(target)

    newaction = Action(
        actor_content_type=ContentType.objects.get_for_model(actor),
        actor_object_id=actor.pk,
        verb=unicode(verb),
        target_object_id=target.id,
        target_content_type=ContentType.objects.get_for_model(target),
        action_object_object_id=action_object.id,
        action_object_content_type=ContentType.objects.get_for_model(
            action_object),
        public=bool(public),
        description=description,
        timestamp=datetime.datetime.now(),
    )

    newaction.save()

    return newaction
Esempio n. 6
0
def place_action_handler(verb, **kwargs):
    """
    Handler function to create Action instance upon action signal call.
    """
    kwargs.pop('signal', None)

    actor = kwargs.pop('sender', None)
    if not actor:
        actor = User.objects.get(pk=settings.ACTIVITY_STREAM_DEFAULT_ACTOR_PK)
    check_actionable_model(actor)

    newaction = Action(
        actor_content_type=ContentType.objects.get_for_model(actor),
        actor_object_id=actor.pk,
        verb=unicode(verb),
        place=kwargs.pop('place',
                         None),  # TODO get automatically from target obj?
        public=bool(kwargs.pop('public', True)),
        description=kwargs.pop('description', None),
        timestamp=kwargs.pop('timestamp', now()))

    for opt in ('target', 'action_object'):
        obj = kwargs.pop(opt, None)
        if not obj is None:
            check_actionable_model(obj)
            setattr(newaction, '%s_object_id' % opt, obj.pk)
            setattr(newaction, '%s_content_type' % opt,
                    ContentType.objects.get_for_model(obj))

    if actstream_settings.USE_JSONFIELD and len(kwargs):
        newaction.data = kwargs
    newaction.save()
Esempio n. 7
0
def action_handler(verb, **kwargs):
    """
    Handler function to create Action instance upon action signal call.
    """
    from actstream.models import Action

    kwargs.pop('signal', None)
    actor = kwargs.pop('sender')
    check_actionable_model(actor)
    newaction = Action(
        actor_content_type=ContentType.objects.get_for_model(actor),
        actor_object_id=actor.pk,
        verb=unicode(verb),
        public=bool(kwargs.pop('public', True)),
        description=kwargs.pop('description', None),
        timestamp=kwargs.pop('timestamp', now()))

    for opt in ('target', 'action_object'):
        obj = kwargs.pop(opt, None)
        if not obj is None:
            check_actionable_model(obj)
            setattr(newaction, '%s_object_id' % opt, obj.pk)
            setattr(newaction, '%s_content_type' % opt,
                    ContentType.objects.get_for_model(obj))
    if len(kwargs):
        newaction.data = kwargs
    newaction.save()
def action_create(actor, verb, action_object, target, description=None, public=True):
    """
    Handler function to create Action instance upon action signal call.
    """
    # Prevent AnonymousUser from not passing the checks
    if actor.is_anonymous():
        actor = User.objects.get(id=settings.ANONYMOUS_USER_ID)
    
    check_actionable_model(actor)
    check_actionable_model(action_object)
    check_actionable_model(target)
    
    newaction = Action(
        actor_content_type=ContentType.objects.get_for_model(actor),
        actor_object_id=actor.pk,
        verb=unicode(verb),
        target_object_id=target.id,
        target_content_type=ContentType.objects.get_for_model(target),
        action_object_object_id=action_object.id,
        action_object_content_type=ContentType.objects.get_for_model(action_object), 

        public=bool(public),
        description=description,
        timestamp=datetime.datetime.now(),
    )

    newaction.save()

    return newaction
Esempio n. 9
0
def place_action_handler(verb, **kwargs):
    """
    Handler function to create Action instance upon action signal call.
    """
    kwargs.pop("signal", None)

    actor = kwargs.pop("sender", None)
    if not actor:
        actor = User.objects.get(pk=settings.ACTIVITY_STREAM_DEFAULT_ACTOR_PK)
    check_actionable_model(actor)

    newaction = Action(
        actor_content_type=ContentType.objects.get_for_model(actor),
        actor_object_id=actor.pk,
        verb=unicode(verb),
        place=kwargs.pop("place", None),  # TODO get automatically from target obj?
        public=bool(kwargs.pop("public", True)),
        description=kwargs.pop("description", None),
        timestamp=kwargs.pop("timestamp", now()),
    )

    for opt in ("target", "action_object"):
        obj = kwargs.pop(opt, None)
        if not obj is None:
            check_actionable_model(obj)
            setattr(newaction, "%s_object_id" % opt, obj.pk)
            setattr(newaction, "%s_content_type" % opt, ContentType.objects.get_for_model(obj))

    if actstream_settings.USE_JSONFIELD and len(kwargs):
        newaction.data = kwargs
    newaction.save()
Esempio n. 10
0
def add_action(actor, verb, action_object, description, target):
    """
    API to add Action to database:
    actor: Performer of Action
    verb: Action Performed
    action_object: object related to Action if any
    description: details on the action
    target: Who or what the action was done for or on.
    """

    new_action = Action(actor=actor,
                        verb=verb,
                        action_object=action_object,
                        description=description,
                        target=target)
    new_action.save()

    if isinstance(action_object, Task):
        items = TaggedItem.objects.filter(object_id=action_object.id)
        for item in items:
            follows = Follow.objects.filter(followed_skill=item.tag)
            for follow in follows:
                if follow.follower.username != actor.username:
                    if isinstance(target, UserProfile):
                        if follow.follower.username != target.username:
                            p['stream_' +
                              str(follow.follower.username)].trigger(
                                  'liveStream', {})
                    else:
                        p['stream_' + str(follow.follower.username)].trigger(
                            'liveStream', {})

    followers = Follow.objects.filter(followed__id=actor.id)
    for item in followers:
        if item.follower.username != actor.username:
            if isinstance(target, UserProfile):
                if item.follower.username != target.username:
                    p['stream_' + str(item.follower.username)].trigger(
                        'liveStream', {})
            else:
                p['stream_' + str(item.follower.username)].trigger(
                    'liveStream', {})

    p['stream_' + str(actor.username)].trigger('liveStream', {})
    if isinstance(target, UserProfile) and target.username != actor.username:
        p['stream_' + str(target.username)].trigger('liveStream', {})

    if verb == "task_post" or verb == "task_assigned":
        p['discover'].trigger('discover_shoghlanah', {})

    return new_action
Esempio n. 11
0
def action(actor, verb, action_object=None, target=None, public=True):
    '''using the signal api doesn't give us a ref to the new action...'''
    # this'll cause some circular dep problems...
    from actstream.models import Action
    newaction = Action(
        actor_content_type=ContentType.objects.get_for_model(actor),
        actor_object_id=actor.pk,
        verb=unicode(verb),
        public=public,
        timestamp=datetime.datetime.now())
    if action_object:
        newaction.action_object = action_object
        newaction.action_object_content_type = ContentType.objects.get_for_model(action_object)
    if target:
        newaction.target = target
        newaction.target_content_type = ContentType.objects.get_for_model(target)
    newaction.save()
    return newaction
def action_handler(sender, verb, **kwargs):
    from actstream.models import Action

    target = kwargs.get('target', None)
    public = kwargs.get('public', True)
    description = kwargs.get('description', None)
    timestamp = kwargs.get('timestamp', datetime.now())
    action = Action(actor_content_type=ContentType.objects.get_for_model(sender),
                    actor_object_id=sender.pk,
                    verb=unicode(verb),
                    public=public,
                    timestamp = timestamp,
                    description = description)
    if target:
        action.target_object_id = target.pk
        action.target_content_type = ContentType.objects.get_for_model(target)

    action.save()
Esempio n. 13
0
def action(actor, verb, action_object=None, target=None, public=True):
    '''using the signal api doesn't give us a ref to the new action...'''
    # this'll cause some circular dep problems...
    from actstream.models import Action
    newaction = Action(
        actor_content_type=ContentType.objects.get_for_model(actor),
        actor_object_id=actor.pk,
        verb=unicode(verb),
        public=public,
        timestamp=datetime.datetime.now())
    if action_object:
        newaction.action_object = action_object
        newaction.action_object_content_type = ContentType.objects.get_for_model(action_object)
    if target:
        newaction.target = target
        newaction.target_content_type = ContentType.objects.get_for_model(target)
    newaction.save()
    return newaction
def add_action(actor, verb, action_object, description, target):
    """
    API to add Action to database:
    actor: Performer of Action
    verb: Action Performed
    action_object: object related to Action if any
    description: details on the action
    target: Who or what the action was done for or on.
    """

    new_action = Action(actor=actor, verb=verb, action_object=action_object, description=description, target=target)
    new_action.save()  
    
    if isinstance(action_object, Task):
        items = TaggedItem.objects.filter(object_id=action_object.id)
        for item in items:
            follows = Follow.objects.filter(followed_skill=item.tag)
            for follow in follows:
                if follow.follower.username != actor.username:
                    if isinstance(target, UserProfile):
                        if follow.follower.username != target.username:
                            p['stream_' + str(follow.follower.username)].trigger('liveStream', {})
                    else:
                        p['stream_' + str(follow.follower.username)].trigger('liveStream', {})

    followers = Follow.objects.filter(followed__id=actor.id)
    for item  in followers:
        if item.follower.username != actor.username:
            if isinstance(target, UserProfile):
                if item.follower.username != target.username:
                    p['stream_' + str(item.follower.username)].trigger('liveStream', {})
            else:            
                p['stream_' + str(item.follower.username)].trigger('liveStream', {})

    p['stream_' + str(actor.username)].trigger('liveStream', {})
    if isinstance(target, UserProfile) and target.username != actor.username:
        p['stream_' + str(target.username)].trigger('liveStream', {})
        

    if verb == "task_post" or verb == "task_assigned":
        p['discover'].trigger('discover_shoghlanah', {})

    return new_action
Esempio n. 15
0
def resource_permissions(request, resource_id):
    try:
        resource = resolve_object(
            request, ResourceBase, {
                'id': resource_id}, 'base.change_resourcebase_permissions')
        resource_content_type = ContentType.objects.get_for_model(resource).id

    except PermissionDenied:
        # we are handling this in a non-standard way
        return HttpResponse(
            'You are not allowed to change permissions for this resource',
            status=401,
            mimetype='text/plain')

    if request.method == 'POST':
        permission_spec = json.loads(request.body)
        old_permission_spec = resource.get_all_level_info()

        for user in permission_spec['users']:
            user = get_user_model().objects.get(username=user)
            if user not in old_permission_spec['users']:
                action = Action(
                    actor=request.user, 
                    action_object_id=resource.id,
                    action_object_content_type_type=resource_content_type,
                    target=user,
                    verb='permission_granted')
                action.save()
            else:
                old_permission_spec['users'].pop(user)

        resource.set_permissions(permission_spec)

        for user in old_permission_spec['users']:
            action = Action(
                actor=request.user, 
                action_object_id=resource.id,
                action_object_content_type=resource_content_type,
                target=user,
                verb='permission_revoked')
            action.save()


        return HttpResponse(
            json.dumps({'success': True}),
            status=200,
            mimetype='text/plain'
        )

    elif request.method == 'GET':
        permission_spec = _perms_info_json(resource)
        return HttpResponse(
            json.dumps({'success': True, 'permissions': permission_spec}),
            status=200,
            mimetype='text/plain'
        )
    else:
        return HttpResponse(
            'No methods other than get and post are allowed',
            status=401,
            mimetype='text/plain')