Exemplo n.º 1
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)
Exemplo n.º 2
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)
Exemplo n.º 3
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)
Exemplo n.º 4
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)
Exemplo n.º 5
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)
Exemplo n.º 6
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)
Exemplo n.º 7
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
Exemplo n.º 8
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)
Exemplo n.º 9
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)
Exemplo n.º 10
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)
Exemplo n.º 11
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)
Exemplo n.º 12
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)
Exemplo n.º 13
0
 def get(self, request):
     top_list = get_top()
     return http.JsonResponse({'code': RETCODE.OK, 'top_list': top_list})