Пример #1
0
def feeds(request):
    feeds = Feed.get_feeds(api_user=request.user,
                           index=0,
                           size=FEEDS_NUM_PAGES)
    # 最終更新時間
    last_reload = str(datetime.datetime.now())
    # anonymous以外の全ユーザを返却する
    users_list = STIPUser.objects.filter(is_active=True).exclude(
        username='******').order_by('username')

    if feeds:
        # feedsがあれば、 last_feedを一番最新のfeed id に指定する
        from_feed = feeds[0].package_id
    else:
        from_feed = None

    r = render(
        request, 'feeds/feeds.html', {
            'feeds': feeds,
            'jira': imported_jira,
            'from_feed': from_feed,
            'last_reload': last_reload,
            'page': 1,
            'users': users_list,
            'sharing_groups': Group.objects.all(),
        })
    r.set_cookie(key='username', value=str(request.user))
    return r
Пример #2
0
def profile(request, username):
    page_user = get_object_or_404(User, username=username)
    feeds = Feed.get_feeds(api_user=request.user,
                           user_id=page_user.id,
                           index=0,
                           size=FEEDS_NUM_PAGES)

    from_feed = None
    if feeds:
        from_feed = feeds[0].package_id
    return render(request, 'core/profile.html', {
        'page_user': page_user,
        'feeds': feeds,
        'from_feed': from_feed,
        'page': 1
    })
Пример #3
0
def load(request):
    from_feed = request.GET.get('from_feed')
    page = int(request.GET.get('page'))
    feed_source = request.GET.get('feed_source')
    user_id = None
    if feed_source is not None:
        if feed_source != 'all':
            user_id = feed_source
    # from_feed 指定の STIXPacakge ID の produced 時間を取得する
    if from_feed != 'None':
        # from_feed が設定されている場合
        package_from_feed = rs.get_package_info_from_package_id(
            request.user, from_feed)
        produced_str = package_from_feed['produced']

        # RS から produced 時間より古い最新の Feed を取得する
        last_reload = Feed.get_datetime_from_string(produced_str)

        # Feed 取得する
        index = (page - 1) * FEEDS_NUM_PAGES
        feeds = Feed.get_feeds(api_user=request.user,
                               last_reload=last_reload,
                               user_id=user_id,
                               index=index,
                               size=FEEDS_NUM_PAGES)
    else:
        # from_feed が設定されていない場合 (投稿がない場合)
        feeds = []
    html = ''
    csrf_token = (csrf(request)['csrf_token'])
    for feed in feeds:
        html = '{0}{1}'.format(
            html,
            render_to_string(
                'feeds/partial_feed.html', {
                    'feed': feed,
                    'jira': imported_jira,
                    'user': request.user,
                    'csrf_token': csrf_token,
                }))
    return HttpResponse(html)
Пример #4
0
def update(request):
    first_feed_datetime = get_datetime_from_string(
        request.GET.get('first_feed'))
    last_feed_datetime = get_datetime_from_string(request.GET.get('last_feed'))
    feed_source = request.GET.get('feed_source')
    feeds = Feed.get_feeds(
        range_big_datetime=first_feed_datetime,  # 期間範囲指定の大きい方(新しい方)。この時間を含む
        range_small_datetime=last_feed_datetime,  # 期間範囲指定の小さい方(古い方)。この時間を含む
        api_user=request.user)

    if feed_source != 'all':
        l = []
        for feed in feeds:
            if feed.package_id == feed_source:
                l.append(feed)
        feeds = l
    dump = {}
    for feed in feeds:
        feed = Feed.add_like_comment_info(request.user, feed)
        dump[feed.pk] = {'likes': feed.likes, 'comments': feed.comments}
    data = json.dumps(dump)
    return HttpResponse(data, content_type='application/json')