Esempio n. 1
0
def seal(request, item_id, curr_user):
	"""
	When buyer seals the deal
	status = 0 -> 1
	"""
	try:
		item = items.objects.get(id=item_id, is_expired=False, is_sold=False)
	except items.DoesNotExist:
		return render(request, 'error.html', {'error': 'Item Not Found'})

	if request.method == 'POST':
		form = DealForm(request.POST)
		if form.is_valid() and form.cleaned_data.get('deal', False):
			# If sealed by buyer
			if item.user != curr_user.user_obj:
				try:
					comm = Comm.objects.get(buyer=curr_user.user_obj, item=item)
				except Comm.DoesNotExist:
					comm = Comm(buyer=curr_user.user_obj, item=item)
					comm.save()
				if comm.status == 0:
					comm.status = 1
					comm.save()
				else:
					return render(request, 'error.html', {'error': 'You can\'t seal the deal now!'})
				return HttpResponseRedirect(item.get_comm_url())
			else:
				# Current user is the seller
				return render(request, 'error.html', {'error': 'You can\'t purchase your own item!!'})
	return HttpResponseRedirect(item.get_comm_url())
Esempio n. 2
0
def seller_seal(request, item_id, buyer_nick, curr_user):
	try:
		item = items.objects.get(id=item_id, is_expired=False, is_sold=False)
	except items.DoesNotExist:
		return render(request, 'error.html', {'error': 'Item Not Found'})

	try:
		tar_user = user_profile.objects.get(nick=buyer_nick)
	except user_profile.DoesNotExist:
		return render(request, 'error.html', {'error': 'User Not Found'})

	if request.method == 'POST':
		form = DealForm(request.POST)
		if form.is_valid() and form.cleaned_data.get('deal', False):
			# If sealed by buyer
			if item.user != curr_user.user_obj:
				return render(request, 'error.html', {'error': 'Not your item!'})
			else:
				# Current user is the seller
				try:
					comm = Comm.objects.get(buyer=tar_user, item=item)
				except Comm.DoesNotExist:
					return render(request, 'error.html', {'error': 'Invalid Action!!'})
				if comm.status == 1:
					item.is_sold = True
					item.buyer = tar_user
					item.save()
					comm.status = 2
					comm.save()
				else:
					return render(request, 'error.html', {'error': 'Invalid Action!!'})

	return HttpResponseRedirect(item.get_comm_url())
Esempio n. 3
0
def create_deal(request, venue_id):
    v = Venue.objects.get(id=venue_id)

    if request.POST:
        f = DealForm(request.POST)
        if f.is_valid():
            d = f.save(commit=False)
            d.venue = v
            d.save()

            return HttpResponseRedirect('/')
    else:
        f = DealForm()

    args = {}
    args.update(csrf(request))

    args['venue'] = v
    args['form'] = f

    return render_to_response('create_deal.html', args)