def form_valid(self, form): # save model application = form.save() # if available, save the "utm_source" query param application.utm_source = self.request.GET.get('utm_source', '') # assign application object to current batch batch = Batch.objects.get(accepting_applications=True) application.batch = batch application.save() next_step_url = reverse('applications:application-2', args=(str(application.id), )) # send confirmation email email = form.cleaned_data['email'] subject = 'Thank you for applying to rmotr.com courses' send_template_mail(subject, 'application-email-confirm.html', recipient_list=[email], context={ 'next_step_url': next_step_url, 'first_name': form.cleaned_data['first_name'] }) return render(self.request, 'applications/application_step_1_confirmation.html', context={'application': application})
def form_valid(self, form): app = Application.objects.get(id=self.kwargs['uuid']) for i in range(6): q_name = 'scholarship_q{}'.format(i + 1) setattr(app, q_name, form.cleaned_data[q_name]) # mark application as step4 completed app.status = 4 # send email with first scholarship assignment subject = 'Scholarship application assignment 1' solution_url = reverse('applications:application-5', args=(str(app.id), )) send_template_mail( subject, 'application-scholarship-assignment-1.html', recipient_list=[app.email], context={ 'solution_url': solution_url, 'scholarship_assignment_url': settings.SCHOLARSHIP_ASSIGNMENTS['assignment_1'], 'application': app }) app.scholarship_a1_email_sent = datetime.now() app.save() return render(self.request, 'applications/application_step_4_confirmation.html')
def handle(self, *args, **kwargs): action = kwargs['action'] dry_run = kwargs['dry_run'] if action not in CONFIG: raise CommandError('Invalid action type, please use one of: {}' ''.format(', '.join(CONFIG.keys()))) config = CONFIG[action] applications = Application.objects.filter(**config['filter']) if 'exclude' in config: applications = applications.exclude(**config['exclude']) print('Sending reminder emails...') print() for app in applications: next_url = reverse(config['next_url'], args=(str(app.id), )) context = {'next_url': next_url, 'application': app} subject = config['subject'].replace('*|FNAME|*', app.first_name) template = config['template_name'] if dry_run: # instead of sending real emails, print in stdout print('Recipient: "{}"'.format(app.email)) print('Subject: "{}"'.format(subject)) print('Next URL: "{}"'.format(next_url)) print() else: send_template_mail(subject, template, recipient_list=[app.email], context=context) print('Finished. {} emails were successfully sent' ''.format(applications.count()))
def form_valid(self, form): user = form.save(commit=False) user.is_active = False user.set_password(form.cleaned_data['password']) user.save() # send confirmation email subject = 'Thank you for signing up at rmotr.com' send_template_mail(subject, 'signup-successful.html', recipient_list=[user.email], context={'user': user}) return super(UserSignupView, self).form_valid(form)
def form_valid(self, form): user = form.save(commit=False) user.is_active = False user.set_password(form.cleaned_data['password']) user.save() # send confirmation email subject = 'Thank you for signing up at rmotr.com' send_template_mail(subject, 'signup-successful.html', recipient_list=[user.email], context={'user': user}) return super(UserSignupView, self).form_valid(form)
def post(self, *args, **kwargs): stripe.api_key = settings.STRIPE['secret_key'] application = get_object_or_404(Application, id=kwargs['uuid']) try: charge = stripe.Charge.create( amount=application.get_price(), # amount in cents currency="usd", source=self.request.POST['stripeToken'], description="Remote Python Course", metadata={ 'application_id': kwargs['uuid'], 'email': application.email, 'batch': application.batch.number }) except stripe.error.CardError as e: # The card has been declined context = { 'app': application, 'public_key': settings.STRIPE['public_key'], 'amount_cents': application.get_price(), 'amount_dollars': int(application.get_price()) / 100, 'error': e } return render(self.request, 'applications/application_checkout.html', context=context) else: # save payment details application.charge_id = charge['id'] application.charge_details = charge application.save() # notify admins subject = '{} {} has just performed a checkout'.format( application.first_name.title(), application.last_name.title()) application_url = reverse('admin:applications_application_change', args=(str(application.id), )) context = { 'application_url': application_url, 'amount_dollars': int(application.get_price()) / 100, 'application': application } send_template_mail(subject, 'application-checkout-notify.html', recipient_list=[a[1] for a in settings.ADMINS], context=context) return render(self.request, 'applications/application_checkout_success.html', context={'app': application})
def form_valid(self, form): app = Application.objects.get(id=self.kwargs['uuid']) correct_count = 0 for index, question in enumerate(SKILLS_ASSESSMENT): if question['correct'] == form.cleaned_data['q{}'.format(index)]: correct_count += 1 app.skills_assessment_questions = SKILLS_ASSESSMENT app.skills_assessment_answers = form.cleaned_data app.skills_assessment_correct_count = correct_count # mark application as step3 completed app.status = 3 app.save() # notify admins subject = '{} {} has completed the application form'.format( app.first_name.title(), app.last_name.title()) application_url = reverse('admin:applications_application_change', args=(str(app.id), )) send_template_mail(subject, 'application-admin-notify.html', recipient_list=[a[1] for a in settings.ADMINS], context={ 'application_url': application_url, 'application': app }) context = { 'scholarship_url': reverse('applications:application-4', args=(str(self.kwargs['uuid']), )), 'application': app } return render(self.request, 'applications/application_step_3_confirmation.html', context=context)
def form_valid(self, form): app = Application.objects.get(id=self.kwargs['uuid']) field = 'scholarship_a{}_solution'.format(self.assignment_number) solution = form.cleaned_data['scholarship_a{}_solution'.format( self.assignment_number)] setattr(app, field, solution) # mark application as step5 completed app.status = self.current_status # send email with the next scholarship assignment if not hasattr(self, 'last_assignment') or not self.last_assignment: subject = 'Scholarship application assignment {}'.format( self.assignment_number + 1) solution_url = reverse( 'applications:application-{}'.format(self.current_status + 1), args=(str(app.id), )) email_template = 'application-scholarship-assignment-{}.html'.format( self.assignment_number + 1) send_template_mail( subject, email_template, recipient_list=[app.email], context={ 'solution_url': solution_url, 'scholarship_assignment_url': settings.SCHOLARSHIP_ASSIGNMENTS['assignment_{}'.format( self.assignment_number + 1)], 'application': app }) field = 'scholarship_a{}_email_sent'.format( self.assignment_number + 1) setattr(app, field, datetime.now()) app.save() template = 'applications/application_step_{}_confirmation.html'.format( self.current_status) return render(self.request, template)
def process_application(self, app_id): if app_id in self.processed_applications_ids: self.duplicated_applications_ids.add(app_id) return try: app = Application.objects.get(id=app_id) except Application.DoesNotExist: self.nonexistent_applications_ids.append(app_id) return if not app.selected: self.unselected_applications_ids.append(app_id) return # Everything ok! Send the email. Mark as processed self.processed_applications_ids.append(app_id) signup_url = reverse('applications:application-signup', args=(str(app.id),)) context = { 'signup_url': signup_url, 'application': app } if self.dry_run: # instead of sending real emails, print in stdout print("\n====================================") print('App ID: "{}"'.format(app.id)) print('Recipient: "{}"'.format(app.email)) print('Subject: "{}"'.format(SUBJECT)) print("URL: {}".format(signup_url)) print("====================================\n") return send_template_mail(SUBJECT, self.template_name, recipient_list=[app.email], context=context)