コード例 #1
0
ファイル: PostController.py プロジェクト: evanhuang8/Exchange
def page(request, page = 1):
	response = {
		'status':'FAIL',
		'error':'ACCESS_FORBIDDEN'
	}
	userID = request.session.get('id', False)
	user = None
	posts = []
	paging = []
	if userID:
		user = User.objects.get(id = userID)
		page = int(page)
		pageCount = PostManager.countPage(user.parent_community)
		prevPage = max(1, page - 1)
		nextPage = min(pageCount, page + 1)
		paging = PostManager.paging(page, user.parent_community)
		posts = PostManager.fetch(page, user.parent_community, serialized = True)
		if posts == None or len(posts) == 0:
			response = {
				'status':'FAIL',
				'error':'NO_RECORD'
			}
		else:
			response = {
				'status':'OK',
				'posts':posts,
				'page_count':pageCount,
				'paging':paging,
				'previous_page':prevPage,
				'next_page':nextPage
			}
	return HttpResponse(json.dumps(response))
コード例 #2
0
ファイル: PostController.py プロジェクト: evanhuang8/exchange
def page(request, page=1):
    response = {'status': 'FAIL', 'error': 'ACCESS_FORBIDDEN'}
    userID = request.session.get('id', False)
    user = None
    posts = []
    paging = []
    if userID:
        user = User.objects.get(id=userID)
        page = int(page)
        pageCount = PostManager.countPage(user.parent_community)
        prevPage = max(1, page - 1)
        nextPage = min(pageCount, page + 1)
        paging = PostManager.paging(page, user.parent_community)
        posts = PostManager.fetch(page, user.parent_community, serialized=True)
        if posts == None or len(posts) == 0:
            response = {'status': 'FAIL', 'error': 'NO_RECORD'}
        else:
            response = {
                'status': 'OK',
                'posts': posts,
                'page_count': pageCount,
                'paging': paging,
                'previous_page': prevPage,
                'next_page': nextPage
            }
    return HttpResponse(json.dumps(response))
コード例 #3
0
def index(request, page = 1):
	userID = request.session.get('id', False)
	user = None
	posts = []
	paging = []
	if userID:
		user = User.objects.get(id = userID)
		if user.profile.notification == '' or not user.parent_community:
			return redirect('exchange-registration')
		else:
			msgCount = PostManager.uncheckMessageCount(user)
		page = int(page)
		pageCount = PostManager.countPage(user.parent_community)
		prevPage = max(1, page - 1)
		nextPage = min(max(pageCount, 1), page + 1)
		posts = PostManager.fetch(page, user.parent_community)
		paging = PostManager.paging(page, user.parent_community)
		if posts == None:
			return redirect('exchange-home')
		return render(request, 'index.html', locals())
	else:
		return render(request, 'landing.html', locals())