Пример #1
0
    def get(self, request, category_id, page_num):
        try:
            # 查出该类别
            category = ArticleCategory.objects.get(id=category_id)
            # 获取文章及数量
            articles, category_article_count = self.get_articles(category)
        except Exception as e:
            logger.error('CategoryAllArticleView:get:' + str(e))
            # return http.HttpResponse('数据库错误')
            raise Http404
        page_query_set, total_page = paginator_function(
            articles, page_num, constants.ARTICLE_LIST_LIMIT)
        article_labels = []
        for article in page_query_set:
            # 该文章的标签
            labels = article.labels.all()
            article_labels.append({'article': article, 'labels': labels})

        data_dict = {
            'category_id': category.id,
            'articles': article_labels,
            'category': category,
            'article_count': category_article_count,
            'total_page': total_page,
            'page_num': page_num,
            'cat_list': get_cat_lst(),
            'photo_category': get_photo_category(),
            'recommend_list': get_recommend(),
            'top_list': get_top(),
            'labels': get_labels(),
        }

        return render(request, 'list.html', context=data_dict)
Пример #2
0
    def get(self, request, article_id):
        context = {}
        try:
            # 获取本条数据
            article = Article.objects.get(id=article_id)
        except Exception as e:
            logger.error('ArticleDetailView:get:' + str(e))
            raise Http404
        # 获取上一条数据和下一条数据
        context['next_article'] = self.get_next_article(article)
        context['pre_article'] = self.get_pre_article(article)
        # 相关数据10条
        context['articles'] = self.get_connected_article(article)
        # 阅读次数+1
        article.read_count += 1
        article.save()
        context['article'] = article
        # 分类信息
        context['cat_list'] = get_cat_lst()
        # 相册分类
        context['photo_category'] = get_photo_category()
        context['recommend_list'] = get_recommend()
        context['top_list'] = get_top()
        context['labels'] = get_labels()

        return render(request, 'info.html', context=context)
Пример #3
0
    def get(self, request, label_id, page_num):

        try:
            label = Label.objects.get(id=label_id)
        except Exception as e:
            logger.error('LabelArticlesView:get:' + str(e))
            # return http.JsonResponse('标签错误')
            raise Http404
        # 查出该标签下所有文章
        articles, article_count = self.get_label_articles(label)
        page_query_set, total_page = paginator_function(
            articles, page_num, constants.ARTICLE_LIST_LIMIT)
        article_labels = []
        for article in page_query_set:
            # 该文章的标签
            labels = article.labels.all()
            article_labels.append({'article': article, 'labels': labels})

        context = {
            'label': label,
            'articles': article_labels,
            'article_count': article_count,
            'total_page': total_page,
            'page_num': page_num,
            'cat_list': get_cat_lst(),
            'photo_category': get_photo_category(),
            'recommend_list': get_recommend(),
            'top_list': get_top(),
            'labels': get_labels(),
        }

        return render(request, 'labelList.html', context=context)
Пример #4
0
    def get(self, request, category_id, page_num):
        photo_category = PhotoCategory.objects.get(id=category_id)
        if photo_category.is_secret is True and request.user.is_anonymous:
            url = request.get_full_path()
            res = render(request, 'login.html')
            res.set_cookie('next', url)
            return res
        try:
            photo_groups = PhotoGroup.objects.filter(
                category=photo_category).order_by('-create_time')
        except Exception as e:
            logger.error(e)
            raise
        page_photo_groups, total_page = paginator_function(
            photo_groups, page_num, Const.EXTREMUM.PHOTO_LIST)

        context = {
            'category_id': category_id,
            'photo_groups': page_photo_groups,
            'total_page': total_page,
            'page_num': page_num,
            'cat_list': ArticleCategory.get_cat_lst(),
            'photo_group_count': photo_groups.count(),
            'photo_category': get_photo_category()
        }

        return render(request, 'categoryPhoto.html', context=context)
