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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
def get(self, request): cat_list = get_cat_lst() return http.JsonResponse({'code': RETCODE.OK, 'cat_list': cat_list})
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)