def article_write(request): userInfo = request.session.get('uInfo', False) url = C.getProtocol(request) + request.get_host() if C.checkLoginAdmin(userInfo) == False: return HttpResponseRedirect('/') if request.method == 'POST': currTime = C.getCurrTime() createTime = cgi.escape(request.POST.get('create_date')) + ' ' + cgi.escape(request.POST.get('create_time')) articleInfo = Article.objects.create( look_count = 0, comment_count = 0, update_time = currTime, create_time = createTime, author = int(userInfo['user_id']), title = cgi.escape(request.POST.get('title')), content = cgi.escape(request.POST.get('content')), article_pic = cgi.escape(request.POST.get('article_pic')), created = datetime.datetime.strftime(datetime.datetime.now(timeZone), '%Y年%m月') ) categoryIdList = request.REQUEST.getlist('category') for item in categoryIdList: Relation.objects.create(aid=articleInfo.article_id, cid=item) categoryList = C.getCategoryList() attachmentList = Attachment.objects.all().order_by('-attrch_id') context = { 'url' : url, 'categoryList' : categoryList, 'attachmentList' : attachmentList } return render(request, manageThemeDir + 'article_write.html', context)
def article_edit(request): if C.checkLoginAdmin(request.session.get('uInfo', False)) == False: return HttpResponseRedirect('/signin/') else: context = {} url = request.get_host() userInfo = request.session.get('uInfo', False) aid = cgi.escape(request.GET.get('aid', 0)) if request.method == 'POST': updateArticle = Article.objects.get(article_id=aid) createTime = cgi.escape(request.POST.get('create_date')) + ' ' + cgi.escape(request.POST.get('create_time')) updateArticle.create_time = createTime updateArticle.update_time = C.getCurrTime() updateArticle.author = int(userInfo['user_id']) updateArticle.article_pic = request.POST.get('article_pic', '') updateArticle.title = cgi.escape(request.POST.get('title', '')) updateArticle.content = cgi.escape(request.POST.get('content', '')) updateArticle.save() Relation.objects.filter(aid=aid).delete() categoryIdList = cgi.escape(request.REQUEST.getlist('category')) for item in categoryIdList: Relation.objects.create(aid=aid, cid=item) return HttpResponse('修改文章成功') detail = [] if C.isset(aid): detail = Article.objects.get(article_id=aid) detail.create_date = str(detail.create_time)[0:10] detail.create_time = str(detail.create_time)[10:16] detail.author = User.objects.get(user_id=detail.author).username detail.content = detail.content.replace('\t', '').replace('\n', '').replace(' ', '') categoryList = C.getCategoryList() activeCategory = Relation.objects.filter(aid=aid).all() attachmentList = Attachment.objects.all().order_by('-attrch_id') context = { 'detail' : detail, 'categoryList' : categoryList, 'activeCategory' : activeCategory, 'attachmentList' : attachmentList } return render(request, manageThemeDir + 'article_edit.html', context)