3

我刚刚设置了 django-activity-stream,但是当我转到内置模板 mysite.com/activity/ 时,它无法显示我的操作。但是,如果我检查管理站点,我可以看到操作已按预期保存。我正在使用 django-allauth 进行身份验证/授权

我的应用程序/设置.py

ACTSTREAM_SETTINGS = {
    'MODELS': ('auth.user', 'auth.group'),
    'MANAGER': 'actstream.managers.ActionManager',
    'FETCH_RELATIONS': True,
    'USE_PREFETCH': True,
    'USE_JSONFIELD': True,
    'GFK_FETCH_DEPTH': 0,
}

myapp/receivers.py

    from actstream import action
    @receiver(user_logged_in)
    def handle_user_logged_in(sender, **kwargs):
        request = kwargs.get("request")
        user = kwargs['user']
        action.send(user, verb='logged in')

在 django-activity-stream 中views.py,它似乎models.user_stream(request.user)返回空。但我不知道为什么。

actstream/views.py

  @login_required
    def stream(request):
        """
        Index page for authenticated user's activity stream. (Eg: Your feed at
        github.com)
        """
        return render_to_response(('actstream/actor.html', 'activity/actor.html'), {
            'ctype': ContentType.objects.get_for_model(User),
            'actor': request.user, 'action_list': models.user_stream(request.user)
        }, context_instance=RequestContext(request))

从中进行调试models.userstream(request.user)似乎我发现它没有返回任何结果:

actstream/managers.py

 @stream
    def user(self, object, **kwargs):
        """
        Stream of most recent actions by objects that the passed User object is
        following.
        """
        q = Q()
        qs = self.filter(public=True)
        actors_by_content_type = defaultdict(lambda: [])
        others_by_content_type = defaultdict(lambda: [])

        follow_gfks = get_model('actstream', 'follow').objects.filter(
            user=object).values_list('content_type_id',
                                     'object_id', 'actor_only')

        if not follow_gfks:
            return qs.none()

当我检查值时,q = self.filter我实际上可以看到我通过的用户的所有正确“登录”活动,但是当它到达时,follow_gfks = get_model因为有问题的用户没有关注其他任何人,follow_gfks最终结果是 None 并且查询集qs被删除在最后一行。

当我只是想查看我自己的用户活动提要时,为什么会这样工作,我不知道。

这是我的 actstream_action 表中的一行的样子:

id                              1
actor_content_type_id           [fk]3
actor_object_id                 2
verb                            logged in
description                     NULL
target_content_type_id          NULL
target_object_id                NULL
action_object_content_type_id   NULL    
action_object_object_id         NULL
timestamp                       2013-09-28 12:58:41.499694+00
public                          TRUE
data                            NULL
4

2 回答 2

1

如果您要为其显示操作的是您的用户,则需要传递with_user_activity=Trueuser_stream; 如果是其他用户,您需要先关注他们。

于 2014-09-19T00:08:08.523 回答
1

我设法通过传递useractor_stream()而不是获取当前登录用户的操作/活动列表user_stream()。但我不知道为什么user_stream不能按预期工作

于 2013-09-29T15:07:08.457 回答