22
33from django .conf import settings
44from django .shortcuts import redirect , render
5+ from django .utils .http import urlencode
56from django .views .static import serve
67from django .urls import reverse
78
89from pythonpro .absolute_uri import build_absolute_uri
10+ from pythonpro .cohorts import facade as cohorts_facade
911from pythonpro .cohorts .facade import find_most_recent_cohort
10- from pythonpro .domain import user_facade
12+ from pythonpro .domain import user_facade , membership_domain
1113from pythonpro .launch .forms import LeadForm
1214from pythonpro .email_marketing import facade as email_marketing_facade
1315from pythonpro .launch .facade import (
@@ -157,3 +159,58 @@ def onesignal_sdk_updater_worker(request):
157159 'js/spp/OneSignalSDUpdaterKWorker.js' ,
158160 document_root = os .path .join (settings .BASE_DIR , 'pythonpro' , 'core' , 'static' )
159161 )
162+
163+
164+ def member_landing_page (request ):
165+ template_open_launch = 'payments/meteoric_landing_page_open.html'
166+ template_closed_launch = 'payments/member_landing_page_subscription_closed.html'
167+ is_launch_open = settings .SUBSCRIPTIONS_OPEN or request .GET .get ('debug' )
168+ return _render_launch_page (is_launch_open , request , template_closed_launch , template_open_launch ,
169+ 'member_landing_page' )
170+
171+
172+
173+
174+ def _render_launch_page (is_launch_open , request , template_closed_launch , template_open_launch , redirect_path_name : str ):
175+ user = request .user
176+ if user .is_authenticated :
177+ user_facade .visit_member_landing_page (request .user , source = request .GET .get ('utm_source' , default = 'unknown' ))
178+ notification_url = reverse ('payments:membership_notification' , kwargs = {'user_id' : user .id })
179+ else :
180+ notification_url = reverse ('payments:membership_anonymous_notification' )
181+ if is_launch_open :
182+ template = template_open_launch
183+ discount = membership_domain .calculate_discount (user )
184+ discount_float = discount / 100
185+
186+ price = membership_domain .calculate_membership_price (user )
187+ price_float = price / 100
188+ full_price_float = price_float + discount_float
189+ price_installment = (price // 10 ) / 100
190+ full_price_installment = full_price_float // 10
191+ login_url = reverse ('two_factor:login' )
192+ redirect_path = reverse (redirect_path_name )
193+ qs = urlencode ({'utm_source' : request .GET .get ('utm_source' , 'unknown' )})
194+ redirect_url = f'{ redirect_path } ?{ qs } '
195+ qs = urlencode ({'next' : redirect_url })
196+ login_url = f'{ login_url } ?{ qs } '
197+ return render (
198+ request ,
199+ template ,
200+ {
201+ 'PAGARME_CRYPTO_KEY' : settings .PAGARME_CRYPTO_KEY ,
202+ 'price' : price ,
203+ 'price_float' : price_float ,
204+ 'price_installment' : price_installment ,
205+ 'notification_url' : request .build_absolute_uri (notification_url ),
206+ 'cohort' : cohorts_facade .find_most_recent_cohort (),
207+ 'has_discount' : discount_float > 0 ,
208+ 'discount_float' : discount_float ,
209+ 'full_price_installment' : full_price_installment ,
210+ 'full_price_float' : full_price_float ,
211+ 'login_url' : login_url ,
212+ }
213+ )
214+ else :
215+ template = template_closed_launch
216+ return render (request , template , {})
0 commit comments