Exemplo n.º 1
0
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))
Exemplo n.º 2
0
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))
Exemplo n.º 3
0
def dashboard(request):
	userID = request.session.get('id', False)
	if userID:
		user = User.objects.get(id = userID)
		if user.profile.notification == '':
			return redirect('exchange-registration')
		bullets = PostManager.fetchBulletin(user)
		msgCount = PostManager.uncheckMessageCount(user)
	return render(request, 'dashboard.html', locals())
Exemplo n.º 4
0
def claim(request):
    response = {'status': 'FAIL', 'error': 'ACCESS_FORBIDDEN'}
    userID = request.session.get('id', False)
    if request.REQUEST and userID:
        urlHelper = UrlHelper()
        params = urlHelper.validate(request.REQUEST,
                                    {'id', 'phone', 'email', 'note'})
        if params == False:
            response = {'status': 'FAIL', 'error': 'BAD_REQUEST'}
        else:
            user = User.objects.get(id=userID)
            post = Post.objects.filter(id=params['id'],
                                       claimer=None,
                                       community=user.parent_community)
            if post.count() > 0 and post[0].owner.id != user.id:
                post = post[0]
                postType = PostManager.postType(post)
                message = None
                if postType == Post_money:
                    message = Message_money(to=post.owner,
                                            email='',
                                            text='',
                                            note=params['note'],
                                            about=post.post_money)
                else:
                    message = Message_other(to=post.owner,
                                            email='',
                                            text='',
                                            note=params['note'],
                                            about=post.post_other)
                contact = False
                if re.search(
                        r'^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name))$',
                        params['email']):
                    message.email = params['email']
                    contact = True
                if re.search(r'^[0-9]{10}$', params['phone']):
                    message.text = params['phone']
                    contact = True
                if contact:
                    post.claimer = user
                    post.claimed_time = datetime.now()
                    post.save()
                    message.save()
                    response = {'status': 'OK'}
                else:
                    response = {
                        'status': 'FAIL',
                        'error': 'INVALID_CONTACT_INFO'
                    }
            else:
                response = {'status': 'FAIL', 'error': 'INVALID_POST'}
    return HttpResponse(json.dumps(response))
Exemplo n.º 5
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())
Exemplo n.º 6
0
def search(request):
	userID = request.session.get('id', False)
	if userID:
		user = User.objects.get(id = userID)
		if user.profile.notification == '':
			return redirect('exchange-registration')
		else:
			msgCount = PostManager.uncheckMessageCount(user)
		if request.GET:
			urlHelper = UrlHelper()
			params = urlHelper.validate(request.GET, {'q'}, {'p'})
			if params and params['q'] != '':
				page = 0
				if params['p']:
					page = int(params['p'])
				query = params['q']
				results = SearchManager.offerResults(query, user)
				return render(request, 'search.html', locals())
	return redirect('exchange-home')
Exemplo n.º 7
0
def claim(request):
	response = {
		'status':'FAIL',
		'error':'ACCESS_FORBIDDEN'
	}
	userID = request.session.get('id', False)
	if request.REQUEST and userID:
		urlHelper = UrlHelper()
		params = urlHelper.validate(request.REQUEST, {'id', 'phone', 'email', 'note'})
		if params == False:
			response = {
				'status':'FAIL',
				'error':'BAD_REQUEST'
			}
		else:
			user = User.objects.get(id = userID)
			post = Post.objects.filter(id = params['id'], claimer = None, community = user.parent_community)
			if post.count() > 0 and post[0].owner.id != user.id:
				post = post[0]
				postType = PostManager.postType(post)
				message = None
				if postType == Post_money:
					message = Message_money(
						to = post.owner,
						email = '',
						text = '',
						note = params['note'],
						about = post.post_money
					)
				else:
					message = Message_other(
						to = post.owner,
						email = '',
						text = '',
						note = params['note'],
						about = post.post_other
					)
				contact = False
				if re.search(r'^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name))$', params['email']):
					message.email = params['email']
					contact = True
				if re.search(r'^[0-9]{10}$', params['phone']):
					message.text = params['phone']
					contact = True
				if contact:
					post.claimer = user
					post.claimed_time = datetime.now() 
					post.save()
					message.save()
					response = {
						'status':'OK'
					}
				else:
					response = {
						'status':'FAIL',
						'error':'INVALID_CONTACT_INFO'
					}
			else:
				response = {
					'status':'FAIL',
					'error':'INVALID_POST'
				}
	return HttpResponse(json.dumps(response))