コード例 #1
0
ファイル: views.py プロジェクト: vijayaprag/Tweet
def blog(request):
    # return render(request, "feeds/blog.html")
    all_feeds = Feed.get_feeds()
    paginator = Paginator(all_feeds, FEEDS_NUM_PAGES)
    feeds = paginator.page(1)
    from_feed = -1
    if feeds:
        from_feed = feeds[0].id
    users_list = User.objects.filter(is_active=True).order_by('username')
    paginator = Paginator(users_list, 15)
    page = request.GET.get('page')
    try:
        users = paginator.page(page)
    except PageNotAnInteger:
        users = paginator.page(1)

    except EmptyPage:  # pragma: no cover
        users = paginator.page(paginator.num_pages)

    return render(request, 'feeds/blog.html', {
        'blog': blog,
        'from_feed': from_feed,
        'page': 1,
        'users': users,
    })

    #class EditComments(LoginRequiredMixin, UpdateView):
    # template_name = 'feeds/edit.html'
    #model = Feed
    #form_class = ArticleForm
    #success_url = reverse_lazy('feeds')

    #def checking(func):
    """
コード例 #2
0
def profile(request, username):
    page_user = get_object_or_404(User, username=username)
    all_feeds = Feed.get_feeds().filter(user=page_user)
    paginator = Paginator(all_feeds, FEEDS_NUM_PAGES)
    feeds = paginator.page(1)
    from_feed = -1
    if feeds:  # pragma: no cover
        from_feed = feeds[0].id

    feeds_count = Feed.objects.filter(user=page_user).count()
    article_count = Article.objects.filter(create_user=page_user).count()
    article_comment_count = ArticleComment.objects.filter(
        user=page_user).count()
    activity_count = Activity.objects.filter(user=page_user).count()
    messages_count = Message.objects.filter(
        Q(from_user=page_user) | Q(user=page_user)).count()
    data, datepoints = Activity.daily_activity(page_user)
    data = {
        'page_user': page_user,
        'feeds_count': feeds_count,
        'article_count': article_count,
        'article_comment_count': article_comment_count,
        'global_interactions': activity_count + article_comment_count + messages_count,  # noqa: E501
        'bar_data': [
            feeds_count, article_count, article_comment_count, activity_count],
        'bar_labels': json.dumps('["Feeds", "Articles", "Comments", "Activities"]'),  # noqa: E501
        'line_labels': datepoints,
        'line_data': data,
        'feeds': feeds,
        'from_feed': from_feed,
        'page': 1
        }
    return render(request, 'core/profile.html', data)
コード例 #3
0
ファイル: views.py プロジェクト: echopen/kit-soft
def load(request):
    from_feed = request.GET.get('from_feed')
    page = request.GET.get('page')
    feed_source = request.GET.get('feed_source')
    all_feeds = Feed.get_feeds(from_feed)
    if feed_source != 'all':
        all_feeds = all_feeds.filter(user__id=feed_source)
    paginator = Paginator(all_feeds, FEEDS_NUM_PAGES)
    try:
        feeds = paginator.page(page)
    except PageNotAnInteger:
        return HttpResponseBadRequest()
    except EmptyPage:
        feeds = []
    html = u''
    csrf_token = unicode(csrf(request)['csrf_token'])
    for feed in feeds:
        html = u'{0}{1}'.format(html,
                                render_to_string('feeds/partial_feed.html',
                                                 {
                                                    'feed': feed,
                                                    'user': request.user,
                                                    'csrf_token': csrf_token
                                                    }))

    return HttpResponse(html)
コード例 #4
0
ファイル: views.py プロジェクト: manuelpalacin/bootcamp
def load(request):
    from_feed = request.GET.get('from_feed')
    page = request.GET.get('page')
    feed_source = request.GET.get('feed_source')
    all_feeds = Feed.get_feeds(from_feed)
    if feed_source != 'all':
        all_feeds = all_feeds.filter(user__id=feed_source)
    paginator = Paginator(all_feeds, FEEDS_NUM_PAGES)
    try:
        feeds = paginator.page(page)
    except PageNotAnInteger:
        return HttpResponseBadRequest()
    except EmptyPage:
        feeds = []
    html = u''
    csrf_token = unicode(csrf(request)['csrf_token'])
    for feed in feeds:
        html = u'{0}{1}'.format(
            html,
            render_to_string('feeds/partial_feed.html', {
                'feed': feed,
                'user': request.user,
                'csrf_token': csrf_token
            }))
    return HttpResponse(html)
コード例 #5
0
def update(request):
    first_feed = request.GET.get('first_feed')
    last_feed = request.GET.get('last_feed')
    feeds = Feed.get_feeds().filter(id__range=(last_feed, first_feed))
    dump = {}
    for feed in feeds:
        dump[feed.pk] = {'likes': feed.likes, 'comments': feed.comments}
    data = json.dumps(dump)
    return HttpResponse(data, mimetype='application/json')
コード例 #6
0
ファイル: views.py プロジェクト: BlastarIndia/bootcamp
def profile(request, username):
    page_user = User.objects.get(username=username)
    all_feeds = Feed.get_feeds().filter(user=page_user)
    paginator = Paginator(all_feeds, FEEDS_NUM_PAGES)
    feeds = paginator.page(1)
    from_feed = -1
    if feeds:
        from_feed = feeds[0].id
    return render(
        request, "core/profile.html", {"page_user": page_user, "feeds": feeds, "from_feed": from_feed, "page": 1}
    )
コード例 #7
0
ファイル: views.py プロジェクト: echopen/kit-soft
def feeds(request):
    all_feeds = Feed.get_feeds()
    paginator = Paginator(all_feeds, FEEDS_NUM_PAGES)
    feeds = paginator.page(1)
    from_feed = -1
    if feeds:
        from_feed = feeds[0].id
    return render(request, 'feeds/feeds.html', {
        'feeds': feeds,
        'from_feed': from_feed,
        'page': 1,
        })
コード例 #8
0
ファイル: views.py プロジェクト: manuelpalacin/bootcamp
def feeds(request):
    all_feeds = Feed.get_feeds()
    paginator = Paginator(all_feeds, FEEDS_NUM_PAGES)
    feeds = paginator.page(1)
    from_feed = -1
    if feeds:
        from_feed = feeds[0].id
    return render(request, 'feeds/feeds.html', {
        'feeds': feeds,
        'from_feed': from_feed,
        'page': 1,
    })
コード例 #9
0
ファイル: views.py プロジェクト: manuelpalacin/bootcamp
def update(request):
    first_feed = request.GET.get('first_feed')
    last_feed = request.GET.get('last_feed')
    feed_source = request.GET.get('feed_source')
    feeds = Feed.get_feeds().filter(id__range=(last_feed, first_feed))
    if feed_source != 'all':
        feeds = feeds.filter(user__id=feed_source)
    dump = {}
    for feed in feeds:
        dump[feed.pk] = {'likes': feed.likes, 'comments': feed.comments}
    data = json.dumps(dump)
    return HttpResponse(data, content_type='application/json')
コード例 #10
0
ファイル: test_senarios.py プロジェクト: ghsaheb/Bootcamp
    def test_senario1(self):
        self.aliLoggedIn()
        self.aliSendsPost('Who loves me?')
        self.aliLoggedOut()
        self.alisFeed = Feed.get_feeds().filter(user__id=self.ali.id)[0]
        self.poopakLoggedIn()
        self.poopakLikesAlisPost()
        self.poopakSendsCommentOnAlisPost('I love you baby!')
        self.aliLoggedIn()
        self.aliSendsCommentOnPoopaksComment('+989355246329')
        self.aliLoggedOut()
        self.poopakLoggedOut()

        alisFeeds = Feed.get_feeds().filter(user__id=self.ali.id)
        self.assertEquals(len(alisFeeds), 1)
        self.assertEquals(alisFeeds[0].post, 'Who loves me?')
        self.assertEquals(alisFeeds[0].calculate_likes(), 1)
        self.assertEqual(alisFeeds[0].get_likers()[0], self.poopak)
        self.assertEqual(alisFeeds[0].get_comments()[0].post,
                         'I love you baby!')
        self.assertEqual(alisFeeds[0].get_comments()[1].post, '+989355246329')
コード例 #11
0
ファイル: views.py プロジェクト: echopen/kit-soft
def update(request):
    first_feed = request.GET.get('first_feed')
    last_feed = request.GET.get('last_feed')
    feed_source = request.GET.get('feed_source')
    feeds = Feed.get_feeds().filter(id__range=(last_feed, first_feed))
    if feed_source != 'all':
        feeds = feeds.filter(user__id=feed_source)
    dump = {}
    for feed in feeds:
        dump[feed.pk] = {'likes': feed.likes, 'comments': feed.comments}
    data = json.dumps(dump)
    return HttpResponse(data, content_type='application/json')
コード例 #12
0
ファイル: views.py プロジェクト: Yihen/ibootcamp
def profile(request, username):
    page_user = get_object_or_404(User, username=username)
    tag = request.session.get("TRIBE_TAG")
    all_feeds = Feed.get_feeds(tag).filter(user=page_user)
    paginator = Paginator(all_feeds, FEEDS_NUM_PAGES)
    feeds = paginator.page(1)
    from_feed = -1
    if feeds:
        from_feed = feeds[0].id
    return render(
        request, "core/profile.html", {"page_user": page_user, "feeds": feeds, "from_feed": from_feed, "page": 1}
    )
コード例 #13
0
ファイル: views.py プロジェクト: Yihen/ibootcamp
def feeds(request):
    tag = request.session.get("TRIBE_TAG")
    all_feeds = Feed.get_feeds(tag)
    paginator = Paginator(all_feeds, FEEDS_NUM_PAGES)
    feeds = paginator.page(1)
    from_feed = -1
    if feeds:
        from_feed = feeds[0].id
    return render(request, 'feeds/feeds.html', {
        'feeds': feeds, 
        'from_feed': from_feed, 
        'page': 1,
        })
コード例 #14
0
ファイル: views.py プロジェクト: JWeesner/DjangoMetrics
def profile(request, username):
    page_user = get_object_or_404(User, username=username)
    all_feeds = Feed.get_feeds().filter(user=page_user)
    paginator = Paginator(all_feeds, FEEDS_NUM_PAGES)
    feeds = paginator.page(1)
    from_feed = -1
    if feeds:
        from_feed = feeds[0].id
    return render(request, 'core/profile.html', {
        'page_user': page_user,
        'feeds': feeds,
        'from_feed': from_feed,
        'page': 1
    })
コード例 #15
0
def feeds(request):
    # return all feeds whose parent is None
    # ordering by date descending
    all_feeds = Feed.get_feeds()
    paginator = Paginator(all_feeds, FEEDS_NUM_PAGES)
    feeds = paginator.page(1)
    from_feed = -1
    if feeds:
        from_feed = feeds[0].id  # maximum id of all feeds
    return render(request, 'feeds/feeds.html', {
        'feeds': feeds,
        'from_feed': from_feed,
        'page': 1,
    })
コード例 #16
0
ファイル: views.py プロジェクト: Allianzcortex/bootcamp
def profile(request, username):
    page_user = get_object_or_404(User, username=username)
    all_feeds = Feed.get_feeds().filter(user=page_user)
    paginator = Paginator(all_feeds, FEEDS_NUM_PAGES)
    feeds = paginator.page(1)
    from_feed = -1
    if feeds:
        from_feed = feeds[0].id
    return render(request, 'core/profile.html', {
        'page_user': page_user,
        'feeds': feeds,
        'from_feed': from_feed,
        'page': 1
        })
コード例 #17
0
ファイル: views.py プロジェクト: vijayaprag/Tweet
def feeds(request):
    all_feeds = Feed.get_feeds()
    paginator = Paginator(all_feeds, FEEDS_NUM_PAGES)
    feeds = paginator.page(1)
    from_feed = -1
    if feeds:
        from_feed = feeds[0].id

    users_list = User.objects.filter(is_active=True).order_by('username')
    #User.following.all() # all users this user is following
    #User.followed_by.all() # all users who follow this user
    paginator = Paginator(users_list, 15)
    page = request.GET.get('page')
    try:
        users = paginator.page(page)

    except PageNotAnInteger:
        users = paginator.page(1)

    except EmptyPage:  # pragma: no cover
        users = paginator.page(paginator.num_pages)

#all_articles = Feed.get_published()
#  paginator = Paginator(articles, 10)
# try:
#     articles = paginator.page(page)

# except PageNotAnInteger:
#    articles = paginator.page(1)

#except EmptyPage:   # pragma: no cover
#    articles = paginator.page(paginator.num_pages)

# popular_tags = Article.get_counted_tags()

    return render(
        request,
        'feeds/feeds.html',
        {
            'feeds': feeds,
            'from_feed': from_feed,
            'page': 1,
            'users': users,
            #'all_articles': all_articles,
            #'popular_tags': popular_tags,
        })
コード例 #18
0
def feeds(request):
    # 查看所有的主feed
    all_feeds = Feed.get_feeds()

    #分页,一次10个
    paginator = Paginator(all_feeds, FEEDS_NUM_PAGES)

    # 第一次加载,获取第一页
    feeds = paginator.page(1)
    from_feed = -1
    if feeds:
        from_feed = feeds[0].id
    return render(request, 'feeds/feeds.html', {
        'feeds': feeds,
        'from_feed': from_feed,
        'page': 1,
    })
コード例 #19
0
def profile(request, username):
    page_user = get_object_or_404(User, username=username)
    print type(page_user)
    all_feeds = Feed.get_feeds().filter(user=page_user)
    all_projects = Collaborator.get_published_by_user(page_user)
    print all_projects
    paginator = Paginator(all_feeds, FEEDS_NUM_PAGES)
    feeds = paginator.page(1)
    from_feed = -1
    if feeds:
        from_feed = feeds[0].id
    return render(request, 'core/profile.html', {
        'page_user': page_user,
        'feeds': feeds,
        'from_feed': from_feed,
        'page': 1,
        'projects':all_projects,
        })
コード例 #20
0
ファイル: views.py プロジェクト: lmeetr1984/bootcamp
def profile(request, username):
    # 获取用户的profile

    # 根据用户名找到用户, 否则一个404
    page_user = get_object_or_404(User, username=username)

    # 找到该用户的所有feed
    all_feeds = Feed.get_feeds().filter(user=page_user)
    # 获取10个
    paginator = Paginator(all_feeds, FEEDS_NUM_PAGES)
    feeds = paginator.page(1)
    from_feed = -1
    if feeds:
        from_feed = feeds[0].id

    # 用模版填充渲染,和flask没有什么区别
    return render(request, 'core/profile.html', {
        'page_user': page_user,
        'feeds': feeds,
        'from_feed': from_feed,
        'page': 1
    })
コード例 #21
0
def load(request):
    # 加载分页数据
    from_feed = request.GET.get('from_feed')
    page = request.GET.get('page')
    feed_source = request.GET.get('feed_source')

    # 从from_feed开始获取主feed
    all_feeds = Feed.get_feeds(from_feed)
    if feed_source != 'all':
        all_feeds = all_feeds.filter(user__id=feed_source)

    # 分页
    paginator = Paginator(all_feeds, FEEDS_NUM_PAGES)
    try:
        feeds = paginator.page(page)
    except PageNotAnInteger:
        return HttpResponseBadRequest()
    except EmptyPage:
        feeds = []
    html = u''

    # 重新计算一个csrftoken
    csrf_token = unicode(csrf(request)['csrf_token'])

    # 渲染一下
    # render_to_string: 用模版去format,返回string
    # 循环渲染,返回的是所有的feed的html string
    # 用于ajax append 到节点上
    for feed in feeds:
        html = u'{0}{1}'.format(html,
                                render_to_string('feeds/partial_feed.html',
                                                 {
                                                     'feed': feed,
                                                     'user': request.user,
                                                     'csrf_token': csrf_token
                                                 }))

    return HttpResponse(html)
コード例 #22
0
ファイル: views.py プロジェクト: ghsaheb/Bootcamp
def profile(request, username):
    page_user = get_object_or_404(User, username=username)
    all_feeds = Feed.get_feeds().filter(user=page_user)
    paginator = Paginator(all_feeds, FEEDS_NUM_PAGES)
    feeds = paginator.page(1)
    from_feed = -1
    if feeds:  # pragma: no cover
        from_feed = feeds[0].id

    feeds_count = Feed.objects.filter(user=page_user).count()
    article_count = Article.objects.filter(create_user=page_user).count()
    article_comment_count = ArticleComment.objects.filter(
        user=page_user).count()
    question_count = Question.objects.filter(user=page_user).count()
    answer_count = Answer.objects.filter(user=page_user).count()
    activity_count = Activity.objects.filter(user=page_user).count()
    messages_count = Message.objects.filter(
        Q(from_user=page_user) | Q(user=page_user)).count()
    data, datepoints = Activity.daily_activity(page_user)
    data = {
        'page_user': page_user,
        'feeds_count': feeds_count,
        'article_count': article_count,
        'article_comment_count': article_comment_count,
        'question_count': question_count,
        'global_interactions': activity_count + article_comment_count + answer_count + messages_count,  # noqa: E501
        'answer_count': answer_count,
        'bar_data': [
            feeds_count, article_count, article_comment_count, question_count,
            answer_count, activity_count],
        'bar_labels': json.dumps('["Feeds", "Articles", "Comments", "Questions", "Answers", "Activities"]'),  # noqa: E501
        'line_labels': datepoints,
        'line_data': data,
        'feeds': feeds,
        'from_feed': from_feed,
        'page': 1
        }
    return render(request, 'core/profile.html', data)
コード例 #23
0
ファイル: views.py プロジェクト: ssahilsahil798/socialnetwork
def feeds(request):
    all_feeds = Feed.get_feeds()
    paginator = Paginator(all_feeds, FEEDS_NUM_PAGES)
    feeds = paginator.page(1)
    # likers = Feed.get_likers()
    from_feed = -1
    if feeds:
        from_feed = feeds[0].id
    userhere = request.user

    notifications = userhere.usernoti.all().exclude(is_read=True)
    print notifications

    return render(
        request,
        'feeds/feeds.html',
        {
            'feeds': feeds,
            'from_feed': from_feed,
            'page': 1,
            'notifications': notifications
            # 'notifications': notifications
            # 'likers': likers
        })
コード例 #24
0
ファイル: test_models.py プロジェクト: ghsaheb/Bootcamp
 def test_getFeeds_withFromFeed1(self):
     feeds = Feed.get_feeds(self.feed2.id)
     self.assertEquals(len(feeds), 2)
     self.assertTrue(self.feed in feeds)
     self.assertTrue(self.feed2 in feeds)
コード例 #25
0
ファイル: test_models.py プロジェクト: ghsaheb/Bootcamp
 def test_getFeeds_withFromFeed1(self):
     feeds = Feed.get_feeds(self.feed2.id)
     self.assertEquals(len(feeds), 2)
     self.assertTrue(self.feed in feeds)
     self.assertTrue(self.feed2 in feeds)
コード例 #26
0
ファイル: test_models.py プロジェクト: Serji0/diploma
 def test_get_feeds(self):
     assert self.feed_two in Feed.get_feeds(self.feed_three.id)