Beispiel #1
0
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)
Beispiel #2
0
def category(request):
    if C.checkLoginAdmin(request.session.get('uInfo', False)) == False:
        return HttpResponseRedirect('/signin/')
    else:
		context = {
			'categoryList' : C.getCategoryList('<i class="uk-icon-minus"></i>')
		}

		return render(request, manageThemeDir + 'category.html', context)
Beispiel #3
0
def index(request):
	
	url = request.get_host()
	cid = request.GET.get('cid')
	
	if C.isset(cid) == 0:
		cid = 0

	navList = C.getNavList()
	
	if request.method == 'POST':
		articleList = Article.objects.filter(title__icontains=cgi.escape(request.POST.get('word'))).order_by('-article_id')
	
	elif cid == 0:
		articleList = Article.objects.all().order_by('-article_id')
	
	else:
		sql = 'SELECT * FROM "' + Meta.db_table + '_article" AS article LEFT JOIN "' + Meta.db_table
		sql += '_relation" AS relation ON article.article_id=relation.aid WHERE relation.cid=' + cgi.escape(cid)
		#sql += " AND article.title LIKE '%%" + request.POST.get('word') + "%%'"
		sql += ' ORDER BY article_id DESC'
		articleList = Article.objects.raw(sql)
		articleList = list(articleList)
	
	paginator  = Paginator(articleList, 5)
	page       = int(request.GET.get('page', 1))
	
	try:
		pagebar = paginator.page(page)

	except PageNotAnInteger:
		pagebar = paginator.page(1)

	except EmptyPage:
		pagebar = paginator.page(paginator.num_pages)

	categoryList  = C.getCategoryList()
	userInfo      = request.session.get('uInfo', '')

	contentDateList = Article.objects.order_by('created').values('created').distinct()

	context = {
		'url'              : url,
		'pagebar'          : pagebar,
		'navList'          : navList,
		'userinfo'         : userInfo,
		'cid'              : int(cid),
		'articleList'      : articleList,
        'categoryList'     : categoryList,
		'webInfo'          : C.getWebInfo(),
		'contentDateList'  : contentDateList,
		'themeHeader'      : C.getThemePath() + '/Public/header.html',
		'themeFooter'      : C.getThemePath() + '/Public/footer.html'
	}

	return render(request, C.getThemePath() + 'index.html', context)
Beispiel #4
0
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)
Beispiel #5
0
def category_add(request):
	context = {}
	
	if request.method == 'POST':

		chosenPid  = int(request.POST.get('pid', 0))
		pidInfo    = Category.objects.get(category_id=chosenPid)
		currPath   = str(pidInfo.path) + '-' + str(pidInfo.category_id)
		
		Category.objects.create(
			path  = currPath,
			pid   = chosenPid,
			name  = cgi.escape(request.POST.get('name', '')),
		)

		return HttpResponse('success')
	
	context = {
		'categoryList' : C.getCategoryList()
	}

	return render(request, manageThemeDir + 'category_add.html', context)
Beispiel #6
0
def category_add(request):
    if C.checkLoginAdmin(request.session.get('uInfo', False)) == False:
        return HttpResponseRedirect('/signin/')
	else:
		context = {}
		if request.method == 'POST':

			chosenPid  = int(request.POST.get('pid', 0))
			pidInfo    = Category.objects.get(category_id=chosenPid)
			currPath   = str(pidInfo.path) + '-' + str(pidInfo.category_id)
			
			Category.objects.create(
				path  = currPath,
				pid   = chosenPid,
				name  = cgi.escape(request.POST.get('name', '')),
			)

			return HttpResponse('success')
		
		context = {
			'categoryList' : C.getCategoryList()
		}

		return render(request, manageThemeDir + 'category_add.html', context)
Beispiel #7
0
def category(request):
	context = {
		'categoryList' : C.getCategoryList('<i class="uk-icon-minus"></i>')
	}

	return render(request, manageThemeDir + 'category.html', context)