-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathviews.py
More file actions
300 lines (250 loc) · 11.9 KB
/
views.py
File metadata and controls
300 lines (250 loc) · 11.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
import time
from datetime import timedelta
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseRedirect
from django.shortcuts import render, redirect
from django.urls import reverse
from django.utils import timezone
from django_pagarme import facade
from pythonpro.checkout import facade as checkout_facade
from pythonpro.checkout import forms as checkout_forms
from pythonpro.checkout.forms import WaitingForm
from pythonpro.core.facade import is_webdev
from pythonpro.domain import user_domain
def _redirect_to_bootcamp_lp(request):
if checkout_facade.has_50_percent_discount():
path_name = 'checkout:bootcamp_lp_d1'
elif checkout_facade.has_35_percent_discount():
path_name = 'checkout:bootcamp_lp_d2'
else:
path_name = 'checkout:bootcamp_lp_d3'
if is_webdev(request.user):
path_name = f'{path_name}_webdev'
if not checkout_facade.is_launch_open():
path_name = 'checkout:bootcamp_lp'
return HttpResponseRedirect(reverse(path_name) + '?' + request.META['QUERY_STRING'])
def bootcamp_lp(request):
if request.method == 'POST':
form = WaitingForm(request.POST)
if form.is_valid():
source = request.GET.get('utm_source', default='unknown')
data = form.cleaned_data
session_id = request.session.session_key
if request.user.is_authenticated:
user_domain.subscribe_to_waiting_list(session_id, request.user, data['phone'], source)
else:
user_domain.subscribe_anonymous_user_to_waiting_list(
session_id, data['email'], data['first_name'], data['phone'], source
)
return redirect(reverse('checkout:waiting_list_ty'))
return render(request, 'checkout/bootcamp_lp_subscription_closed.html', {'form': form})
if not checkout_facade.is_launch_open():
if request.user.is_authenticated:
user_domain.visit_member_landing_page(request.user, source=request.GET.get('utm_source', default='unknown'))
form = checkout_forms.WaitingForm()
return render(request, 'checkout/bootcamp_lp_subscription_closed.html', {'form': form})
return _redirect_to_bootcamp_lp(request)
def _no_wevdev_discount(request, discount_slug, promotion_end_date,
template_name='checkout/bootcamp_lp_subscription_open.html'):
if request.user.is_authenticated:
user_domain.visit_member_landing_page(request.user, source=request.GET.get('utm_source', default='unknown'))
form = facade.ContactForm()
payment_item_config = facade.find_payment_item_config(discount_slug)
no_discount_item_config = facade.find_payment_item_config('bootcamp')
first_day_discount = no_discount_item_config.price - payment_item_config.price
client_discount = 0
has_first_day_discount = True
has_client_discount = False
return _render_bootcamp_lp(client_discount, first_day_discount, form, has_client_discount, has_first_day_discount,
no_discount_item_config, payment_item_config, promotion_end_date, request, template_name)
def _render_bootcamp_lp(client_discount, first_day_discount, form, has_client_discount, has_first_day_discount,
no_discount_item_config, payment_item_config, promotion_end_date, request,
template_name='checkout/bootcamp_lp_subscription_open.html'):
# Seconds to milliseconds https://stackoverflow.com/questions/5022447/converting-date-from-python-to-javascript
promotion_end_date_milliseconds = int(time.mktime(promotion_end_date.timetuple())) * 1000
context = {
'launch_datetime_finish': checkout_facade.launch_datetime_finish,
'discount_datetime_limit': promotion_end_date,
'payment_item_config': payment_item_config,
'contact_form': form,
'has_first_day_discount': has_first_day_discount,
'has_client_discount': has_client_discount,
'client_discount': client_discount,
'first_day_discount': first_day_discount,
'promotion_end_date': promotion_end_date,
'promotion_end_date_milliseconds': promotion_end_date_milliseconds,
'no_discount_item_config': no_discount_item_config,
}
return render(request, template_name, context)
def bootcamp_lp_d1(request):
user = request.user
is_debug = bool(request.GET.get('debug', False))
if not is_debug and ((not checkout_facade.has_50_percent_discount()) or is_webdev(user)):
return _redirect_to_bootcamp_lp(request)
return _no_wevdev_discount(
request,
'bootcamp-50-discount',
checkout_facade.discount_50_percent_datetime_limit,
'checkout/bootcamp_lp_d1.html'
)
@login_required
def bootcamp_lp_d1_webdev(request):
user = request.user
is_debug = bool(request.GET.get('debug', False))
if not is_debug and not (checkout_facade.has_50_percent_discount() and is_webdev(user)):
return _redirect_to_bootcamp_lp(request)
client_discount_slug = 'bootcamp-webdev-50-discount'
first_day_discount_slug = 'bootcamp-50-discount'
promotion_end_date = checkout_facade.discount_50_percent_datetime_limit
return _render_with_webdev_and_first_day_discounts(
request,
client_discount_slug,
first_day_discount_slug,
promotion_end_date,
'checkout/bootcamp_lp_d1.html'
)
def bootcamp_lp_d2(request):
user = request.user
is_debug = bool(request.GET.get('debug', False))
if not is_debug and (not checkout_facade.has_35_percent_discount() or is_webdev(user)):
return _redirect_to_bootcamp_lp(request)
return _no_wevdev_discount(
request,
'bootcamp-35-discount',
checkout_facade.discount_35_percent_datetime_limit,
'checkout/bootcamp_lp_d2.html'
)
@login_required
def bootcamp_lp_d2_webdev(request):
user = request.user
is_debug = bool(request.GET.get('debug', False))
if not is_debug and not (checkout_facade.has_35_percent_discount() and is_webdev(user)):
return _redirect_to_bootcamp_lp(request)
client_discount_slug = 'bootcamp-webdev-35-discount'
first_day_discount_slug = 'bootcamp-35-discount'
promotion_end_date = checkout_facade.discount_35_percent_datetime_limit
return _render_with_webdev_and_first_day_discounts(
request,
client_discount_slug,
first_day_discount_slug,
promotion_end_date,
'checkout/bootcamp_lp_d2.html'
)
def bootcamp_lp_d3(request):
user = request.user
has_discount = checkout_facade.has_35_percent_discount() or checkout_facade.has_50_percent_discount() or is_webdev(
user)
is_debug = bool(request.GET.get('debug', False))
if not is_debug and ((not checkout_facade.is_launch_open()) or has_discount):
return _redirect_to_bootcamp_lp(request)
if request.user.is_authenticated:
user_domain.visit_member_landing_page(request.user, source=request.GET.get('utm_source', default='unknown'))
form = facade.ContactForm()
payment_item_config = no_discount_item_config = facade.find_payment_item_config('bootcamp')
first_day_discount = 0
client_discount = 0
has_first_day_discount = False
has_client_discount = False
promotion_end_date = checkout_facade.launch_datetime_finish
return _render_bootcamp_lp(
client_discount,
first_day_discount,
form,
has_client_discount,
has_first_day_discount,
no_discount_item_config,
payment_item_config,
promotion_end_date,
request,
'checkout/bootcamp_lp_d3.html'
)
@login_required
def bootcamp_lp_d3_webdev(request):
user = request.user
has_discount = checkout_facade.has_35_percent_discount() or checkout_facade.has_50_percent_discount()
is_debug = bool(request.GET.get('debug', False))
if not is_debug and (has_discount or not (checkout_facade.is_launch_open() and is_webdev(user))):
return _redirect_to_bootcamp_lp(request)
user_domain.visit_member_landing_page(request.user, source=request.GET.get('utm_source', default='unknown'))
has_client_discount = True
data = {'name': request.user.first_name, 'email': request.user.email}
form = facade.ContactForm(data)
has_first_day_discount = False
no_discount_item_config = facade.find_payment_item_config('bootcamp')
first_day_discount = 0
client_discount_item_config = facade.find_payment_item_config('bootcamp-webdev')
promotion_end_date = checkout_facade.launch_datetime_finish
payment_item_config = client_discount_item_config
client_discount = no_discount_item_config.price - client_discount_item_config.price - first_day_discount
return _render_bootcamp_lp(
client_discount,
first_day_discount,
form,
has_client_discount,
has_first_day_discount,
no_discount_item_config,
payment_item_config,
promotion_end_date,
request,
'checkout/bootcamp_lp_d3.html'
)
def waiting_list_ty(request):
return redirect("https://forms.gle/b2JxGZPvbBYsr5UKA")
@login_required
def webdev_landing_page_oto(request):
template_name = 'checkout/webdev_landing_page_oto.html'
return _webdev_landing_page_50_off(request, template_name)
@login_required
def webdev_landing_page_50_off(request):
template_name = 'checkout/webdev_landing_page_50_off.html'
return _webdev_landing_page_50_off(request, template_name, seconds_to_show_full_page=0)
def _webdev_landing_page_50_off(request, template_name, seconds_to_show_full_page=90):
payment_item_config = facade.find_payment_item_config('webdev-oto')
user = request.user
if user.is_authenticated:
data = {'name': user.first_name, 'email': user.email}
form = facade.ContactForm(data)
else:
form = facade.ContactForm()
countdown_limit = request.user.date_joined + timedelta(days=5)
is_promotion_expired = timezone.now() > countdown_limit
if request.GET.get('debug') is not None:
is_promotion_expired = False
ctx = {
'payment_item_config': payment_item_config,
'contact_form': form,
'countdown_limit': countdown_limit,
'is_promotion_expired': is_promotion_expired,
'seconds_to_show_full_page': seconds_to_show_full_page
}
return render(request, template_name, ctx)
def webdev_landing_page(request):
payment_item_config = facade.find_payment_item_config('webdev')
user = request.user
if user.is_authenticated:
data = {'name': user.first_name, 'email': user.email, 'phone': ''}
form = facade.ContactForm(data)
else:
form = facade.ContactForm()
ctx = {
'payment_item_config': payment_item_config,
'contact_form': form,
}
return render(request, 'checkout/webdev_landing_page.html', ctx)
def _render_with_webdev_and_first_day_discounts(
request, client_discount_slug, first_day_discount_slug, promotion_end_date,
template_name='checkout/bootcamp_lp_subscription_open.html'
):
user_domain.visit_member_landing_page(request.user, source=request.GET.get('utm_source', default='unknown'))
has_client_discount = True
data = {'name': request.user.first_name, 'email': request.user.email}
form = facade.ContactForm(data)
has_first_day_discount = True
no_discount_item_config = facade.find_payment_item_config('bootcamp')
first_day_discount_item_config = facade.find_payment_item_config(first_day_discount_slug)
first_day_discount = no_discount_item_config.price - first_day_discount_item_config.price
client_discount_item_config = facade.find_payment_item_config(client_discount_slug)
payment_item_config = client_discount_item_config
client_discount = no_discount_item_config.price - client_discount_item_config.price - first_day_discount
return _render_bootcamp_lp(client_discount, first_day_discount, form, has_client_discount, has_first_day_discount,
no_discount_item_config, payment_item_config, promotion_end_date, request, template_name)