2013-09-28 56 views
2

我刚刚设置了django-activity-stream,但无法显示我的操作时,我得到了内置模板mysite.com/activity/。但是,如果我查看管理网站,我可以看到这些操作已按预期保存。我使用的Django allauth认证/授权django-activity-stream操作不显示

MYAPP/Settings.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的活动流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最终成为无,并且查询集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 

回答

1

我已经成功通过传递useractor_stream()而不是user_stream()获得登录用户当前的行动/活动列表。但我不知道为什么user_stream不按预期工作

0

如果您的用户想要显示的动作,您需要通过with_user_activity=Trueuser_stream;如果是用于其他用户,则需要先关注他们。