def decorator(request, *args, **kwargs): code = request.GET.get('code', None) try: voucher = get_cached_voucher(code) offer = voucher.best_offer if offer.condition.range and offer.condition.range.course_seat_types == 'credit': if not request.user.is_authenticated: # The next url needs to have the coupon code as a query parameter. next_url = '{}?{}'.format(request.path, request.META.get('QUERY_STRING')) return redirect_to_login(next_url) except (Voucher.DoesNotExist, exceptions.ProductNotFoundError): pass return function(request, *args, **kwargs)
def handle(self, *args, **options): send_nudge_email_count = 0 site = Site.objects.get_current() nudge_emails = self._get_nudge_emails() total_nudge_emails_count = nudge_emails.count() logger.info( '[Code Assignment Nudge Email] Total count of Enterprise Nudge Emails that are scheduled for today is %s.', total_nudge_emails_count ) for nudge_email in nudge_emails: try: voucher = get_cached_voucher(nudge_email.code) except Voucher.DoesNotExist: continue if voucher.is_expired(): # unsubscribe the user to avoid sending any nudge in future regarding this same code assignment CodeAssignmentNudgeEmails.unsubscribe_from_nudging( codes=[nudge_email.code], user_emails=[nudge_email.user_email] ) continue base_enterprise_url = nudge_email.options.get('base_enterprise_url', '') # Get the formatted email body and subject on the bases of given code. email_body, email_subject = nudge_email.email_template.get_email_content( nudge_email.user_email, nudge_email.code, base_enterprise_url=base_enterprise_url, ) if email_body: nudge_email.already_sent = True nudge_email.save() send_nudge_email_count += 1 sender_alias = self._get_sender_alias(site, nudge_email) reply_to = self._get_reply_to_email(site, nudge_email) send_code_assignment_nudge_email.delay( nudge_email.user_email, email_subject, email_body, sender_alias, reply_to, base_enterprise_url=base_enterprise_url, ) self.set_last_reminder_date(nudge_email.user_email, nudge_email.code) self._create_email_sent_record(site, nudge_email) logger.info( '[Code Assignment Nudge Email] %s out of %s added to the email sending queue.', send_nudge_email_count, total_nudge_emails_count )