Exemple #1
0
def home(request):
	
	try:
		loggeduser = User.objects.get(id=request.session['USERZ'])
	except (KeyError, User.DoesNotExist):
		loggeduser = 0
	form = SearchForm(request.POST)
	queryTag = form.save(commit=False)
	query = form.cleaned_data["tag"]
	if query != '':
		all_posts = Posts.objects.all()
		return render(request, 'marketplace/search.html', {'all_posts':all_posts, 'query':query,'loggeduser':loggeduser, 'form':form})
	
	filter_number = 10
	if request.POST:
		post_num = request.POST.get("numberz",False)
		filter_number = int(post_num)
		print(filter_number)
		print(type(filter_number))
		
	if request.POST.get("more"):
		filter_number = filter_number + 5
		
	all_posts = Posts.objects.all().order_by('?')[:filter_number]
	
	
	context = {
		'all_posts': all_posts,
		'loggeduser':loggeduser,
		'form':form,	
	}
	return render(request, 'marketplace/home.html', context)
Exemple #2
0
def detail2(request, user_id,offer_id):
	all_posts = Posts.objects.all()
	all_offers = Offer.objects.all()
	try:
		user = User.objects.get(pk=user_id)
	except (KeyError, User.DoesNotExist):
		raise Http404("User does not exist")
		
	offer = Offer.objects.get(pk=offer_id)
	
	try:
		loggeduser = User.objects.get(id=request.session['USERZ'])
	except (KeyError, User.DoesNotExist):
		loggeduser = None
	form = SearchForm(request.POST)
	queryTag = form.save(commit=False)
	query = form.cleaned_data["tag"]
	if query != '':
		return render(request, 'marketplace/search.html', {'all_posts':all_posts, 'query':query,'loggeduser':loggeduser, 'form':form})
	
	context = {
		'user': user,
		'loggeduser':loggeduser,
		'form':form,
		'all_offers':all_offers,
		'all_posts':all_posts,
		'offer':offer,
	}	
	return render(request, 'marketplace/userprofile2.html', context)
Exemple #3
0
def logoutNow(request):
	del request.session['USERZ']
	all_posts = Posts.objects.all()
	loggeduser = None
	form = SearchForm(request.POST)
	queryTag = form.save(commit=False)
	query = form.cleaned_data["tag"]
	if query != '':
		return render(request, 'marketplace/search.html', {'all_posts':all_posts, 'query':query,'loggeduser':loggeduser, 'form':form})
	
	render(request, 'marketplace/logout.html')
	return render(request, 'marketplace/home.html',{'all_posts':all_posts,'form':form})
Exemple #4
0
def search(request):
	form = SearchForm(request.POST)
	try:
		loggeduser = User.objects.get(id=request.session['USERZ'])
	except (KeyError, User.DoesNotExist):
		loggeduser = None
	all_posts = Posts.objects.all()
	if form.is_valid():
		queryTag = form.save(commit=False)
		query = form.cleaned_data["tag"]
		return render(request, 'marketplace/search.html', {'all_posts':all_posts, 'query':query,'loggeduser':loggeduser, 'form':form})
				
	
	return render(request, 'marketplace/search.html', {'loggeduser':loggeduser,'form':form})
Exemple #5
0
def search_results(request):
	form = SearchForm(request.GET)
	if form.is_valid():
		query = form.cleaned_data['q']
	else:
		return render(request, 'marketplace/index.html', {'form':form})
#	query = ''
	results = []
	try:
		query = request.GET['q']
		if len(query) > 0:
			results = Item.objects.filter(Q(title__contains=query) | Q(description__contains=query))
	except (NameError, KeyError):
		return render(request, 'marketplace/search_results.html', {'query':query, 'resuts':results, 'error_message': "No results found",})
	else:
		return render(request, 'marketplace/search_results.html', {'query':query, 'results':results})
Exemple #6
0
def itemdetails(request,post_id):
	all_posts = Posts.objects.all()
	all_offers = Offer.objects.all()
	posts = Posts.objects.get(pk=post_id)
	try:
		user = User.objects.get(id=request.session['USERZ'])
	except (KeyError, User.DoesNotExist):
		user = None
	
	form = SearchForm(request.POST)
	queryTag = form.save(commit=False)
	query = form.cleaned_data["tag"]
	
	if query != '':
		return render(request, 'marketplace/search.html', {'all_posts':all_posts, 'query':query,'loggeduser':user, 'form':form})
		
	return render(request,'marketplace/viewitem.html',{'posts':posts, 'loggeduser':user, 'form':form,'all_offers':all_offers})
Exemple #7
0
def addpost(request):
	form = PostForm(request.POST or None, request.FILES or None)
	user_id = request.session['USERZ']
	user = User.objects.get(pk=user_id)
	all_posts = Posts.objects.all()
	if form.is_valid():
		post = form.save(commit=False)
		post.user = user
		post.save()
		return render(request, 'marketplace/home.html', {'all_posts': all_posts,'loggeduser':user})
	
	form2 = SearchForm(request.POST)
	queryTag = form2.save(commit=False)
	query = form2.cleaned_data["tag"]
	if query != '':
		return render(request, 'marketplace/search.html', {'all_posts':all_posts, 'query':query,'loggeduser':user, 'form':form2})
	return render(request, 'marketplace/addpost.html', {'form':form, 'loggeduser':user,'form2':form2})	
Exemple #8
0
def home_mongo():
    form = SearchForm()
    posts = m_db.posts.find({}).sort('date_posted', pymongo.DESCENDING)
    posts = list(posts)
    for post in posts:
        post['id'] = post.pop('_id')
        post['category'] = [{'name': cat} for cat in post['categories']]
        post['author'] = m_db.users.find_one({'_id': post['user_id']})
    return render_template('home_mongo.html', posts=posts, form=form)
