Example #1
0
def add_category(request):
    """增加新的用户日志分类"""
    category_name = request.POST.get("category_name", "")
    try:
        new_category = ArticleCategory(
            author = request.user.person,
            name = category_name,
        )
        new_category.save()
        is_success = True
    except IntegrityError,e:
        print e
        is_success = False
Example #2
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)
Example #3
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)
Example #4
0
File: views.py Project: ltfred/web
    def get(self, request, article_id):

        try:
            article = ArticleDetail.get_article_obj(id=article_id)
            article.view_count += 1
            article.save()
        except:
            raise
        article.content = markdown.markdown(
            article.content.replace("\r\n", '  \n'),
            extensions=[
                'markdown.extensions.extra', 'markdown.extensions.codehilite',
                'markdown.extensions.toc'
            ])
        related_articles = ArticleDetail.objects.filter(
            category2=article.category2).exclude(
                id=article.id).order_by("-digg_count")[0:4]
        context = {
            "article": article,
            'categories': ArticleCategory.get_categories(),
            'related_articles': related_articles,
            'labels_and_count': ArticleLabel.get_labels(),
            'links': Link.objects.all()
        }
        return render(request, 'article_detail.html', context)
Example #5
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
Example #6
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
Example #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
Example #8
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
Example #9
0
File: views.py Project: ltfred/web
 def get(self, request, category_id):
     page_num = request.GET.get('page', 1)
     q = request.GET.get('q', '')
     articles = ArticleDetail.objects.filter(
         Q(category1_id=category_id) | Q(category2_id=category_id))
     if q:
         if q == 'time':
             articles = articles.order_by('-create_time')
         elif q == 'hot':
             articles = articles.order_by('-view_count')
     page_list, total_page = paginator_func(articles, page_num)
     category = ArticleCategory.objects.get(id=category_id)
     context = {
         'articles': page_list,
         'category': category,
         'categories': ArticleCategory.get_categories(),
         'sub_categories': ArticleCategory.get_sub_categories(),
         'total_page': total_page
     }
     return render(request, 'category_article.html', context=context)
Example #10
0
File: views.py Project: ltfred/web
    def get(self, request):

        page = request.GET.get('page', 1)
        articles = ArticleDetail.objects.all().values('title', 'create_time',
                                                      'id')
        page_list, total_page = paginator_func(articles, page)
        context = {
            'articles': page_list,
            'count': articles.count(),
            'categories': ArticleCategory.get_categories()
        }
        return render(request, 'time_line.html', context=context)
Example #11
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)
Example #12
0
File: views.py Project: ltfred/web
 def get(self, request, label_id):
     page_num = request.GET.get('page')
     page_num = page_num if page_num else 1
     label_obj = ArticleLabel.objects.get(id=label_id)
     label_articles = label_obj.labels.all()
     page_list, total_page = paginator_func(label_articles, page_num)
     context = {
         'label': label_obj,
         'categories': ArticleCategory.get_categories(),
         'label_articles': page_list,
         'total_page': total_page,
         'labels_and_count': ArticleLabel.get_labels()
     }
     return render(request, 'label_article.html', context)
Example #13
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)
Example #14
0
 def get_context_data(self, **kwargs):
     content = super().get_context_data(**kwargs)
     content["new_articles"] = ArticleDetail.objects.all()[0:12]
     content["carousel_article"] = Carousel.objects.filter(is_active=True)
     content["categories"] = ArticleCategory.get_categories()
     content["tech_articles"] = ArticleDetail.objects.filter(
         category1_id=4).order_by('-view_count')[0:5]
     content["life_articles"] = ArticleDetail.objects.filter(
         category2_id=7).order_by('-view_count')[0:5]
     content["tech_new_articles"] = ArticleDetail.objects.filter(
         category1_id=4).order_by('-create_time')[0:8]
     content["shi_count"] = ArticleDetail.objects.filter(
         category1_id=2).count()
     content["tech_count"] = ArticleDetail.objects.filter(
         category1_id=4).count()
     content["tool_count"] = ArticleDetail.objects.filter(
         category1_id=5).count()
     content["ci_count"] = ArticleDetail.objects.filter(
         category2_id=8).count()
     return content
Example #15
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)
Example #16
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)
Example #17
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)
Example #18
0
File: views.py Project: ltfred/web
 def extra_context(self):
     content = super(MySearchView, self).extra_context()
     content['categories'] = ArticleCategory.get_categories()
     content['search_count'] = self.results.count()
     return content
Example #19
0
 def get(self, request):
     cat_list = ArticleCategory.get_cat_lst()
     return http.JsonResponse({'code': RETCODE.OK, 'cat_list': cat_list})
Example #20
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