def best_buy_table_callback(request, context=None): if context is None: context = {} if request.method == 'POST': form = BestBuyCallbackForm(request.POST) if form.is_valid(): create_profile_output = create_stage_one_profile( request=request, email=form.cleaned_data['email'], source='best_buy_call_back', send_activation=False, login_user=False) user, user_created, record_stats = create_profile_output record_referral_signup(request=request, user=user, user_created=user_created, action='best_buy_call_back') AdviserQueue.add_to_queue( email=form.cleaned_data['email'], first_name=form.cleaned_data['name'], last_name='.', lead_source='Best Buy Call Back', telephone_number=form.cleaned_data['phone']) return render(request, 'products/topaccounts/callback/success.html', context) context['form'] = form return render(request, 'products/topaccounts/callback/form.html', context) return render(request, 'products/topaccounts/callback/failure.html', context)
def adviser_client_dashboard(request, client_id, context=None): if context is None: context = {} if AdviserQueue.objects.filter(pk=client_id, adviser=request.user).exists(): adviser_queue = AdviserQueue.objects.get(pk=client_id, adviser=request.user) try: user = User.objects.get(email=adviser_queue.email) user_created = False except User.DoesNotExist: create_profile_output = create_stage_one_profile(request, adviser_queue.email, source='Concierge Signup', send_activation=False, login_user=False) if isinstance(create_profile_output, tuple): user, user_created, record_stats = create_profile_output else: return create_profile_output record_referral_signup(request=request, user=user, user_created=user_created, action='signup') context['concierge_user'], _ = ConciergeUserOption.objects.get_or_create(user=user) context['user_options_form'] = ConciergeUserOptionForm(instance=context['concierge_user']) context['user_notes_form'] = ConciergeUserNotesForm(initial={'user': user}) context['user_notes'] = ConciergeUserNotes.objects.filter(user=user) concierge_lead_capture, _ = ConciergeLeadCapture.objects.get_or_create(user=user, named_user=True) context['lead_capture_first'] = ConciergeLeadCaptureForm(prefix='first_client', instance=concierge_lead_capture) concierge_lead_capture, _ = ConciergeLeadCapture.objects.get_or_create(user=user, named_user=False) context['lead_capture_second'] = ConciergeLeadCaptureForm(prefix='second_client', instance=concierge_lead_capture) record_referral_signup(request=request, user=user, user_created=user_created, action='concierge_enquiry') return render(request, 'concierge/adviser/client_dashboard.html', context) return HttpResponse(status=403)
def adviser_signed_client_ajax(request, enquiry_id): if request.method == 'POST': if AdviserQueue.objects.filter(adviser=request.user, pk=enquiry_id).exists(): adviser_queue = AdviserQueue.objects.get(pk=enquiry_id) form = SignedForm(request.POST, instance=adviser_queue) if form.is_valid(): form.save() adviser_queue.status = 9 adviser_queue.add_note( 'Client signed up with £%d, fee was charged as £%d' % (form.cleaned_data['portfolio_value'], form.cleaned_data['fee'])) adviser_queue.save() try: user = User.objects.get(email=adviser_queue.email) except User.DoesNotExist: user, _, record_stats = create_stage_one_profile( request, adviser_queue.email, 'manual_add_concierge', send_activation=False, login_user=False) record_referral_signup(request, user, True, 'concierge_client') return HttpResponse(status=204) else: assert False, form.errors return HttpResponse(status=409, content='{"status":"doesn\'t exist"}') return HttpResponse(status=409, content='{"status":"not post"}')
def bj_signup(request): form_1 = BJForm(prefix="bj_form1") form_2 = BJForm(prefix="bj_form2") if request.method == "POST": form_1 = BJForm(request.POST, prefix="bj_form1") form_2 = BJForm(request.POST, prefix="bj_form2") if form_1.is_valid() or form_2.is_valid(): if form_1.is_valid(): form = form_1 else: form = form_2 form.save() if 'referer' in request.session: referer = Referrer.objects.get(pk=request.session['referer']).name else: referer = '(Direct)' analytics.delay('event', 'Beckford James', 'Signup', referer) user, user_created, record_stats = create_stage_one_profile(request=request, email=form.cleaned_data.get('email'), source='beckford_james_signup', send_activation=False, login_user=False) from common.tasks import update_subscription_on_email_service update_subscription_on_email_service.delay(user.email, interest_group=u'Beckford James Referral') name = form.cleaned_data.get('name') email = form.cleaned_data.get('email') telephone = form.cleaned_data.get('telephone') postcode = form.cleaned_data.get('postcode') text_email = get_template('ifa/bj_signup_email.txt') client_details = {'name': name, 'email': email, 'telephone': telephone, 'postcode': postcode} c = Context(client_details) text_content = text_email.render(c) subject, from_email = "New Beckford James Enquiry", "*****@*****.**" msg = EmailMultiAlternatives(subject, text_content, from_email, ["*****@*****.**", '*****@*****.**']) msg.send() AdviserQueue.add_to_queue(client_details['email'], client_details['name'], u'.', u'IFA (Beckford James) Signup', telephone_number=client_details['telephone']) record_referral_signup(request, user, user_created, 'bj_referral') return redirect(reverse('bj_thankyou')) else: messages.error(request, 'Your input contained errors, or you have already enquired about Beckford James') return render(request, 'ifa/bj_signup.html', { 'bj_form': form_1, 'bj_form2': form_2 })
def savings_healthcheck_portfolio_add_product( request, template_file="products/healthcheck/success/newproduct.html", context=None): if context is None: context = {} form = AddProductsForm() if request.method == "POST": form = AddProductsForm(request.POST) if form.is_valid(): user = request.user product = Product.objects.get(pk=form.cleaned_data.get('product')) portfolio = ProductPortfolio() portfolio.user = user portfolio.account_type = BestBuy.objects.get( id=product.bestbuy_type.all()[0].id) portfolio.balance = form.cleaned_data.get('balance') portfolio.master_product = product.master_product portfolio.provider = product.provider # When making I found some bonus terms can be entered as '' as well as None #hence the ugly if statement to ensure it is an int #as it only gets evaluated on portfolio.save() which by then a typeerror try/except is too late as it could be any field if isinstance(product.bonus_term, int) or isinstance( product.bonus_term, float): portfolio.bonus_term = product.bonus_term else: portfolio.bonus_term = None portfolio.notice = product.notice opening_date = form.cleaned_data.get('opening_date') if opening_date: portfolio.opening_date = opening_date portfolio.is_synched = False portfolio.save() context['p'] = portfolio record_referral_signup(request=request, user=user, user_created=False, action='rate_tracker_used', third_party=False) if request.is_ajax(): return render(request, template_file, context) context['form'] = form context['error'] = True template_file = 'products/healthcheck/addproductsform.html' return render(request, template_file, context)
def adviser_client_dashboard(request, client_id, context=None): if context is None: context = {} if AdviserQueue.objects.filter(pk=client_id, adviser=request.user).exists(): adviser_queue = AdviserQueue.objects.get(pk=client_id, adviser=request.user) try: user = User.objects.get(email=adviser_queue.email) user_created = False except User.DoesNotExist: create_profile_output = create_stage_one_profile( request, adviser_queue.email, source='Concierge Signup', send_activation=False, login_user=False) if isinstance(create_profile_output, tuple): user, user_created, record_stats = create_profile_output else: return create_profile_output record_referral_signup(request=request, user=user, user_created=user_created, action='signup') context[ 'concierge_user'], _ = ConciergeUserOption.objects.get_or_create( user=user) context['user_options_form'] = ConciergeUserOptionForm( instance=context['concierge_user']) context['user_notes_form'] = ConciergeUserNotesForm( initial={'user': user}) context['user_notes'] = ConciergeUserNotes.objects.filter(user=user) concierge_lead_capture, _ = ConciergeLeadCapture.objects.get_or_create( user=user, named_user=True) context['lead_capture_first'] = ConciergeLeadCaptureForm( prefix='first_client', instance=concierge_lead_capture) concierge_lead_capture, _ = ConciergeLeadCapture.objects.get_or_create( user=user, named_user=False) context['lead_capture_second'] = ConciergeLeadCaptureForm( prefix='second_client', instance=concierge_lead_capture) record_referral_signup(request=request, user=user, user_created=user_created, action='concierge_enquiry') return render(request, 'concierge/adviser/client_dashboard.html', context) return HttpResponse(status=403)
def reccuring_business_bestbuy_emails(request): context = {'weekly_form': WeeklyBusinessRateAlertsForm()} if request.method == 'POST': form = WeeklyBusinessRateAlertsForm(request.POST) if form.is_valid(): best_buy_table_emails = form.save() if 'referer' in request.session: referer = Referrer.objects.get(pk=request.session['referer']).name else: referer = '(Direct)' analytics.delay('event', 'Recurring Business Best Buy Emails', 'Signup', referer) create_profile_output = create_stage_one_profile(request=request, email=best_buy_table_emails.email, source='recurring_business_best_buy_emails', send_activation=False, login_user=False) if isinstance(create_profile_output, tuple): user, user_created, record_stats = create_profile_output else: return create_profile_output record_referral_signup(request=request, user=user, user_created=user_created, action='signup') context['weekly_signed_up'] = True if best_buy_table_emails.frequency == 1: update_subscription_on_email_service.delay(best_buy_table_emails.email, interest_group=u'Daily Business Best Buy Tables') record_referral_signup(request=request, user=user, user_created=user_created, action='recurring_business_daily_best_buys') if best_buy_table_emails.frequency == 2: update_subscription_on_email_service.delay(best_buy_table_emails.email, interest_group=u'Weekly Business Best Buy Tables') record_referral_signup(request=request, user=user, user_created=user_created, action='recurring_business_weekly_best_buys') if best_buy_table_emails.frequency == 3: update_subscription_on_email_service.delay(best_buy_table_emails.email, interest_group=u'Monthly Business Best Buy Tables') record_referral_signup(request=request, user=user, user_created=user_created, action='recurring_business_monthly_best_buys') return render(request, 'products/topaccounts/business_reccuring_emails.html', context)
def reccuring_business_bestbuy_emails(request): context = {'weekly_form': WeeklyBusinessRateAlertsForm()} if request.method == 'POST': form = WeeklyBusinessRateAlertsForm(request.POST) if form.is_valid(): best_buy_table_emails = form.save() if 'referer' in request.session: referer = Referrer.objects.get( pk=request.session['referer']).name else: referer = '(Direct)' analytics.delay('event', 'Recurring Business Best Buy Emails', 'Signup', referer) create_profile_output = create_stage_one_profile( request=request, email=best_buy_table_emails.email, source='recurring_business_best_buy_emails', send_activation=False, login_user=False) if isinstance(create_profile_output, tuple): user, user_created, record_stats = create_profile_output else: return create_profile_output record_referral_signup(request=request, user=user, user_created=user_created, action='signup') context['weekly_signed_up'] = True if best_buy_table_emails.frequency == 1: update_subscription_on_email_service.delay( best_buy_table_emails.email, interest_group=u'Daily Business Best Buy Tables') record_referral_signup( request=request, user=user, user_created=user_created, action='recurring_business_daily_best_buys') if best_buy_table_emails.frequency == 2: update_subscription_on_email_service.delay( best_buy_table_emails.email, interest_group=u'Weekly Business Best Buy Tables') record_referral_signup( request=request, user=user, user_created=user_created, action='recurring_business_weekly_best_buys') if best_buy_table_emails.frequency == 3: update_subscription_on_email_service.delay( best_buy_table_emails.email, interest_group=u'Monthly Business Best Buy Tables') record_referral_signup( request=request, user=user, user_created=user_created, action='recurring_business_monthly_best_buys') return render(request, 'products/topaccounts/business_reccuring_emails.html', context)
def personal_top_accounts(request, bestbuy_slug, term=None): context = RequestContext(request) # required for the sidebar bestbuys = BestBuy.objects.filter(has_table=True, client_type='p') context['bestbuys'] = bestbuys context['bestbuyselected'] = True bestbuy = BestBuy.objects.get(slug=bestbuy_slug, client_type='p') context['bestbuy'] = bestbuy products = bestbuy.get_personal_products(term=term) fixed_rate_bond_products = defaultdict(list) for product in products: product_term = product.link_to_products.get(bestbuy=bestbuy, product=product, date_replaced=None).term fixed_rate_bond_products[product_term].append(product) context['terms'] = fixed_rate_bond_products.keys() context['products'] = fixed_rate_bond_products context['emailform'] = EmailInstructionsForm() context['weekly_form'] = WeeklyRateAlertsForm() if request.method == 'POST': form = WeeklyRateAlertsForm(request.POST) if form.is_valid(): best_buy_table_emails = form.save() if 'referer' in request.session: referer = Referrer.objects.get(pk=request.session['referer']).name else: referer = '(Direct)' analytics.delay('event', 'Reccuring Best Buy Emails', 'Signup', referer) create_profile_output = create_stage_one_profile(request=request, email=best_buy_table_emails.email, source='recurring_best_buy_emails', send_activation=False, login_user=False) if isinstance(create_profile_output, tuple): user, user_created, record_stats = create_profile_output else: return create_profile_output record_referral_signup(request=request, user=user, user_created=user_created, action='signup') context['weekly_signed_up'] = True from common.tasks import update_subscription_on_email_service if best_buy_table_emails.frequency == 1: update_subscription_on_email_service.delay(best_buy_table_emails.email, interest_group=u'Daily Best Buy Tables') record_referral_signup(request=request, user=user, user_created=user_created, action='recurring_daily_best_buys') if best_buy_table_emails.frequency == 2: update_subscription_on_email_service.delay(best_buy_table_emails.email, interest_group=u'Weekly Best Buy Tables') record_referral_signup(request=request, user=user, user_created=user_created, action='recurring_weekly_best_buys') if best_buy_table_emails.frequency == 3: update_subscription_on_email_service.delay(best_buy_table_emails.email, interest_group=u'Monthly Best Buy Tables') record_referral_signup(request=request, user=user, user_created=user_created, action='recurring_monthly_best_buys') return render_to_response('products/topaccounts/table.html', context_instance=context)
def savings_healthcheck_portfolio_add_product(request, template_file="products/healthcheck/success/newproduct.html", context=None): if context is None: context = {} form = AddProductsForm() if request.method == "POST": form = AddProductsForm(request.POST) if form.is_valid(): user = request.user product = Product.objects.get(pk=form.cleaned_data.get('product')) portfolio = ProductPortfolio() portfolio.user = user portfolio.account_type = BestBuy.objects.get(id=product.bestbuy_type.all()[0].id) portfolio.balance = form.cleaned_data.get('balance') portfolio.master_product = product.master_product portfolio.provider = product.provider # When making I found some bonus terms can be entered as '' as well as None #hence the ugly if statement to ensure it is an int #as it only gets evaluated on portfolio.save() which by then a typeerror try/except is too late as it could be any field if isinstance(product.bonus_term, int) or isinstance(product.bonus_term, float): portfolio.bonus_term = product.bonus_term else: portfolio.bonus_term = None portfolio.notice = product.notice opening_date = form.cleaned_data.get('opening_date') if opening_date: portfolio.opening_date = opening_date portfolio.is_synched = False portfolio.save() context['p'] = portfolio record_referral_signup(request=request, user=user, user_created=False, action='rate_tracker_used', third_party=False) if request.is_ajax(): return render(request, template_file, context) context['form'] = form context['error'] = True template_file = 'products/healthcheck/addproductsform.html' return render(request, template_file, context)
def savings_healthcheck_portfolio_add_fixed_product( request, template_file="products/healthcheck/success/newproduct.html", context=None): if context is None: context = {} form = AddFixedProductForm() if request.method == "POST": form = AddFixedProductForm(request.POST) if form.is_valid(): user = request.user reminder = RatetrackerReminder() reminder.user = user reminder.provider = form.cleaned_data.get('fixed_provider') account_type = BestBuy.objects.get( id=form.cleaned_data.get('account_type')) reminder.account_type = account_type reminder.balance = form.cleaned_data.get('balance') reminder.rate = form.cleaned_data.get('rate') reminder.maturity_date = form.cleaned_data.get('maturity_date') reminder.is_synched = False reminder.save() context['p'] = reminder record_referral_signup(request=request, user=user, user_created=False, action='rate_tracker_used', third_party=False) if request.is_ajax(): return render(request, template_file, context) else: messages.error(request, 'Your Savings Product was invalid.') context['fixed_product_form'] = form context['error'] = True template_file = 'products/healthcheck/addfixedproductsform.html' return render(request, template_file, context)
def adviser_signed_client_ajax(request, enquiry_id): if request.method == 'POST': if AdviserQueue.objects.filter(adviser=request.user, pk=enquiry_id).exists(): adviser_queue = AdviserQueue.objects.get(pk=enquiry_id) form = SignedForm(request.POST, instance=adviser_queue) if form.is_valid(): form.save() adviser_queue.status = 9 adviser_queue.add_note('Client signed up with £%d, fee was charged as £%d' % (form.cleaned_data['portfolio_value'], form.cleaned_data['fee'])) adviser_queue.save() try: user = User.objects.get(email=adviser_queue.email) except User.DoesNotExist: user, _, record_stats = create_stage_one_profile(request, adviser_queue.email, 'manual_add_concierge', send_activation=False, login_user=False) record_referral_signup(request, user, True, 'concierge_client') return HttpResponse(status=204) else: assert False, form.errors return HttpResponse(status=409, content='{"status":"doesn\'t exist"}') return HttpResponse(status=409, content='{"status":"not post"}')
def best_buy_table_callback(request, context=None): if context is None: context = {} if request.method == 'POST': form = BestBuyCallbackForm(request.POST) if form.is_valid(): create_profile_output = create_stage_one_profile(request=request, email=form.cleaned_data['email'], source='best_buy_call_back', send_activation=False, login_user=False) user, user_created, record_stats = create_profile_output record_referral_signup(request=request, user=user, user_created=user_created, action='best_buy_call_back') AdviserQueue.add_to_queue(email=form.cleaned_data['email'], first_name=form.cleaned_data['name'], last_name='.', lead_source='Best Buy Call Back', telephone_number=form.cleaned_data['phone']) return render(request, 'products/topaccounts/callback/success.html', context) context['form'] = form return render(request, 'products/topaccounts/callback/form.html', context) return render(request, 'products/topaccounts/callback/failure.html', context)
def savings_healthcheck_portfolio_add_fixed_product(request, template_file="products/healthcheck/success/newproduct.html", context=None): if context is None: context = {} form = AddFixedProductForm() if request.method == "POST": form = AddFixedProductForm(request.POST) if form.is_valid(): user = request.user reminder = RatetrackerReminder() reminder.user = user reminder.provider = form.cleaned_data.get('fixed_provider') account_type = BestBuy.objects.get(id=form.cleaned_data.get('account_type')) reminder.account_type = account_type reminder.balance = form.cleaned_data.get('balance') reminder.rate = form.cleaned_data.get('rate') reminder.maturity_date = form.cleaned_data.get('maturity_date') reminder.is_synched = False reminder.save() context['p'] = reminder record_referral_signup(request=request, user=user, user_created=False, action='rate_tracker_used', third_party=False) if request.is_ajax(): return render(request, template_file, context) else: messages.error(request, 'Your Savings Product was invalid.') context['fixed_product_form'] = form context['error'] = True template_file = 'products/healthcheck/addfixedproductsform.html' return render(request, template_file, context)
def post(self, request, format=None): data = request.data thb_reminder = None source = data.get('source', None) user, user_created = create_stage_one_profile(request=request, email=data['email'], source='thb_tool', send_activation=False, login_user=False) record_referral_signup(request=request, user=user, user_created=user_created, action='signup') if data['remind_me']: # Client asked to be reminded of the FSCS change to £75,000 update_subscription_on_email_service.delay(data['email'], interest_group=u'FSCS Protection Drop Reminder') record_referral_signup(request=request, user=user, user_created=user_created, action='thb_remind_me_fscs') if data['set_reminder'] == 'true': deposit_date = datetime.date(year=int(data['deposit_year']), month=int(data['deposit_month']), day=int(data['deposit_day'])) thb_reminder = THBToolReminder.add_reminder( name=data['name'], email=data['email'], phone_number=data['phone_number'], source=source, deposit_date=deposit_date, callback=(data['book_callback'] == 'true') ) record_referral_signup(request=request, user=user, user_created=user_created, action='thb_alert_me_fscs') if data['book_callback'] == 'true': AdviserQueue.add_to_queue(email=data['email'], first_name=data['name'], last_name='.', lead_source='THB Tool', telephone_number=data['phone_number']) if thb_reminder is not None: thb_reminder.scheduled_callback = True thb_reminder.save() record_referral_signup(request=request, user=user, user_created=user_created, action='thb_book_callback') return JsonResponse({ 'status': 'ok' })
def bj_signup(request): form_1 = BJForm(prefix="bj_form1") form_2 = BJForm(prefix="bj_form2") if request.method == "POST": form_1 = BJForm(request.POST, prefix="bj_form1") form_2 = BJForm(request.POST, prefix="bj_form2") if form_1.is_valid() or form_2.is_valid(): if form_1.is_valid(): form = form_1 else: form = form_2 form.save() if 'referer' in request.session: referer = Referrer.objects.get( pk=request.session['referer']).name else: referer = '(Direct)' analytics.delay('event', 'Beckford James', 'Signup', referer) user, user_created, record_stats = create_stage_one_profile( request=request, email=form.cleaned_data.get('email'), source='beckford_james_signup', send_activation=False, login_user=False) from common.tasks import update_subscription_on_email_service update_subscription_on_email_service.delay( user.email, interest_group=u'Beckford James Referral') name = form.cleaned_data.get('name') email = form.cleaned_data.get('email') telephone = form.cleaned_data.get('telephone') postcode = form.cleaned_data.get('postcode') text_email = get_template('ifa/bj_signup_email.txt') client_details = { 'name': name, 'email': email, 'telephone': telephone, 'postcode': postcode } c = Context(client_details) text_content = text_email.render(c) subject, from_email = "New Beckford James Enquiry", "*****@*****.**" msg = EmailMultiAlternatives( subject, text_content, from_email, ["*****@*****.**", '*****@*****.**']) msg.send() AdviserQueue.add_to_queue( client_details['email'], client_details['name'], u'.', u'IFA (Beckford James) Signup', telephone_number=client_details['telephone']) record_referral_signup(request, user, user_created, 'bj_referral') return redirect(reverse('bj_thankyou')) else: messages.error( request, 'Your input contained errors, or you have already enquired about Beckford James' ) return render(request, 'ifa/bj_signup.html', { 'bj_form': form_1, 'bj_form2': form_2 })
def personal_top_accounts(request, bestbuy_slug, term=None): context = RequestContext(request) # required for the sidebar bestbuys = BestBuy.objects.filter(has_table=True, client_type='p') context['bestbuys'] = bestbuys context['bestbuyselected'] = True bestbuy = BestBuy.objects.get(slug=bestbuy_slug, client_type='p') context['bestbuy'] = bestbuy products = bestbuy.get_personal_products(term=term) fixed_rate_bond_products = defaultdict(list) for product in products: product_term = product.link_to_products.get(bestbuy=bestbuy, product=product, date_replaced=None).term fixed_rate_bond_products[product_term].append(product) context['terms'] = fixed_rate_bond_products.keys() context['products'] = fixed_rate_bond_products context['emailform'] = EmailInstructionsForm() context['weekly_form'] = WeeklyRateAlertsForm() if request.method == 'POST': form = WeeklyRateAlertsForm(request.POST) if form.is_valid(): best_buy_table_emails = form.save() if 'referer' in request.session: referer = Referrer.objects.get( pk=request.session['referer']).name else: referer = '(Direct)' analytics.delay('event', 'Reccuring Best Buy Emails', 'Signup', referer) create_profile_output = create_stage_one_profile( request=request, email=best_buy_table_emails.email, source='recurring_best_buy_emails', send_activation=False, login_user=False) if isinstance(create_profile_output, tuple): user, user_created, record_stats = create_profile_output else: return create_profile_output record_referral_signup(request=request, user=user, user_created=user_created, action='signup') context['weekly_signed_up'] = True from common.tasks import update_subscription_on_email_service if best_buy_table_emails.frequency == 1: update_subscription_on_email_service.delay( best_buy_table_emails.email, interest_group=u'Daily Best Buy Tables') record_referral_signup(request=request, user=user, user_created=user_created, action='recurring_daily_best_buys') if best_buy_table_emails.frequency == 2: update_subscription_on_email_service.delay( best_buy_table_emails.email, interest_group=u'Weekly Best Buy Tables') record_referral_signup(request=request, user=user, user_created=user_created, action='recurring_weekly_best_buys') if best_buy_table_emails.frequency == 3: update_subscription_on_email_service.delay( best_buy_table_emails.email, interest_group=u'Monthly Best Buy Tables') record_referral_signup(request=request, user=user, user_created=user_created, action='recurring_monthly_best_buys') return render_to_response('products/topaccounts/table.html', context_instance=context)
def create_concierge_client(request, template_file="administration/concierge_creation/index.html"): context = RequestContext(request) if request.method == "POST": form = ConciergeForm(request.POST) if form.is_valid(): form_email = form.cleaned_data.get('email') first_name = form.cleaned_data.get('first_name') last_name = form.cleaned_data.get('last_name') number = form.cleaned_data.get('number') try: user = User.objects.get(email__iexact=form_email) try: profile = user.profile except Profile.DoesNotExist: profile = Profile(user=user) profile.save() except Profile.MultipleObjectsReturned: profiles = Profile.objects.filter(user=user) profile = profiles[0] user.first_name = first_name user.last_name = last_name user.is_active = True user.save() profile.telephone = number profile.is_synched = False profile.skeleton_user = False profile.filled_in_name = True profile.save() try: campaign_signup = CampaignsSignup.objects.get(email__iexact=form_email) except CampaignsSignup.DoesNotExist: campaign_signup = CampaignsSignup(email=form_email) campaign_signup.name = " ".join([first_name, last_name]) campaign_signup.telephone = number campaign_signup.is_client = True campaign_signup.is_synched = False campaign_signup.save() except User.DoesNotExist: try: campaign_signup = CampaignsSignup.objects.get(email__iexact=form_email) except CampaignsSignup.DoesNotExist: campaign_signup = CampaignsSignup() campaign_signup.email = form_email campaign_signup.name = " ".join([first_name, last_name]) campaign_signup.telephone = number campaign_signup.is_client = True campaign_signup.is_synched = False campaign_signup.save() user = User() user.is_active = True user.first_name = first_name user.last_name = last_name user.email = form_email user.username = MakeUsername() # This should be removed once messaging the client is brought in house user.skeleton_user = True # Set to stop concierge clients getting emails about rate tracker. user.save() profile = Profile() profile.user = user profile.telephone = number profile.skeleton_user = False profile.filled_in_name = True profile.is_synched = False profile.save() context[ 'message'] = "%s has now been changed to a concierge client, this will be reflected in Salesforce over the next 2-3mins" % user.email record_referral_signup(request, user, True, 'concierge_client', third_party=True) else: context['form'] = form else: context['form'] = ConciergeForm() return render_to_response(template_file, context_instance=context)
def tpo_signup(request, balance=None): if balance == '1': form = IFAForm(initial={'signup_amount': '£250,000 - £1million'}) elif balance == '2': form = IFAForm(initial={'signup_amount': '£1million - £5million'}) elif balance == '3': form = IFAForm(initial={'signup_amount': '£5million +'}) else: form = IFAForm() if request.method == "POST": form = IFAForm(request.POST) if form.is_valid(): form.save() if 'referer' in request.session: referer = Referrer.objects.get(pk=request.session['referer']).name else: referer = '(Direct)' analytics.delay('event', 'TPO', 'Signup', referer) user, user_created, record_stats = create_stage_one_profile(request=request, email=form.cleaned_data.get('email'), source='tpo_signup', send_activation=False, login_user=False) from common.tasks import update_subscription_on_email_service update_subscription_on_email_service.delay(user.email, interest_group=u'TPO Referral') text_email = get_template('ifa/ifa_signup_email.txt') guide_email = get_template('ifa/ifa_guide_email.txt') html_guide_email = get_template('ifa/ifa_guide_email.html') client_details = {'name': form.cleaned_data.get('name'), 'last_name': form.cleaned_data.get('last_name'), 'email': form.cleaned_data.get('email'), 'signup_amount': form.cleaned_data.get('signup_amount'), 'postcode': form.cleaned_data.get('postcode'), 'telephone': form.cleaned_data.get('telephone')} c = Context(client_details) text_content = text_email.render(c) guide_content = guide_email.render(c) html_guide_content = html_guide_email.render(c) subject, from_email = "New IFA Enquiry", "*****@*****.**" to_email = ["*****@*****.**"] AdviserQueue.add_to_queue(client_details['email'], client_details['name'], u'.', u'IFA Signup (TPO) - {value}'.format(value=client_details['signup_amount']), telephone_number=client_details['telephone']) msg = EmailMultiAlternatives(subject, text_content, from_email, to_email) msg.send() subject, from_email = "Your IFA Guide", "*****@*****.**" msg = EmailMultiAlternatives(subject, guide_content, from_email, [c['email']]) msg.attach_alternative(html_guide_content, "text/html") guide_path = os.path.join(settings.STATIC_ROOT, 'doc', 'ifa', '9_steps_to_choosing_an_independent_financial_adviser.pdf') msg.attach_file(guide_path) msg.send() record_referral_signup(request, user, user_created, 'tpo_referral') return redirect('tpo_thankyou') else: messages.error(request, 'Your input contained errors, or you have already enquired about The Private Office') return render(request, 'ifa/tpo_signup_alt.html', { 'form': form })
def tpo_signup(request, balance=None): if balance == '1': form = IFAForm(initial={'signup_amount': '£250,000 - £1million'}) elif balance == '2': form = IFAForm(initial={'signup_amount': '£1million - £5million'}) elif balance == '3': form = IFAForm(initial={'signup_amount': '£5million +'}) else: form = IFAForm() if request.method == "POST": form = IFAForm(request.POST) if form.is_valid(): form.save() if 'referer' in request.session: referer = Referrer.objects.get( pk=request.session['referer']).name else: referer = '(Direct)' analytics.delay('event', 'TPO', 'Signup', referer) user, user_created, record_stats = create_stage_one_profile( request=request, email=form.cleaned_data.get('email'), source='tpo_signup', send_activation=False, login_user=False) from common.tasks import update_subscription_on_email_service update_subscription_on_email_service.delay( user.email, interest_group=u'TPO Referral') text_email = get_template('ifa/ifa_signup_email.txt') guide_email = get_template('ifa/ifa_guide_email.txt') html_guide_email = get_template('ifa/ifa_guide_email.html') client_details = { 'name': form.cleaned_data.get('name'), 'last_name': form.cleaned_data.get('last_name'), 'email': form.cleaned_data.get('email'), 'signup_amount': form.cleaned_data.get('signup_amount'), 'postcode': form.cleaned_data.get('postcode'), 'telephone': form.cleaned_data.get('telephone') } c = Context(client_details) text_content = text_email.render(c) guide_content = guide_email.render(c) html_guide_content = html_guide_email.render(c) subject, from_email = "New IFA Enquiry", "*****@*****.**" to_email = ["*****@*****.**"] AdviserQueue.add_to_queue( client_details['email'], client_details['name'], u'.', u'IFA Signup (TPO) - {value}'.format( value=client_details['signup_amount']), telephone_number=client_details['telephone']) msg = EmailMultiAlternatives(subject, text_content, from_email, to_email) msg.send() subject, from_email = "Your IFA Guide", "*****@*****.**" msg = EmailMultiAlternatives(subject, guide_content, from_email, [c['email']]) msg.attach_alternative(html_guide_content, "text/html") guide_path = os.path.join( settings.STATIC_ROOT, 'doc', 'ifa', '9_steps_to_choosing_an_independent_financial_adviser.pdf') msg.attach_file(guide_path) msg.send() record_referral_signup(request, user, user_created, 'tpo_referral') return redirect('tpo_thankyou') else: messages.error( request, 'Your input contained errors, or you have already enquired about The Private Office' ) return render(request, 'ifa/tpo_signup_alt.html', {'form': form})
def create_concierge_client( request, template_file="administration/concierge_creation/index.html"): context = RequestContext(request) if request.method == "POST": form = ConciergeForm(request.POST) if form.is_valid(): form_email = form.cleaned_data.get('email') first_name = form.cleaned_data.get('first_name') last_name = form.cleaned_data.get('last_name') number = form.cleaned_data.get('number') try: user = User.objects.get(email__iexact=form_email) try: profile = user.profile except Profile.DoesNotExist: profile = Profile(user=user) profile.save() except Profile.MultipleObjectsReturned: profiles = Profile.objects.filter(user=user) profile = profiles[0] user.first_name = first_name user.last_name = last_name user.is_active = True user.save() profile.telephone = number profile.is_synched = False profile.skeleton_user = False profile.filled_in_name = True profile.save() try: campaign_signup = CampaignsSignup.objects.get( email__iexact=form_email) except CampaignsSignup.DoesNotExist: campaign_signup = CampaignsSignup(email=form_email) campaign_signup.name = " ".join([first_name, last_name]) campaign_signup.telephone = number campaign_signup.is_client = True campaign_signup.is_synched = False campaign_signup.save() except User.DoesNotExist: try: campaign_signup = CampaignsSignup.objects.get( email__iexact=form_email) except CampaignsSignup.DoesNotExist: campaign_signup = CampaignsSignup() campaign_signup.email = form_email campaign_signup.name = " ".join([first_name, last_name]) campaign_signup.telephone = number campaign_signup.is_client = True campaign_signup.is_synched = False campaign_signup.save() user = User() user.is_active = True user.first_name = first_name user.last_name = last_name user.email = form_email user.username = MakeUsername() # This should be removed once messaging the client is brought in house user.skeleton_user = True # Set to stop concierge clients getting emails about rate tracker. user.save() profile = Profile() profile.user = user profile.telephone = number profile.skeleton_user = False profile.filled_in_name = True profile.is_synched = False profile.save() context[ 'message'] = "%s has now been changed to a concierge client, this will be reflected in Salesforce over the next 2-3mins" % user.email record_referral_signup(request, user, True, 'concierge_client', third_party=True) else: context['form'] = form else: context['form'] = ConciergeForm() return render_to_response(template_file, context_instance=context)
def create_stage_one_profile(request, email, source, send_activation=True, login_user=True, use_site_framework=True): user_created = False record_stats = False try: user = User.objects.get(email__iexact=email) except User.MultipleObjectsReturned: user = User.objects.filter(email__iexact=email).earliest('date_joined') # Found more than one account with this email, use the first one. except User.DoesNotExist: password = User.objects.make_random_password(50) # make a 50 char password for temporary use site = get_current_site(request) username = MakeUsername() user = RegistrationProfile.objects.create_inactive_user(site=site, send_email=send_activation, request=request, username=username, password=password, email=email) user_created = True try: profile = user.profile except Profile.DoesNotExist: profile = Profile(user=user) profile.save() except Profile.MultipleObjectsReturned: profiles = Profile.objects.filter(user=user) profile = profiles.earliest() if profile.skeleton_user: if request is not None: profile.ip_address = get_client_ip(request) else: profile.ip_address = '127.0.0.1' profile.save() elif send_activation and not user.is_active and not user_created: return redirect('resend_activation') elif login_user and user.is_active is True: return redirect('auth_login') Stage1Profile(user, request, source) if not email.endswith('@local'): record_referral_signup(request, user, user_created, 'signup') statsd_client = StatsDClient().get_counter_client( client_name='user.profile.created' ) statsd_client += 1 statsd_client = StatsDClient().get_counter_client( client_name='user.profile.created.{source}'.format( source=source ) ) statsd_client += 1 statsd_client = StatsDClient().get_counter_client( client_name='user.profile.created.{source}.{path}'.format( source=source, path=request.path ) ) statsd_client += 1 record_stats = True return user, user_created, record_stats