예제 #1
0
파일: views.py 프로젝트: microwu/Stucampus
def article_list(request, category=None):
    category = get_object_or_404(Category, english_name=category)
    article_list = Article.objects.filter(category=category,
                                          publish=True,
                                          deleted=False).order_by('-pk')
    paginator = Paginator(article_list, 5)
    try:
        page = paginator.page(request.GET.get('page'))
    except InvalidPage:
        page = paginator.page(1)
    if not request.is_ajax():
        page = DuoShuo.appendNumToArticles(page)
        comments = DuoShuo.getRecentComment()
        visitors = DuoShuo.getListVisitors()
        categories = Category.objects.all().order_by("priority")
        return render(
            request, 'articles/article-list.html', {
                'page': page,
                'category': category,
                'comments': comments,
                'visitors': visitors,
                'categories': categories
            })
    else:
        newest_articles = DuoShuo.appendNumToArticles(page)
        return render(request, "ajax_article_list.html",
                      {'newest_articles': newest_articles})
예제 #2
0
파일: front.py 프로젝트: microwu/Stucampus
def index(request):
    if not request.is_ajax():
        # 深大焦点
        slides = Slide.objects.filter(
                        published=True,
                        deleted=False).order_by("-priority","-pk")[:5]  
        # 最新文章
        newest_articles = \
                Article.objects.filter(
                        publish=True,
                        deleted=False).order_by('-pk')[:10]
        paginator = Paginator(newest_articles, 5)
        try:
            newest_articles = paginator.page(request.GET.get('page'))
        except InvalidPage:
            newest_articles = paginator.page(1)
        newest_articles=DuoShuo.appendNumToArticles(newest_articles)
        
        comments = DuoShuo.getRecentComment()
        visitors = DuoShuo.getListVisitors()

        categories=Category.objects.all().order_by("priority")
          
        return render(request, "index.html",
                    {'slides': slides,
                    'newest_articles':newest_articles,
                    'comments':comments,
                    'visitors':visitors,
                    'categories':categories})
    else:
        article_list = Article.objects.filter(publish=True,deleted=False).order_by('-pk')
        paginator = Paginator(article_list, 5)
        try:
            newest_articles = paginator.page(request.GET.get('page'))
        except InvalidPage:
            newest_articles = paginator.page(1)
        newest_articles=DuoShuo.appendNumToArticles(newest_articles)
        
        return render(request, "ajax_article_list.html",{'newest_articles':newest_articles})
예제 #3
0
def article_list(request, category=None):
    category = get_object_or_404(Category, english_name=category)
    article_list = Article.objects.filter(category=category,
                                          publish=True,
                                          deleted=False).order_by('-pk')
    paginator = Paginator(article_list, 5)
    try:
        page = paginator.page(request.GET.get('page'))
    except InvalidPage:
        page = paginator.page(1)
    if not request.is_ajax():
        page = DuoShuo.appendNumToArticles(page)
        comments = DuoShuo.getRecentComment()
        visitors = DuoShuo.getListVisitors()
        categories=Category.objects.all().order_by("priority")
        return render(request, 'articles/article-list.html',
                {'page': page, 'category': category,
                 'comments':comments,
                 'visitors':visitors,
                 'categories':categories})
    else:
        newest_articles=DuoShuo.appendNumToArticles(page)
        return render(request, "ajax_article_list.html",{'newest_articles':newest_articles})