Пример #5
0
    def get(self, request):
        # 24小时内PV记录
        conn = get_redis_connection('default')
        if conn.setnx('24_hours_pv', 0):
            conn.expire('24_hours_pv', constants.PV_EXPIRE)
        conn.incr('24_hours_pv')
        context = dict()
        # 最新博文
        context['articles'] = self.get_new_articles()
        # 分类信息
        context['cat_list'] = self.get_cat_lst()
        # 静态随机图
        context['static_articles'] = self.get_static_articles()
        # 轮播图
        context['carousel_articles'] = self.get_carousel_articles()
        # 精彩专题数据
        context['like_articles'] = self.get_like_articles()[0:6]
        # 个人信息
        context['profile'] = self.get_profile()
        # 相册分类
        context['photo_category'] = get_photo_category()
        # 公告
        context['notice_list'] = get_notice()
        context['recommend_list'] = get_recommend()
        context['top_list'] = get_top()
        context['labels'] = get_labels()
        context['count'], context['pv'], context['days'] = get_site_info()

        return render(request, 'index.html', context=context)
Пример #6
0
    def get(self, request, notice_id):
        try:
            notice = Notice.objects.get(id=notice_id)
            next_notice = Notice.objects.filter(id__gt=notice.id).first()
            pre_notice = Notice.objects.filter(
                id__lt=notice.id).order_by('-id').first()
            notices = Notice.objects.exclude(id=notice.id)[0:9]
        except Exception as e:
            logger.error(e)
            raise
        # 每访问一次此页面阅读数+1
        notice.read_count += 1
        notice.save()

        context = {
            'notice': notice,
            'next_notice': next_notice,
            'pre_notice': pre_notice,
            'notices': notices,
            'cat_list': ArticleCategory.get_cat_lst(),
            'photo_category': get_photo_category(),
            'recommend_list': get_recommend(),
            'top_list': get_top(),
            'labels': get_labels(),
        }
        return render(request, 'noticeDetail.html', context=context)
Пример #7
0
    def get(self, request, notice_id):

        try:
            # 获取本条数据
            notice = Notice.objects.get(id=notice_id)
            # 获取上一条数据和下一条数据
            next_notice = Notice.objects.filter(id__gt=notice.id).first()
            pre_notice = Notice.objects.filter(
                id__lt=notice.id).order_by('-id').first()
            # 相关数据10条
            notices = Notice.objects.exclude(id=notice.id)[0:9]
        except Exception as e:
            logger.error(e)
            return http.JsonResponse({
                'code': RETCODE.DBERR,
                'errmsg': '数据库错误'
            })

        # 每访问一次此页面阅读数+1
        notice.read_count += 1
        notice.save()

        context = {
            'notice': notice,
            'next_notice': next_notice,
            'pre_notice': pre_notice,
            'notices': notices,
            'cat_list': get_cat_lst(),
            'photo_category': get_photo_category(),
            'recommend_list': get_recommend(),
            'top_list': get_top(),
            'labels': get_labels(),
        }

        return render(request, 'noticeDetail.html', context=context)
Пример #8
0
 def extra_context(self):
     content = super(ArticleSearchView, self).extra_context()
     content['cat_list'] = ArticleCategory.get_cat_lst()
     content['photo_category'] = get_photo_category()
     content['total_count'] = self.results.count()
     content["page_num"] = int(self.request.GET.get('page', 1))
     content["total_page"] = self.get_total_page()
     return content
Пример #9
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     context['recommend_links'] = Link.objects.filter(is_recommend=True)
     context['links'] = Link.objects.filter(is_recommend=False)
     context['cat_list'] = ArticleCategory.get_cat_lst()
     context['photo_category'] = get_photo_category()
     soups = Soup.objects.all()
     context['soup'] = random.choice(soups).content if soups else ''
     return context
