def done(self, form_list, **kwargs): registration = RegistrationForm(form_list[0].cleaned_data,instance=self.registration).save(commit=False) custom_data = self.get_cleaned_data_for_step('registration_form_custom') or None if custom_data: registration.data = custom_data if registration.status == Registration.STATUS_WAITLIST_INCOMPLETE: registration.status = Registration.STATUS_WAITLISTED elif registration.status == Registration.STATUS_APPLY_INCOMPLETE: registration.status = Registration.STATUS_APPLIED # registration.status = Registration.STATUS_WAITLISTED if self.registration.is_waitlisted else Registration.STATUS_REGISTERED else: price_data = self.get_cleaned_data_for_step('price_form') or None if price_data: registration.price = price_data['price'] payment = Payment.objects.create(registration=registration,amount=registration.price.amount,processor=price_data['payment_method']) payment_data = self.get_cleaned_data_for_step('payment_form') or None if payment_data: payment.data = payment_data payment.save() processor = self.get_payment_processor() if processor: processor.post_process_form(payment, payment_data) if payment.get_post_form(): registration.save() return HttpResponseRedirect(reverse('pay',kwargs={'id':registration.id})) else: registration.status = Registration.STATUS_REGISTERED registration.save() email_status(registration) self.storage.reset() return HttpResponseRedirect(reverse('registration',kwargs={'id':registration.id}))
def update_event_statuses(request, event): registrations = event.registrations.filter(id__in=request.data.get('selected')) registrations.update(status=request.data.get('status')) if request.data.get('send_email'): for registration in registrations: email_status(registration) return Response({'status':'success'})
def update_registration_status(request,id): registration = Registration.objects.get(id=id) if request.method == 'GET': form = AdminRegistrationStatusForm(instance=registration) elif request.method == 'POST': form = AdminRegistrationStatusForm(request.POST,instance=registration) if form.is_valid(): registration = form.save() email_status(registration) return redirect('registrations',slug_or_id=registration.event_id) #event.get_absolute_url() return render(request, 'ezreg/update_registration_status.html', {'form':form,'registration':registration} ,context_instance=RequestContext(request))
def cancel_registration(request,id): key = request.GET.get('key',None) registration = Registration.objects.get(id=id,key=key) if registration.status in [Registration.STATUS_WAITLIST_PENDING,Registration.STATUS_WAITLISTED]: registration.status = Registration.STATUS_CANCELLED registration.save() email_status(registration) message = 'Your registration has been cancelled' else: message = 'Registration can only be cancelled if you are currently waitlisted' return render(request, 'ezreg/registration.html', {'registration':registration,'message':message},context_instance=RequestContext(request))
def update_event_statuses(request, event): registrations = event.registrations.filter( id__in=request.data.get('selected')) registrations.update(status=request.data.get('status')) for registration in registrations: Log.create( text='Registration status for %s updated to %s by %s' % (registration.email, registration.status, request.user.username), objects=[registration, registration.event, request.user]) if request.data.get('send_email'): email_status(registration) return Response({'status': 'success'})
def cancel_registration(request,id): key = request.GET.get('key',None) registration = Registration.objects.get(id=id,key=key) if registration.status in [Registration.STATUS_WAITLIST_PENDING,Registration.STATUS_WAITLISTED]: registration.status = Registration.STATUS_CANCELLED registration.save() email_status(registration) message = 'Your registration has been cancelled' Log.create(text='Registration for %s cancelled'%(registration.email),objects=[registration]) else: message = 'Registration can only be cancelled if you are currently waitlisted' return render(request, 'ezreg/registration.html', {'registration':registration,'message':message})
def update_registration_status(request,id): registration = Registration.objects.get(id=id) if request.method == 'GET': form = AdminRegistrationStatusForm(instance=registration) elif request.method == 'POST': form = AdminRegistrationStatusForm(request.POST,instance=registration) if form.is_valid(): registration = form.save() email_status(registration) Log.create(text='Registration status for %s updated to %s by %s'%(registration.email,registration.status,request.user.username),objects=[registration,registration.event,request.user]) return redirect('registrations',slug_or_id=registration.event_id) #event.get_absolute_url() return render(request, 'ezreg/update_registration_status.html', {'form':form,'registration':registration} )
def postback(request): req = {k.upper(): v for k, v in request.POST.items() } #Touchnet seems inconsistent about case logger = logging.getLogger('touchnet') try: registration_id = req.get('EXT_TRANS_ID').split( ";").pop() #FID=12345;{FAU==12345;}REGISTRATION_ID registration = Registration.objects.get(id=registration_id) payment = registration.payment posting_key = TouchnetPaymentProcessor.get_posting_key(payment) # if payment.processor.config.has_key('posting_key'): if posting_key != req.get('POSTING_KEY'): # values = ', '.join([key+':'+value for key, value in req.items()]) raise Exception("Invalid POSTING_KEY") if req.get('PMT_STATUS') == 'success': payment.external_id = req.get('TPG_TRANS_ID') if float(req.get('PMT_AMT')) == float(payment.amount): payment.status = Payment.STATUS_PAID payment.paid_at = datetime.now() payment.save() registration.status = Registration.STATUS_REGISTERED registration.save() email_status(registration) else: payment.status = Payment.STATUS_INVALID_AMOUNT payment.save() raise Exception('Invalid amount posted %s, expecting %f' % (req.get('PMT_AMT'), payment.amount)) payment.save() elif req.get( 'PMT_STATUS' ) == 'cancelled' and payment.status != Payment.STATUS_PAID: payment.status = Payment.STATUS_CANCELLED payment.save() if registration.status in [ Registration.STATUS_PENDING_INCOMPLETE, Registration.STATUS_APPLY_INCOMPLETE, Registration.STATUS_WAITLIST_INCOMPLETE ]: registration.status = Registration.STATUS_CANCELLED registration.save() # payment.delete() # registration.delete() return JsonResponse({'status': 'ok', 'payment_status': payment.status}) except Exception, e: # Get an instance of a logger payment.status = Payment.STATUS_ERROR payment.save() logger.info("Error for EXT_TRANS_ID: %s" % req.get('EXT_TRANS_ID', '')) logger.error(e.message) return JsonResponse({'status': 'error'}, status=400)
def done(self, form_list, **kwargs): registration = RegistrationForm( form_list[0].cleaned_data, instance=self.registration).save(commit=False) custom_data = self.get_cleaned_data_for_step( 'registration_form_custom') or None if custom_data: registration.data = custom_data if registration.status == Registration.STATUS_WAITLIST_INCOMPLETE: registration.status = Registration.STATUS_WAITLISTED elif registration.status == Registration.STATUS_APPLY_INCOMPLETE: registration.status = Registration.STATUS_APPLIED # registration.status = Registration.STATUS_WAITLISTED if self.registration.is_waitlisted else Registration.STATUS_REGISTERED else: price_data = self.get_cleaned_data_for_step('price_form') or None if price_data: registration.price = price_data['price'] if registration.price.amount > 0.0: payment = Payment.objects.filter( registration=registration).first() if payment: payment.amount = registration.price.amount payment.processor = price_data['payment_method'] payment.save() else: payment = Payment.objects.create( registration=registration, amount=registration.price.amount, processor=price_data['payment_method']) payment_data = self.get_cleaned_data_for_step( 'payment_form') or None if payment_data: payment.data = payment_data payment.save() processor = self.get_payment_processor() if processor: processor.post_process_form(payment, payment_data) if payment.get_post_form(): registration.save() return HttpResponseRedirect( reverse('pay', kwargs={'id': registration.id})) else: registration.status = Registration.STATUS_REGISTERED else: registration.status = Registration.STATUS_REGISTERED registration.registered = timezone.now() registration.save() email_status(registration) self.storage.reset() return HttpResponseRedirect( reverse('registration', kwargs={'id': registration.id}))
def postback(request): req = {k.upper():v for k,v in request.POST.items()} #Touchnet seems inconsistent about case logger = logging.getLogger('touchnet') try: fid, registration_id = req.get('EXT_TRANS_ID').split(";") registration = Registration.objects.get(id=registration_id) payment = registration.payment posting_key = TouchnetPaymentProcessor.get_posting_key(payment) # if payment.processor.config.has_key('posting_key'): if posting_key != req.get('POSTING_KEY'): # values = ', '.join([key+':'+value for key, value in req.items()]) raise Exception("Invalid POSTING_KEY") if req.get('PMT_STATUS')=='success': payment.external_id = req.get('TPG_TRANS_ID') if float(req.get('PMT_AMT')) == float(payment.amount): payment.status = Payment.STATUS_PAID payment.paid_at = datetime.now() payment.save() registration.status = Registration.STATUS_REGISTERED registration.save() email_status(registration) else: payment.status = Payment.STATUS_INVALID_AMOUNT payment.save() raise Exception('Invalid amount posted %s, expecting %f' % (req.get('PMT_AMT'),payment.amount)) payment.save() elif req.get('PMT_STATUS')=='cancelled': payment.status = Payment.STATUS_CANCELLED payment.save() registration.status = Registration.STATUS_CANCELLED registration.save() # payment.delete() # registration.delete() return JsonResponse({'status':'ok','payment_status':payment.status}) except Exception, e: # Get an instance of a logger payment.status = Payment.STATUS_ERROR payment.save() logger.info("Error for EXT_TRANS_ID: %s"%req.get('EXT_TRANS_ID','')) logger.error(e.message) return JsonResponse({'status':'error'},status=400)