def cats(request): # 站点分类文件 return { 'A_CATS': ctx.cats('A'), 'a_cat': '文学创作', 'B_CATS': ctx.cats('B'), 'b_cat': '技术干货', }
def site_count(request): # 关于站点的统计信息 return {'SITE_CNT': { 'run': ctx.run_days(), # 运行天数 'origin': ctx.origin_art_cnt(), # 原创文章数 'copy': ctx.copy_art_cnt(), # 转载文章, 'visit': ctx.visit_cnt(), # 总访问数 'today_visit': ctx.today_visit_cnt(), # 今日访问 }}
def get(self, request, pk, *args, **kwargs): tag_id = pk tag = m.Tag.objects.filter(is_active=True, pk=tag_id).first() if not tag: raise Http404() try: page = int(self.request.GET.get('page', 1)) page_size = int(self.request.GET.get('page_size', settings.LIST_INFO['page_size'])) except: page = 1 page_size = settings.LIST_INFO['page_size'] num, start, end = self.get_index(tag, page, page_size) queryset = tag.tblogs.filter(is_active=True, cat__is_active=True).order_by('-add')[start:end] ctx = { 'tag': tag, 'list_desc': settings.LIST_INFO['tag'], 'art_list': queryset, 'page_size': page_size, 'page': page, 'total': num, 'prev': page - 1 if page > 1 else None, 'next': page + 1 if page < num else None, 'tags': ContextUtil.random_tags(), } return render(request, 'db/taglist.html', ctx)
def get(self, request, *args, **kwargs): key = self.request.GET.get('key', None) if not key: return render( request, "db/search.html", { 'key': "无关键词", 'list_desc': "输入一个关键词呗, 不然我怎么知道你想找啥", 'art_list': [], 'page_size': settings.LIST_INFO['page_size'], 'page': 1, 'total': 0, 'prev': None, 'next': None, 'tags': ContextUtil.random_tags(), }) try: page = int(self.request.GET.get('page', 1)) page_size = int( self.request.GET.get('page_size', settings.LIST_INFO['page_size'])) except: page = 1 page_size = settings.LIST_INFO['page_size'] cnt, num, start, end = self.get_index(key, page, page_size) queryset = m.Blog.objects.filter( Q(cat__cat__icontains=key) | Q(title__icontains=key) | Q(tags__tag__icontains=key)).filter( is_active=True, cat__is_active=True).distinct().order_by('-add')[start:end] ctx = { 'key': key, 'list_desc': "根据你的关键词【{}】搜索到{}篇文章".format(key, cnt), 'art_list': queryset, 'page_size': page_size, 'page': page, 'total': num, 'prev': page - 1 if page > 1 else None, 'next': page + 1 if page < num else None, 'tags': ContextUtil.random_tags(), } return render(request, "db/search.html", ctx)
def get(self, request, pk): # 获取文章详情 obj = self.get_obj(pk) if not obj: raise Http404() ctx = { 'art': obj, 'tags': ContextUtil.random_tags(), 'cnxh': self.get_cnxh(obj), 'others': self.get_others(obj), 'next': self.get_next(obj), 'prev': self.get_prev(obj), 'liked': self.get_art_like_status(pk), } # 更新阅读次数 obj.read += 1 obj.save(update_fields=('read', )) return render(request, 'db/detail.html', ctx)
def links(request): # 个人网站友链信息 return {"PERSON_LINKS": ctx.person_links()}
def recommend(request): # 推荐阅读 return {'RECOMMEND': ctx.recommend()}
def notice(request): # 网站公告 return {'NOTICE': ctx.notice()}
def most_read(request): # 点击排行 return {'MOST_READ': ctx.most_read()}