Пример #10
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     user = User.objects.all()[0]
     context['bio'] = user.bio
     context['dubai'] = user.soliloquy
     context['name'] = user.webname
     context['avatar'] = user.avatar_url
     context['cat_list'] = ArticleCategory.get_cat_lst()
     context['photo_category'] = get_photo_category()
     return context
Пример #11
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     notices = Notice.objects.all()
     context['notices'] = notices
     context['cat_list'] = ArticleCategory.get_cat_lst()
     context['photo_category'] = get_photo_category()
     context['recommend_list'] = get_recommend()
     context['top_list'] = get_top()
     context['labels'] = get_labels()
     return context
Пример #12
0
 def get(self, request, article_id):
     article = get_object_or_404(Article, id=article_id)
     increase_view_count(request, article)
     context = get_context_data(next_article=article.get_next_article(),
                                pre_article=article.get_pre_article(),
                                articles=article.get_connected_article(),
                                article=article,
                                cat_list=ArticleCategory.get_cat_lst(),
                                photo_category=get_photo_category(),
                                recommend_list=get_recommend(),
                                top_list=get_top(),
                                labels=get_labels())
     return render(request, 'info.html', context=context)
Пример #13
0
    def get(self, request):

        try:
            user = User.objects.all()[0]
        except Exception as e:
            logger.error(e)
            # return http.HttpResponse('数据库错误')
            raise Http404

        context = {'bio': user.bio, 'dubai': user.soliloquy, 'name': user.webname,
                   'avatar': user.avatar_url, 'cat_list': get_cat_lst(),
                   'photo_category': get_photo_category()}

        return render(request, 'about.html', context=context)
Пример #14
0
 def get(self, request):
     context = dict()
     try:
         notices = Notice.objects.all()
     except Exception as e:
         logger.error(e)
         # return http.HttpResponse('服务器出错了')
         raise Http404
     context['notices'] = notices
     context['cat_list'] = get_cat_lst()
     context['photo_category'] = get_photo_category()
     context['recommend_list'] = get_recommend()
     context['top_list'] = get_top()
     context['labels'] = get_labels()
     return render(request, 'noticeList.html', context=context)
Пример #15
0
 def get(self, request, page_num):
     context = {}
     try:
         articles = Article.objects.order_by('-create_time').all().only(
             'id', 'title')
         context['all_counts'] = articles.count()
     except Exception as e:
         logger.error('AllArticleView:get:' + str(e))
         raise Http404
     context['page_articles'], context['total_page'] = paginator_function(
         articles, page_num, constants.HISTORY_ARTICLE_LIST_LIMIT)
     context['page_num'] = page_num
     # 分类信息
     context['cat_list'] = get_cat_lst()
     # 相册分类
     context['photo_category'] = get_photo_category()
     return render(request, 'time.html', context=context)
Пример #16
0
    def get(self, request):
        context = dict()
        try:
            context['recommend_links'] = Link.objects.filter(is_recommend=True)
            context['links'] = Link.objects.filter(is_recommend=False)
            # 分类信息
            context['cat_list'] = get_cat_lst()
            # 相册分类
            context['photo_category'] = get_photo_category()
            # 随机一句心灵鸡汤
            soups = Soup.objects.all()
            context['soup'] = random.choice(soups).content if soups else ''
        except Exception as e:
            logger.error('LinkView:get:' + str(e))
            raise Http404

        return render(request, 'link.html', context=context)
Пример #17
0
 def get(self, request):
     # 24小时内PV记录
     conn = get_redis_connection('default')
     if conn.setnx('24_hours_pv', 0):
         conn.expire('24_hours_pv', Const.EXTREMUM.PV_EXPIRE)
     conn.incr('24_hours_pv')
     context = dict()
     context['articles'] = Article.get_new_articles()
     context['cat_list'] = ArticleCategory.get_cat_lst()
     context['static_articles'] = Article().get_static_articles()
     context['carousel_articles'] = Carousel.get_carousel_articles()
     context['like_articles'] = Article.get_like_articles()[0:6]
     context['profile'] = User.get_profile()
     context['photo_category'] = get_photo_category()
     context['notice_list'] = get_notice()
     context['recommend_list'] = get_recommend()
     context['top_list'] = get_top()
     context['labels'] = get_labels()
     context['count'], context['pv'], context['days'] = get_site_info()
     return render(request, 'index.html', context=context)