Exemple #9
0
def filtersTag(request,post_id):
	form = SearchForm(request.POST)
	all_posts = Posts.objects.all()
	choice = Posts.objects.get(pk=post_id)
	query = choice.tag

	try:
		loggeduser = User.objects.get(id=request.session['USERZ'])
	except (KeyError, User.DoesNotExist):
		loggeduser = None
		
	return render(request, 'marketplace/search.html', {'query':query, 'all_posts':all_posts,'loggeduser':loggeduser,'form':form})
Exemple #10
0
def loginNow(request):
	form = LoginForm(request.POST)
	all_users = User.objects.all()
	all_posts = Posts.objects.all()
	if form.is_valid():
		LPass =	form.cleaned_data["password"]
		LUser = form.cleaned_data["username"]
		for i in all_users:
			if i.username == LUser:
				if i.password == LPass:
					print ('LOGGED IN')
					request.session['USERZ'] = i.id
					form2 = SearchForm(request.POST)
					queryTag = form2.save(commit=False)
					query = form2.cleaned_data["tag"]
					if query != '':
						return render(request, 'marketplace/search.html', {'all_posts':all_posts, 'query':query,'loggeduser':loggeduser, 'form':form2})
					return render(request, 'marketplace/home.html', {'loggeduser': i, 'all_posts':all_posts, 'form':form2})
				else:
					print ('WRONG PASS')
			else:
				print ('Account not found')
				
	return render(request, 'marketplace/login.html', {'form':form})
Exemple #11
0
def decline(request,userid,offer_id):
	form = AcceptForm(request.POST)
	form2 = SearchForm(request.POST)
	offerz = Offer.objects.get(pk=offer_id)
	try:
		loggeduser = User.objects.get(id=request.session['USERZ'])
	except (KeyError, User.DoesNotExist):
		loggeduser = None
	
	all_posts = Posts.objects.all()
	
	if request.method == 'POST':
		if form.is_valid():
			reason = form.save(commit=False)
			reasonQ = form.cleaned_data["reason"]
			offerz.reason = reasonQ
			offerz.OfferStat = 'Decline'
			offerz.save()
			return render(request, 'marketplace/home.html',{'loggeduser':loggeduser,'form':form2,'all_posts':all_posts})
				
	return render(request, 'marketplace/accept.html', {'loggeduser':loggeduser,'form':form})
Exemple #12
0
def results():
    form = SearchForm()

    content = request.args.get('content')
    cat = request.args.get('category')
    loc = request.args.get('location')

    if cat is None:
        cat = 'None'
    if loc is None:
        loc = 'None'

    form.content.data = content
    form.category.data = Category.query.filter((
        Category.id == cat) if 'None' not in cat else sql.false()).first()
    form.location.data = Location.query.filter((
        Location.postal_code == loc
    ) if 'None' not in loc else sql.false()).first()

    page = request.args.get('page', 1, type=int)

    q = db.session.query(Post).filter(
        or_(
            func.lower(Post.content).contains(func.lower(content)),
            func.lower(Post.title).contains(func.lower(content)))).filter((
                Post.location_id == loc) if 'None' not in loc else sql.true(
                )).join(cat_association_table).filter((
                    cat_association_table.c.category_id == cat
                ) if 'None' not in cat else sql.true()).distinct().order_by(
                    Post.date_posted.desc()).paginate(page=page, per_page=5)
    return render_template('search_results.html',
                           posts=q,
                           form=form,
                           content=content,
                           location=loc,
                           category=cat,
                           page=page)
Exemple #13
0
def itemdetails2(request,post_id,offer_id):
	all_posts = Posts.objects.all()
	all_offers = Offer.objects.all()
	posts = Posts.objects.get(pk=post_id)
	offer = Offer.objects.get(pk=offer_id)
	off_type = offer.OfferType
	checker = 0
	
	try:
		user = User.objects.get(id=request.session['USERZ'])
	except (KeyError, User.DoesNotExist):
		user = None
	
	form = SearchForm(request.POST)
	queryTag = form.save(commit=False)
	query = form.cleaned_data["tag"]
	
	if request.POST.get("Update"):
		checker = 1
		
		if off_type == 'Buy':
			form = OfferBuyForm(request.POST or None, request.FILES or None)
		elif off_type == 'Swap':
			form = OfferSwapForm(request.POST or None, request.FILES or None)
			form.fields['offer_post'].queryset = Posts.objects.filter(user = user)
		
		if form.is_valid():
			offer = form.save(commit=False)
			offer.save();
			return render(request,'marketplace/viewitem2.html',{'all_posts':all_posts,'posts':posts, 'loggeduser':user, 'form':form,'all_offers':all_offers,'offer':offer})
	
	if request.POST.get("Cancel"):
		offer.delete()	
		return render(request,'marketplace/home.html',{'all_posts':all_posts, 'loggeduser':user, 'form':form,'all_offers':all_offers})
	
	if query != '':
		return render(request, 'marketplace/search.html', {'all_posts':all_posts, 'query':query,'loggeduser':user, 'form':form})
		
	return render(request,'marketplace/viewitem2.html',{'all_posts':all_posts,'posts':posts, 'loggeduser':user, 'form':form,'all_offers':all_offers,'offer':offer})
Exemple #14
0
def home():
    form = SearchForm()
    page = request.args.get('page', 1, type=int)
    posts = Post.query.order_by(Post.date_posted.desc()).paginate(page=page,
                                                                  per_page=5)
    return render_template('home.html', posts=posts, form=form)