-
Notifications
You must be signed in to change notification settings - Fork 0
/
leads.py
716 lines (618 loc) · 21.1 KB
/
leads.py
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
import os
import webapp2
import jinja2
from google.appengine.ext import ndb
from google.appengine.api import users
import logging
import datetime
template_env = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.getcwd()))
from Employee import EmploymentDetails
class Leads(ndb.Expando):
strEmployeeCode = ndb.StringProperty()
strLeadDate = ndb.DateProperty(auto_now_add=True)
strLeadNotes = ndb.StringProperty()
strInterestedinFuneralCover = ndb.BooleanProperty(default=False)
strInterestedinFuneralService = ndb.BooleanProperty(default=False)
strConversionDate = ndb.DateProperty()
strConvertedBy = ndb.StringProperty() # Employee Code of the Employee who made the conversion
strTitle = ndb.StringProperty()
strFullNames = ndb.StringProperty()
strSurname = ndb.StringProperty()
strIDNumber = ndb.StringProperty()
strDateOfBirth = ndb.StringProperty()
strResidential = ndb.StringProperty()
strTownCity = ndb.StringProperty()
strCountry = ndb.StringProperty()
strProvince = ndb.StringProperty()
strPostalCode = ndb.StringProperty()
strTel = ndb.StringProperty()
strCell = ndb.StringProperty()
strEmail = ndb.StringProperty()
strLeadInterests = ndb.StringProperty() # Funeral Cover or Funeral Service or Other
def readEmployeeCode(self):
try:
strTemp = str(self.strEmployeeCode)
strTemp = strTemp.strip()
if not (strTemp == None):
return strTemp
else:
return ""
except:
return ""
def writeEmployeeCode(self,strinput):
try:
strinput = str(strinput)
strinput = strinput.strip()
if not (strinput == None):
self.strEmployeeCode = strinput
return True
else:
return False
except:
return False
def readLeadDate(self):
try:
return str(self.strLeadDate)
except:
return ""
def readLeadNotes(self):
try:
strTemp = str(self.strLeadNotes)
return strTemp
except:
return ""
def writeLeadNotes(self,strinput):
try:
strinput = str(strinput)
strinput = strinput.strip()
if not(strinput == None):
self.strLeadNotes = strinput
return True
else:
return False
except:
return False
def leadInterestedinFuneralCover(self):
try:
self.strInterestedinFuneralCover = True
return True
except:
return False
def leadInterestedinFuneralService(self):
try:
self.strInterestedinFuneralService = True
return True
except:
return False
def readIfInterestedInFuneralCover(self):
try:
if self.strInterestedinFuneralCover:
return "Yes"
else:
return "No"
except:
return "No"
def readIfInterestedInFuneralService(self):
try:
if self.strInterestedinFuneralService:
return "Yes"
else:
return "No"
except:
return "No"
def readConversionDate(self):
try:
strTemp = str(self.strConversionDate)
return strTemp
except:
return ""
def setConversionDate(self,strinput):
try:
thisDate = datetime.datetime.now()
thisDate = thisDate.date()
self.strConversionDate = thisDate
return True
except:
return True
def readConvertedBy(self):
try:
strTemp = str(self.strConvertedBy)
return strTemp
except:
return ""
def writeConvertedBy(self,strinput):
try:
strinput = str(strinput)
strinput = strinput.strip()
if not(strinput == None):
self.strConvertedBy = strinput
return True
else:
return False
except:
return False
def readTitle(self):
try:
strtemp = str(self.strTitle)
strtemp = strtemp.strip()
if not (strtemp == None):
return strtemp
else:
return ""
except:
return ""
def writeTitle(self, strinput):
try:
strinput = str(strinput)
strinput = strinput.strip()
if not (strinput == None):
self.strTitle = strinput
return True
else:
return False
except:
return False
def writeNames(self, strinput):
try:
strinput = str(strinput)
strinput = strinput.strip()
if not (strinput == None):
self.strFullNames = strinput
return True
else:
return False
except:
return False
def readNames(self):
try:
strTemp = str(self.strFullNames)
strTemp = strTemp.strip()
if not (strTemp == None):
return strTemp
else:
return ""
except:
return ""
def readSurname(self):
try:
strTemp = str(self.strSurname)
strTemp = strTemp.strip()
if not (strTemp == None):
return strTemp
else:
return ""
except:
return ""
def writeSurname(self, strinput):
try:
strinput = str(strinput)
strinput = strinput.strip()
if not (strinput == None):
self.strSurname = strinput
return True
else:
return False
except:
return False
def readIDNumber(self):
try:
strTemp = str(self.strIDNumber)
if strTemp.isdigit():
return strTemp
else:
return ""
except:
return ""
def writeIDNumber(self, strinput):
try:
strinput = str(strinput)
if strinput.isdigit():
self.strIDNumber = strinput
return True
else:
return False
except:
return False
def readDateOfBirth(self):
try:
strtemp = str(self.strDateOfBirth)
return strtemp
except:
return ""
def writeDateOfBirth(self, strinput):
"""
format yyyy-mm-dd
"""
try:
strinput = str(strinput)
Datefields = strinput.split("-")
if len(Datefields) == 3:
tempDate = datetime.date(year=int(Datefields[0]), month=int(Datefields[1]), day=int(Datefields[2]))
self.strDateOfBirth = tempDate
return True
else:
return False
except:
return False
def readResAddress(self):
try:
strTemp = str(self.strResidential)
if not (strTemp == None):
return strTemp
else:
return ""
except:
return ""
def writeResAddress(self, strinput):
try:
strinput = str(strinput)
if not (strinput == None):
self.strResidential = strinput
return True
else:
return False
except:
return False
def readCityTown(self):
try:
strTemp = str(self.strTownCity)
strTemp = strTemp.strip()
if not (strTemp == None):
return strTemp
else:
return ""
except:
return ""
def writeCityTown(self, strinput):
try:
strinput = str(strinput)
strinput = strinput.strip()
if not (strinput == None):
self.strTownCity = strinput
return True
else:
return False
except:
return False
def readCountry(self):
try:
strTemp = str(self.strCountry)
strTemp = strTemp.strip()
if not (strTemp == None):
return strTemp
else:
return ""
except:
return ""
def writeCountry(self, strinput):
try:
strinput = str(strinput)
strinput = strinput.strip()
if not (strinput == None):
self.strCountry = strinput
return True
else:
return False
except:
return False
def readProvince(self):
try:
strTemp = str(self.strProvince)
strTemp = strTemp.strip()
if not (strTemp == None):
return strTemp
else:
return ""
except:
return ""
def writeProvince(self, strinput):
try:
strinput = str(strinput)
strinput = strinput.strip()
if not (strinput == None):
self.strProvince = strinput
return True
else:
return False
except:
return False
def readPostalCode(self):
try:
strTemp = str(self.strPostalCode)
strTemp = strTemp.strip()
if not (strTemp == None):
return strTemp
else:
return ""
except:
return ""
def writePostalCode(self, strinput):
try:
strinput = str(strinput)
strinput = strinput.strip()
if not (strinput == None):
self.strPostalCode = strinput
return True
else:
return False
except:
return False
def readCell(self):
try:
strTemp = str(self.strCell)
strTemp = strTemp.strip()
if not (strTemp == None):
return strTemp
else:
return ""
except:
return ""
def writeCell(self, strinput):
try:
strinput = str(strinput)
strinput = strinput.strip()
if not (strinput == None):
self.strCell = strinput
return True
else:
return False
except:
return False
def readTell(self):
try:
strTemp = str(self.strTel)
strTemp = strTemp.strip()
if not (strTemp == None):
return strTemp
else:
return ""
except:
return ""
def writeTel(self, strinput):
try:
strinput = str(strinput)
strinput = strinput.strip()
if not (strinput == None):
self.strTel = strinput
return True
else:
return False
except:
return False
def readEmail(self):
try:
strTemp = str(self.strEmail)
strTemp = strTemp.strip()
if not (strTemp == None):
return strTemp
else:
return ""
except:
return ""
def writeEmail(self, strinput):
try:
strinput = str(strinput)
strinput = strinput.strip()
if not (strinput == None):
self.strEmail = strinput
return True
else:
return False
except:
return False
def readLeadInterests(self):
try:
strTemp =str(self.strLeadInterests)
return strTemp
except:
return ""
def writeLeadInterests(self,strinput):
try:
strinput = str(strinput)
strinput = strinput.strip().lower()
if strinput == "funeral service":
self.leadInterestedinFuneralService()
self.strLeadInterests = strinput
return True
elif strinput == "funeral cover":
self.leadInterestedinFuneralCover()
self.strLeadInterests = strinput
return True
elif strinput == "other":
self.strLeadInterests = "other"
return True
else:
return False
except:
return False
class LeadResponses(ndb.Expando):
strReference = ndb.StringProperty() # Reference of the User Using the System at the time
strEmployeeName = ndb.StringProperty()
strEmployeeSurname = ndb.StringProperty()
strEmployeeCode = ndb.StringProperty()
strIDNumber = ndb.StringProperty() # ID Number of the Lead
strResponse = ndb.StringProperty()
strStatus = ndb.StringProperty()
strDateTimeResponse = ndb.DateTimeProperty(auto_now_add=True)
strNextSchedule = ndb.DateTimeProperty()
def readReference(self):
try:
strTemp = str(self.strReference)
return strTemp
except:
return None
def writeReference(self,strinput):
try:
strinput = str(strinput)
if not(strinput == None):
self.strReference = strinput
return True
else:
return False
except:
return False
def writeIDNumber(self,strinput):
try:
strinput = str(strinput)
if strinput.isdigit() and (len(strinput) == 13):
self.strIDNumber = strinput
return True
else:
return False
except:
return False
def writeResponses(self,strinput):
try:
strinput = str(strinput)
if not(strinput == None):
self.strResponse = strinput
return True
else:
return False
except:
return False
def writeStatus(self,strinput):
try:
strinput = str(strinput)
strinput = strinput.lower()
if (strinput == "calllater") or (strinput == "unreachable") or (strinput == "dontcall"):
self.strStatus = strinput
return True
else:
return False
except:
return False
def writeNextSchedule(self,strinput):
try:
if not(strinput == None):
self.strNextSchedule = strinput
return True
else:
return False
except:
return False
class CaptureLeadshandler(webapp2.RequestHandler):
def get(self):
Guser = users.get_current_user()
if Guser:
vstrTitle = self.request.get('vstrTitle')
logging.info(vstrTitle)
vstrSurname = self.request.get('vstrSurname')
vstrFullnames = self.request.get('vstrFullnames')
vstrIDNumber = self.request.get('vstrIDNumber')
vstrDateofBirth = self.request.get('vstrDateofBirth')
vstrResidential = self.request.get('vstrResidential')
vstrTownCity = self.request.get('vstrTownCity')
logging.info(vstrTownCity)
vstrCountry = self.request.get('vstrCountry')
vstrProvince = self.request.get('vstrProvince')
vstrPostalCode = self.request.get('vstrPostalCode')
vstrTel = self.request.get('vstrTel')
vstrCell = self.request.get('vstrCell')
logging.info(vstrCell)
vstrEmail = self.request.get('vstrEmail')
vstrLeadNotes = self.request.get('vstrLeadNotes')
vstrInterest = self.request.get('vstrInterest')
findRequests = Leads.query(Leads.strIDNumber == vstrIDNumber)
DuplicateLists = findRequests.fetch()
if len(DuplicateLists) > 0:
self.response.write("Lead has already been Captured")
else:
try:
thisLead = Leads()
logging.info("We have SUCCESFULLY CREATED LEAD CAPTURE CLASS")
thisLead.writeTitle(strinput=vstrTitle)
logging.info("Title Written")
thisLead.writeSurname(strinput=vstrSurname)
thisLead.writeNames(strinput=vstrFullnames)
thisLead.writeIDNumber(strinput=vstrIDNumber)
thisLead.writeDateOfBirth(strinput=vstrDateofBirth)
thisLead.writeResAddress(strinput=vstrResidential)
thisLead.writeCityTown(strinput=vstrTownCity)
thisLead.writeCountry(strinput=vstrCountry)
logging.info("Till Country")
thisLead.writeProvince(strinput=vstrProvince)
thisLead.writePostalCode(strinput=vstrPostalCode)
thisLead.writeTel(strinput=vstrTel)
thisLead.writeCell(strinput=vstrCell)
thisLead.writeEmail(strinput=vstrEmail)
logging.info("Till Email")
thisLead.writeLeadNotes(strinput=vstrLeadNotes)
thisLead.writeLeadInterests(strinput=vstrInterest)
findRequests = EmploymentDetails.query(EmploymentDetails.strReference == Guser.user_id())
EmployeeList = findRequests.fetch()
if len(EmployeeList) > 0:
Employee = EmployeeList[0]
thisLead.writeEmployeeCode(strinput=Employee.strEmployeeCode)
thisLead.put()
self.response.write("Lead Capture Succesfully")
else:
self.response.write("Not Authorised to Capture Lead")
except:
self.response.write("An Error Occured Capturing Lead")
else:
self.response.write("You are presently not logged in")
class SubLeadHandler(webapp2.RequestHandler):
def get(self):
URL = self.request.url
URL = str(URL)
vstrRefreshButtonURL = URL
URLlist = URL.split("/")
strIDNumber = URLlist[len(URLlist) - 1]
findRequest = Leads.query(Leads.strIDNumber == strIDNumber)
LeadList = findRequest.fetch()
thisLead = Leads()
if len(LeadList) > 0:
thisLead = LeadList[0]
findRequest = Leads.query()
LeadList = findRequest.fetch()
findRequest = LeadResponses.query(LeadResponses.strIDNumber == strIDNumber)
LeadResponseList = findRequest.fetch()
findRequest = EmploymentDetails.query(EmploymentDetails.strEmployeeCode == thisLead.strEmployeeCode)
EmployeeList = findRequest.fetch()
Employee = EmploymentDetails()
if len(EmployeeList) > 0:
Employee = EmployeeList[0]
template = template_env.get_template('templates/dynamic/leads/sublead.html')
context = {'thisLead':thisLead,'LeadList':LeadList,'vstrRefreshButtonURL': vstrRefreshButtonURL,'Employee':Employee,
'LeadResponses': LeadResponseList}
self.response.write(template.render(context))
class LeadResponseHandler(webapp2.RequestHandler):
def get(self):
try:
Guser = users.get_current_user()
if Guser:
vstrLeadResponse = self.request.get('vstrLeadResponse')
vstrFollowUpStatus = self.request.get('vstrFollowUpStatus')
vstrNextScheduleCall = self.request.get('vstrNextScheduleCall')
vstrLeadIDNumber = self.request.get('vstrLeadIDNumber')
thisLeadResponse = LeadResponses()
thisLeadResponse.writeReference(strinput=Guser.user_id())
findRequest = EmploymentDetails.query(EmploymentDetails.strReference == Guser.user_id())
EmployeeList = findRequest.fetch()
Employee = EmploymentDetails()
if len(EmployeeList) > 0:
Employee = EmployeeList[0]
thisLeadResponse.strEmployeeName = Employee.strFullNames
thisLeadResponse.strEmployeeSurname = Employee.strSurname
thisLeadResponse.strEmployeeCode = Employee.strEmployeeCode
thisLeadResponse.writeIDNumber(strinput=vstrLeadIDNumber)
thisLeadResponse.writeResponses(strinput=vstrLeadResponse)
thisLeadResponse.writeStatus(strinput=vstrFollowUpStatus)
thisLeadResponse.writeNextSchedule(strinput=vstrNextScheduleCall)
thisLeadResponse.put()
self.response.write("Succesfully saved a lead Response")
else:
self.response.write("Failure Saving Lead Response")
except:
self.response.write("Fatal Error Saving Lead Response")
class LeadSendEmailHandler(webapp2.RequestHandler):
def get(self):
pass
app = webapp2.WSGIApplication([
('/leads/capture', CaptureLeadshandler),
('/leads/sublead/.*',SubLeadHandler),
('/leads/response', LeadResponseHandler),
('/leads/sendemail', LeadSendEmailHandler)
], debug=True)