Пример #18
0
    def get(self, request):
        context = {}
        photo_id = request.GET.get('photo_id')
        photo = Photo.objects.get(id=photo_id)
        try:
            size = get_image_size(photo.url)
        except:
            size = ''
        user = User.objects.get(is_staff=True)

        context['recommend_list'] = get_recommend()
        context['top_list'] = get_top()
        context['labels'] = get_labels()
        context['photo'] = photo
        context['size'] = size
        context['webname'] = user.webname
        context['avatar'] = user.avatar_url
        context['cat_list'] = get_cat_lst()
        context['photo_category'] = get_photo_category()

        return render(request, 'photoDetail.html', context=context)
Пример #19
0
    def get(self, request, page_num):

        try:
            photo_query_set = Photo.objects.all().order_by('-create_time')
        except Exception as e:
            logger.error(e)
            # return http.HttpResponse('获取照片页失败')
            raise Http404

        page_photos, total_page = paginator_function(
            photo_query_set, page_num, constants.PHOTO_LIST_LIMIT)

        context = {
            'photos': page_photos,
            'total_page': total_page,
            'page_num': page_num,
            'cat_list': get_cat_lst(),
            'photo_category': get_photo_category()
        }

        return render(request, 'photo.html', context=context)
Пример #20
0
    def get(self, request, page_num):
        try:
            if request.user.is_anonymous:
                photo_groups = PhotoGroup.objects.filter(
                    category__is_secret=False).order_by('-create_time')
            else:
                photo_groups = PhotoGroup.objects.all().order_by(
                    '-create_time')
        except Exception as e:
            logger.error(e)
            raise
        page_photo_groups, total_page = paginator_function(
            photo_groups, page_num, Const.EXTREMUM.PHOTO_LIST)
        context = {
            'photo_groups': page_photo_groups,
            'total_page': total_page,
            'page_num': page_num,
            'cat_list': ArticleCategory.get_cat_lst(),
            'photo_group_count': photo_groups.count(),
            'photo_category': get_photo_category()
        }

        return render(request, 'photo.html', context=context)
Пример #21
0
    def get(self, request, category_id, page_num):
        category = get_object_or_404(ArticleCategory, id=category_id)
        articles, category_article_count = category.get_articles()
        page_query_set, total_page = paginator_function(
            articles, page_num, Const.EXTREMUM.ARTICLE_LIST)
        article_labels = []
        for article in page_query_set:
            labels = article.labels.all()
            article_labels.append({'article': article, 'labels': labels})

        data_dict = {
            'category_id': category.id,
            'articles': article_labels,
            'category': category,
            'article_count': category_article_count,
            'total_page': total_page,
            'page_num': page_num,
            'cat_list': ArticleCategory.get_cat_lst(),
            'photo_category': get_photo_category(),
            'recommend_list': get_recommend(),
            'top_list': get_top(),
            'labels': get_labels(),
        }
        return render(request, 'list.html', context=data_dict)
Пример #22
0
 def get(self, request):
     context = dict()
     context['cat_list'] = get_cat_lst()
     context['photo_category'] = get_photo_category()
     return render(request, 'player.html', context=context)
Пример #23
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     context['cat_list'] = ArticleCategory.get_cat_lst()
     context['photo_category'] = get_photo_category()
     return context
Пример #24
0
 def get(self, request):
     photo_categories = get_photo_category()
     return http.JsonResponse({
         'code': RETCODE.OK,
         'photo_categories': photo_categories
     })