Ejemplo 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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
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
Ejemplo n.º 4
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
Ejemplo n.º 5
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
Ejemplo n.º 6
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
Ejemplo n.º 7
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)
Ejemplo n.º 8
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
     context['page_articles'], context['total_page'] = paginator_function(
         articles, page_num, Const.EXTREMUM.HISTORY_ARTICLE_LIST)
     context['page_num'] = page_num
     # 分类信息
     context['cat_list'] = ArticleCategory.get_cat_lst()
     # 相册分类
     context['photo_category'] = get_photo_category()
     return render(request, 'time.html', context=context)
Ejemplo n.º 9
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)
Ejemplo n.º 10
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)
Ejemplo n.º 11
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)
Ejemplo n.º 12
0
 def get(self, request):
     cat_list = ArticleCategory.get_cat_lst()
     return http.JsonResponse({'code': RETCODE.OK, 'cat_list': cat_list})
Ejemplo n.º 13
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