Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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})
Exemplo n.º 4
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})
Exemplo n.º 5
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})
Exemplo n.º 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})
Exemplo n.º 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})	
Exemplo n.º 8
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})