def get_object(self, queryset=None): try: article_meta = get_article_meta_by_article(self.kwargs['article_id']) article_meta.read_num += 1 article_meta.save() except: raise Http404() return get_article_by_id(self.kwargs['article_id'])
def detail_article_view(request, article_id): form_error = request.GET.get('form_error', '') article = get_article_by_id(article_id) if not article: raise Http404() meta_data = article.meta_data() meta_data.read_num += 1 meta_data.save() t = get_detail_article_template(article, form_error) return HttpResponse(t.get_html(request))
def create_comment_view(request): if request.method == 'POST': form = CommentForm(request.POST) if form.is_valid(): article_id = form.cleaned_data['article_id'] article = get_article_by_id(article_id) if not article: return JsonFailResponse({'msg': 'article_id不存在'}) form.save() return JsonSuccessResponse({})
def set_acticle_top_view(request, article_id): """ 设置置顶/取消置顶 """ try: article_obj = get_article_by_id(article_id) if article_obj.sorted_num: article_obj.sorted_num = 0 else: article_obj.sorted_num = 1 article_obj.save() except: raise ObjectDoesNotExist() return HttpResponseRedirect(request.headers["Referer"])
def set_article_top_view(request, article_id): """ 设置置顶/取消置顶 """ try: article_obj = get_article_by_id(article_id) if article_obj.sorted_num: article_obj.sorted_num = 0 else: article_obj.sorted_num = 1 article_obj.save() except: raise ObjectDoesNotExist() return HttpResponseRedirect(reverse('admin:app_article_changelist'))
def set_acticle_top(request, article_id): """ 设置置顶/取消置顶 """ try: print(article_id) article_obj = get_article_by_id(article_id) print(article_obj) if article_obj.sorted_num: article_obj.sorted_num = 0 else: article_obj.sorted_num = 1 article_obj.save() except: raise ObjectDoesNotExist() return HttpResponseRedirect("/admin/app/article/")
def detail_article_view(request, article_id): try: article_meta = get_article_meta_by_article(article_id) article_meta.read_num += 1 article_meta.save() except: return JsonFailResponse({'code': 404, 'msg': 'article_id不存在'}) article = get_article_by_id(article_id) result = { 'article': article_to_dict(article), 'article_meta': model_to_dict(article_meta), 'category': [model_to_dict(c) for c in article.category()], 'tags': [model_to_dict(t) for t in article.tags()], 'last_article': article.last_article(), 'next_article': article.next_article() } return JsonSuccessResponse(result)
def create_comment(request): if request.method == 'POST': form = CommentForm(request.POST) if form.is_valid(): article_id = form.cleaned_data['article_id'] article = get_article_by_id(article_id) if not article: msg = '错误id' return HttpResponseRedirect( reverse('app:detail_article', args=(article_id, )) + '?form_error=' + msg + '#comment') # article_meta.comment_num += 1 # article_meta.save() form.save() return HttpResponseRedirect( reverse('app:detail_article', args=(article_id, )) + '#comment')
def is_valid_comment(comment_form): to_id = comment_form.cleaned_data['to_id'] article_id = comment_form.cleaned_data['article_id'] root_id = comment_form.cleaned_data['root_id'] type = comment_form.cleaned_data['type'] article = get_article_by_id(article_id) if not article: return False, '错误id' if type == 202: to_comment = get_valid_comment_by_id_and_article(to_id, article_id) if not to_comment: return False, '错误to_id' if to_comment.root_id == -1: if root_id != to_id: return False, '错误to_id' else: if to_comment.root_id != root_id: return False, '错误root_id' return True, ''
def article(self): from app.db_manager.content_manager import get_article_by_id return get_article_by_id(self.article_id)