Beispiel #1
0
def subscribe(request):
	if request.method == 'POST':
		form = eventChoiceForm(request.POST)
		if form.is_valid():
			step = request.GET['step']
			user_profile = request.user.userprofile

			if form.data['id_event'].isdigit() and form.data['id_event'] > 0:
				eventdata = event.objects.get(pk = form.data['id_event'])
				eventprice = event_price.objects.get(id_event = form.data['id_event'], id_district = user_profile.id_district )

			if (step.isdigit()) and (int(step) == 2) and eventprice:

				reference = user_profile.activation_key
				yet_subscribe = None
				try:
					yet_subscribe_check = event_subscribe.objects.filter(id_event = int(form.data['id_event']), id_user = request.user.id )
					for subscribed in yet_subscribe_check:
						yet_subscribe = subscribed
						if subscribed.StatusTransacao.encode('utf-8') == 'Cancelado' or subscribed.StatusTransacao == 'Cancelado':
							yet_subscribe = None
				except:
					yet_subscribe = None

				if yet_subscribe is not None:
					eventprice = str('%.2f' % (yet_subscribe.event_price,)).replace('.',',')
					response = render_to_response("subscribe.html", {'PAGE_NAME': 'Inscerver', 'eventdata': eventdata, 'eventprice': eventprice, 'pagseguro_email': settings.PAGSEGURO_EMAIL, 'reference': reference, 'event_subscribe': yet_subscribe, }, context_instance=RequestContext(request))


				else:
					user = request.user
					new_event = event.objects.get(pk = request.POST.get('id_event'))
					eventprice_pag = str(eventprice).replace(',','.')
					if request.POST['pay_choice'] == 'P':
						subscribe_intent = event_subscribe_intent(id_event=new_event, id_user=user, event_price=eventprice_pag)
						subscribe_intent.save()
						response = render_to_response("subscribe.html", {'PAGE_NAME': 'Inscerver', 'eventdata': eventdata, 'eventprice_pag': eventprice_pag, 'eventprice': eventprice, 'pagseguro_email': settings.PAGSEGURO_EMAIL, 'reference': reference }, context_instance=RequestContext(request))
					elif request.POST['pay_choice'] == 'F':
						response = render_to_response("subscribe.html", {'PAGE_NAME': 'Inscerver', 'eventdata': eventdata, 'eventprice_pag': eventprice_pag, 'eventprice': eventprice, 'reference': reference, 'pay_choice': request.POST['pay_choice'] }, context_instance=RequestContext(request))

			elif (step.isdigit()) and (int(step) == 3):
				log = LOG(True)
				LOG_TAG='[LOCAL] '
				log.write(LOG_TAG+"  === Nova inscricao LOCAL ===")
				log.write(LOG_TAG+"  ** CLIENT INFO: IP=["+str(request.META['REMOTE_ADDR'])+"] USER AGENT=["+str(request.META['HTTP_USER_AGENT'])+"] **")
				user = request.user
				new_event = event.objects.get(pk = request.POST.get('id_event'))

				price = request.POST.get('event_price').replace(',','.')
				new_date = datetime.today().strftime("%d/%m/%Y %H:%M:%S")
				new_ID = randint(1,1000000000)
				new_subscribe = event_subscribe(TransacaoID=new_ID, DataTransacao=new_date, TipoPagamento='Federação depósito', StatusTransacao='Em Análise', event_price=price, subscribe_amount=request.POST.get('subscribe_amount'), id_event=new_event, id_user=user)

				INFO = 'TransacaoID=['+str(new_ID)+'] DataTransacao=['+str(new_date)+'] event_price=['+str(price)+'] id_event=['+str(new_event)+'] user='******'utf-8') == 'Cancelado' or subscribed.StatusTransacao == 'Cancelado':
							yet_subscribe = None
							log.write(LOG_TAG+"    -> Existe uma inscricao CANCELADA cadastrada no BD...")
						else:
							if subscribed.DataTransacao != new_date:
								yet_subscribe = None

				except Exception, e:
					log.write(LOG_TAG+'Encontrado ERRO ao processar inscricao: '+str(e), level='ERROR')
					yet_subscribe = None

				if yet_subscribe is None:
					log.write(LOG_TAG+"    -> Salvando no BD")
					new_subscribe.save()

				return direct_to_template(request,'subscribe_finish.html')
			else:

				response = render_to_response("subscribe.html", {'form': form, 'PAGE_NAME': 'Inscerver' }, context_instance=RequestContext(request))


		else:
			response = render_to_response("subscribe.html", {'form': form, 'PAGE_NAME': 'Inscerver' }, context_instance=RequestContext(request))
Beispiel #2
0
				if yet_subscribe is None:
					log.write(LOG_TAG+"    -> Salvando no BD")
					new_subscribe.save()

				return direct_to_template(request,'subscribe_finish.html')
			else:

				response = render_to_response("subscribe.html", {'form': form, 'PAGE_NAME': 'Inscerver' }, context_instance=RequestContext(request))


		else:
			response = render_to_response("subscribe.html", {'form': form, 'PAGE_NAME': 'Inscerver' }, context_instance=RequestContext(request))


	else:
		form = eventChoiceForm()
		response = render_to_response("subscribe.html", {'form': form, 'PAGE_NAME': 'Inscerver'}, context_instance=RequestContext(request))

	return response



@csrf_exempt
def pagreturn(request):
	"""
	Descricao:
	Armazena os dados do pedido e exibe a tela de pedido concluido.
	Verifica se o robo do PagSeguro enviou os dados do pedido via POST, e
	então armazena no banco de dados.
	Por fim, exibe a tela de pedido concluido com sucesso.
	"""