-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrackingapp.py
More file actions
executable file
·2787 lines (2091 loc) · 71.5 KB
/
trackingapp.py
File metadata and controls
executable file
·2787 lines (2091 loc) · 71.5 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
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
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import datetime
import logging
import webapp2
from google.appengine.ext import db
from google.appengine.api import users
from google.appengine.api import memcache
import re
import os
from google.appengine.ext.webapp import template
from google.appengine.api import mail
from datetime import datetime, timedelta, tzinfo
import sys
class Person(db.Model):
#Models an individual event entry with an name, location, starting date, ending date
firstName = db.StringProperty()
lastName = db.StringProperty()
authcate = db.StringProperty()
studentID = db.IntegerProperty()
email = db.StringProperty()
address= db.StringProperty()
campus = db.IntegerProperty()
phoneNumber = db.StringProperty()
personType = db.IntegerProperty()
#PersonTypes
# 1: Student
# 2: Staff
# 3: Non-Student
#Campus Numbers
# 1: Clayton
# 2: Caulfield
# 3: Peninsula
# 4: Parkville
# 5: Gippsland
# 6: Berwick
# 7: India
# 8: South Africa
# 9: Italy
# 10: Sunway, Malaysia
# 11: China
class PersonClubStatus(db.Model):
studentID = db.IntegerProperty()
year = db.IntegerProperty()
clubKey = db.IntegerProperty()
joiningDate = db.DateTimeProperty(auto_now_add=True)
memberType = db.IntegerProperty()
addedBy = db.StringProperty()
#Member Type
# 0: Ordinary
# 1: Associate
class Club(db.Model):
name = db.StringProperty()
primaryKey = db.IntegerProperty()
class PersonEventStatus(db.Model):
studentID = db.IntegerProperty()
eventKey = db.IntegerProperty()
creationDate = db.DateTimeProperty(auto_now_add=True)
addedBy = db.StringProperty()
class Event(db.Model):
name = db.StringProperty()
primaryKey = db.IntegerProperty()
clubKey = db.IntegerProperty()
date = db.StringProperty()
clubName = db.StringProperty()
location = db.StringProperty()
creationDate = db.DateTimeProperty(auto_now_add=True)
class userPermissions(db.Model):
email = db.StringProperty()
clubKey = db.IntegerProperty()
permissionLevel = db.IntegerProperty()
name = db.StringProperty()
#permission levels
#2 = admin
#1 = club personel
class ClubCounter(db.Model):
year = db.IntegerProperty()
clubKey = db.IntegerProperty()
numberOfMembers = db.IntegerProperty()
numberOfMSAMembers = db.IntegerProperty()
def person_key(person_name=None):
return db.Key.from_path('Person', person_name or 'default_person')
def personClubStatus_key(personClubStatus_name=None,year = None, clubKey = None):
return db.Key.from_path('PersonClubStatus', (str(personClubStatus_name) + str(year) + str(clubKey)) or 'personClubStatus')
def club_key(club_name=None):
return db.Key.from_path('Club', club_name or 'club')
def personEventStatus_key(personEventStatus_name=None, eventKey = None):
return db.Key.from_path('PersonEventStatus', (str(personEventStatus_name) + str(eventKey)) or 'personEventStatus')
def event_key(event_name=None):
return db.Key.from_path('Event', event_name or 'event')
def userPermissions_key(userPermissions_name=None,clubKey=None):
return db.Key.from_path('userPermissions', (str(userPermissions_name) + str(clubKey)) or 'userPermissions')
def ClubCounter_key(clubKey=None,year=None):
return db.Key.from_path('ClubCounter', (str(clubKey) + str(year)) or 'ClubCounter')
#Security: Unsecured. Accessible to all
class registerPerson(webapp2.RequestHandler):
def get(self):
error = self.request.get('error')
if error == '0':
error = 'Success!'
elif error == '1':
error = 'Looks like you missed something'
elif error == '2':
error = 'Student ID needs to be a number'
elif error == '3':
error = 'Your email looks invalid. Have you tried to use your monash one?'
elif error == '4':
error = 'Student ID already found'
elif error == '6':
error = 'Error with student ID'
elif error == '7':
error = 'You need to accept the Terms and Conditions'
template_values = {
'error': error
}
path = os.path.join(os.path.dirname(__file__), 'register.html')
self.response.out.write(template.render(path, template_values))
#Security: Unsecured. Accessible to all
class registerPerson_Submit(webapp2.RequestHandler):
def post(self):
firstName = self.request.get('firstname')
lastName = self.request.get('lastname')
authcate = self.request.get('authcate')
email = self.request.get('email')
phoneNumber = self.request.get('phonenumber')
campus = self.request.get('campus')
address = self.request.get('address')
termsAndConditions = self.request.get('TermsAndConditions')
personType = self.request.get('personType')
personType = int(personType)
studentID = ''
error = '';
if error == '':
try:
studentID = self.request.get('studentid')
stringLength = studentID.__len__()
studentID = str(securityManager.trimStudentID(studentID))
if stringLength > 7:
studentID = int(studentID[:8])
if studentID:
match = False
personToMatch = db.get(person_key(studentID))
if personToMatch is None:
if personType != 3:
persons = db.GqlQuery("SELECT * "
"FROM Person "
"WHERE authcate = :1 LIMIT 1", authcate)
personToMatch = persons.get()
if personToMatch is not None:
error = '4'
else:
error = '4'
else:
error = '1'
else:
error = '6'
except:
error = '2'
if error == '':
person = Person(key=person_key(studentID))
person.studentID = studentID
else:
self.redirect('/register?error=%s' % error)
return None
if firstName:
person.firstName = firstName
else:
error = '1'
if lastName:
person.lastName = lastName
else:
error = '1'
if authcate:
person.authcate = authcate.lower()
else:
if personType != 3:
error = '1'
if termsAndConditions != 'YES':
error = '7'
if campus:
person.campus = int(campus)
else:
error = '1'
if address:
person.address = address
if email:
if re.match(r"[^@]+@[^@]+\.[^@]+", email):
person.email = email.lower()
else:
error = '3'
if phoneNumber:
person.phoneNumber = phoneNumber
if personType:
person.personType = personType
else:
error = '1'
if error == '':
error = "0"
person.put();
self.redirect('/register?error=%s' % error)
#Security: Restricted to only admins.
class addClub(webapp2.RequestHandler):
def get(self):
if users.is_current_user_admin() == False:
self.redirect('/')
error = self.request.get('error')
if error == '0':
error = 'Success!'
elif error == '1':
error = 'Looks like you missed something'
elif error == '3':
error = 'Email address invalid'
template_values = {
'error': error
}
path = os.path.join(os.path.dirname(__file__), 'addClub.html')
self.response.out.write(template.render(path, template_values))
#Security: Restricted to only admins.
class addClub_Submit(webapp2.RequestHandler):
def post(self):
if users.is_current_user_admin() == False:
self.redirect('/')
clubName = self.request.get('clubname')
clubEmail = self.request.get('clubgoogleaccount')
error = '';
if clubName is None:
error = '1'
if clubEmail:
if re.match(r"[^@]+@[^@]+\.[^@]+", clubEmail) == False:
error = '3'
else:
error = '1'
if error == '':
error = "0"
clubKey = self.get_primaryKey()
newClub = Club(key=club_key(str(clubKey)))
newClub.name = clubName
newClub.primaryKey = clubKey
newClub.clubEmail = clubEmail.lower()
newClub.put();
newUserPermissions = userPermissions(key=userPermissions_key(clubEmail,clubKey))
newUserPermissions.permissionLevel = 2
newUserPermissions.name = 'Club Secretary'
newUserPermissions.clubKey = clubKey
newUserPermissions.email = clubEmail
newUserPermissions.put()
self.redirect('/addClub?error=%s' % error)
def get_primaryKey(addClub_Submit):
data = memcache.get('clubPrimaryKey')
if data is not None:
primaryKey = int(data)
memcache.add(str(primaryKey + 1), 'clubPrimaryKey', 200)
return primaryKey
else:
highestNumber = 0
clubs = db.GqlQuery("SELECT * "
"FROM Club ")
for club in clubs:
if highestNumber < club.primaryKey:
highestNumber = club.primaryKey
highestNumber = highestNumber + 1
memcache.add(str(highestNumber + 1), 'clubPrimaryKey', 200)
return highestNumber
#Security: Should show all clubs to admins, but only clubs the user is admin in if they are not.
class addMembers(webapp2.RequestHandler):
def get(self):
clubs = []
clubsMasterString = ''
clubs = securityManager.getClubsUserIsPersonnelOf()
for Club in clubs:
clubsMasterString = clubsMasterString + '<option value="' + str(Club.primaryKey) + '">' + Club.name + '</option>'
if clubsMasterString == '':
self.redirect('/')
error = self.request.get('error')
if error == '0':
name = self.request.get('name')
if name:
error = 'Successfully added:' + name
else:
error = 'Success!'
elif error == '1':
error = 'Looks like you missed something'
elif error == '2':
error = 'Student ID needs to be a number'
elif error == '3':
error = 'Student ID match not found'
elif error == '4':
error = 'Match already found'
elif error == '5':
error = 'Permission not found'
elif error == '6':
error = 'Student ID malformed.'
year = str(datetime.now().year)
template_values = {
'error': error,
'clubs': clubsMasterString,
'year' : year
}
path = os.path.join(os.path.dirname(__file__), 'addMember.html')
self.response.out.write(template.render(path, template_values))
class addMembers_Submit(webapp2.RequestHandler):
def post(self):
error = ''
year = datetime.now().year
try:
studentID = self.request.get('studentid')
stringLength = studentID.__len__()
if stringLength > 7:
studentID = int(studentID[:8])
else:
error = '6'
except:
error = '2'
clubPrimaryKey = self.request.get('clubinput')
if clubPrimaryKey:
clubPrimaryKey = int(clubPrimaryKey)
else:
error = '1'
personName = ''
personEmail = ''
if error == '':
if studentID:
person = db.get(person_key(studentID))
if person is None:
error = '3'
else:
personName = person.firstName + ' ' + person.lastName
personEmail = person.email
if personEmail:
personEmail = personEmail.lower()
else:
personEmail = 'N/A'
permissionLevel = securityManager.getLevelOfAuthenticationForUserForClub(clubPrimaryKey)
if permissionLevel == 0:
error = '5'
msaCardStatus = self.request.get('msacardstatus')
if msaCardStatus == 'YES':
securityManager.addMSACardToStudent(studentID)
else:
error = '1'
if error == '':
#Check if it already exists.
clubMemberships = db.GqlQuery("SELECT * "
"FROM PersonClubStatus "
"WHERE studentID = :1 AND year = :2 AND clubKey = :3",
studentID,year, clubPrimaryKey)
for person in clubMemberships:
error = '4'
if error == '':
newClubStatus = PersonClubStatus(key=personClubStatus_key(studentID,year,clubPrimaryKey))
newClubStatus.studentID = studentID
newClubStatus.year = year
newClubStatus.clubKey = int(clubPrimaryKey)
newClubStatus.memberType = int(self.request.get('memberType'))
user = users.get_current_user()
email = user.email().lower()
addedByAuthcate = email.split("@")[0]
newClubStatus.addedBy = addedByAuthcate
logging.info('Added to club')
logging.info(clubPrimaryKey)
logging.info(year)
if personName:
logging.info(personName)
else:
logging.info('No name')
newClubStatus.put()
club = db.get(club_key(str(clubPrimaryKey)))
clubName = club.name
clubCounter = db.get(ClubCounter_key(clubPrimaryKey,year))
if clubCounter:
clubCounter.numberOfMembers = clubCounter.numberOfMembers + 1
if msaCardStatus == 'YES':
if clubCounter.numberOfMSAMembers:
clubCounter.numberOfMSAMembers = clubCounter.numberOfMSAMembers + 1
else:
clubCounter.numberOfMSAMembers = 1
clubCounter.put()
else:
clubCounter = ClubCounter(key=ClubCounter_key(clubPrimaryKey,year))
clubCounter.year = datetime.now().year
clubCounter.clubKey = club.primaryKey
clubCounter.numberOfMembers = 1
msaCardStatus = self.request.get('msacardstatus')
if msaCardStatus == 'YES':
clubCounter.numberOfMSAMembers = 0
else:
clubCounter.numberOfMSAMembers = 1
clubCounter.put()
user = users.get_current_user()
email = user.email().lower()
addedByAuthcate = email.split("@")[0]
try:
message = mail.EmailMessage(sender="No Reply <noreply@monashclubs.org>", subject="You have been added to " + clubName)
message.to = personName + '<' + personEmail + '>'
message.body = '''
You have been added as a member of the {!s}.
This has been done by {!s} upon receipt of any membership fees that were payable.
Your information will be used by the club to contact your with regards to club events/activities and
information. If you have been added to this club in error, please contact Clubs & Societies by emailing
webmaster@monashclubs.org. If you would like to make a complaint, please contact the
Club Development Officer at do@monashclubs.org.
'''.format(clubName, addedByAuthcate)
message.send()
except:
logging.error('Failure to send email')
logging.error('error' + str(sys.exc_info()[0]))
error = '0'
if personName != '':
self.redirect(('/addMembers?error=%s' % error) + ('&name=%s' % personName))
else:
self.redirect('/addMembers?error=%s' % error)
class deleteMember(webapp2.RequestHandler):
def get(self):
clubs = []
clubsMasterString = ''
clubs = securityManager.getClubsUserIsAdminOf()
for Club in clubs:
clubsMasterString = clubsMasterString + '<option value="' + str(Club.primaryKey) + '">' + Club.name + '</option>'
if clubsMasterString == '':
self.redirect('/')
error = self.request.get('error')
if error == '0':
error = 'Success!'
elif error == '1':
error = 'Looks like you missed something'
elif error == '2':
error = 'Student ID needs to be a number'
elif error == '3':
error = 'Student ID match not found'
elif error == '4':
error = 'Match already found'
elif error == '5':
error = 'Permission not found'
elif error == '6':
error = 'Student ID malformed.'
elif error == '7':
error = 'Membership not found'
year = str(datetime.now().year)
template_values = {
'error': error,
'clubs': clubsMasterString,
'year' : year
}
path = os.path.join(os.path.dirname(__file__), 'removeMember.html')
self.response.out.write(template.render(path, template_values))
class deleteMember_Submit(webapp2.RequestHandler):
def post(self):
error = ''
year = datetime.now().year
try:
studentID = self.request.get('studentid')
stringLength = studentID.__len__()
if stringLength > 7:
studentID = int(studentID[:8])
else:
error = '6'
except:
error = '2'
clubPrimaryKey = self.request.get('clubinput')
if clubPrimaryKey:
clubPrimaryKey = int(clubPrimaryKey)
else:
error = '1'
if error == '':
try:
if studentID:
person = db.get(person_key(studentID))
if person is None:
error = '3'
permissionLevel = securityManager.getLevelOfAuthenticationForUserForClub(clubPrimaryKey)
if permissionLevel == 0:
error = '5'
else:
error = '1'
except:
error = '4'
if error == '':
#Check if it already exists.
clubMemberships = db.GqlQuery("SELECT * "
"FROM PersonClubStatus "
"WHERE studentID = :1 AND year = :2 AND clubKey = :3",
studentID,year, clubPrimaryKey)
for person in clubMemberships:
clubCounter = db.get(ClubCounter_key(clubPrimaryKey,datetime.now().year))
if clubCounter:
clubCounter.numberOfMembers = clubCounter.numberOfMembers - 1
clubCounter.put()
person.delete()
error = '0'
club = db.get(club_key(str(clubPrimaryKey)))
clubName = club.name
user = users.get_current_user()
email = user.email().lower()
addedByAuthcate = email.split("@")[0]
try:
message = mail.EmailMessage(sender="No Reply <noreply@monashclubs.org>",
subject="You have been added to " + clubName)
message.to = personName + '<' + personEmail + '>'
message.body = '''
You have been removed as a member of the {!s}.
This has been done by {!s} upon receipt of a request from yourself
to terminate your membership or if you have been removed as a member of this club in
accordance with the clubs constitution and the constitution of the Clubs & Societies Council.
If you have been added to this club in error, please contact Clubs & Societies by
emailing webmaster@monashclubs.org. If you would like to make a complaint, please contact
the Club Development Officer at do@monashclubs.org
'''.format(clubName, addedByAuthcate)
message.send()
except:
logging.error('Failure to send email')
self.redirect('/deleteMember?error=%s' % error)
class deletePerson(webapp2.RequestHandler):
def get(self):
clubs = []
clubsMasterString = ''
clubs = securityManager.getClubsUserIsAdminOf()
for Club in clubs:
clubsMasterString = clubsMasterString + '<option value="' + str(Club.primaryKey) + '">' + Club.name + '</option>'
if clubsMasterString == '':
self.redirect('/')
error = self.request.get('error')
if error == '0':
error = 'Success!'
elif error == '1':
error = 'Looks like you missed something'
elif error == '2':
error = 'Student ID needs to be a number'
elif error == '3':
error = 'Student ID match not found'
elif error == '4':
error = 'Match already found'
elif error == '5':
error = 'Permission not found'
elif error == '6':
error = 'Student ID malformed.'
elif error == '7':
error = 'Membership not found'
year = str(datetime.now().year)
template_values = {
'error': error,
'clubs': clubsMasterString,
'year' : year
}
path = os.path.join(os.path.dirname(__file__), 'deletePerson.html')
self.response.out.write(template.render(path, template_values))
class deletePerson_Submit(webapp2.RequestHandler):
def post(self):
error = ''
year = datetime.now().year
if users.is_current_user_admin() == False:
self.redirect('/')
try:
studentID = self.request.get('studentid')
stringLength = studentID.__len__()
if stringLength > 7:
studentID = int(studentID[:8])
else:
error = '6'
except:
error = '2'
if error == '':
try:
if studentID:
person = db.get(person_key(studentID))
if person is None:
error = '3'
else:
person.delete()
else:
error = '1'
except:
error = '4'
if error == '':
#Check if it already exists.
clubMemberships = db.GqlQuery("SELECT * "
"FROM PersonClubStatus "
"WHERE studentID = :1",
studentID)
for person in clubMemberships:
person.delete()
error = '0'
clubMemberships = db.GqlQuery("SELECT * "
"FROM PersonEventStatus "
"WHERE studentID = :1",
studentID)
for person in clubMemberships:
person.delete()
error = '0'
if error == '':
error = '7'
self.redirect('/deletePerson?error=%s' % error)
class viewMembershipTotals(webapp2.RequestHandler):
def get(self):
clubs = securityManager.getClubsUserIsAdminOf()
masterString = ''
for club in clubs:
counters = db.GqlQuery("SELECT * "
"FROM ClubCounter "
"WHERE clubKey = :1",
club.primaryKey)
for counter in counters:
masterString = masterString + '<tr><td>' + club.name + '</td><td>' + str(counter.year) + '</td><td>' + str(counter.numberOfMembers) + '</td><td>' + str(counter.numberOfMSAMembers) + '</td></tr>'
template_values = {
'masterString' :masterString
}
path = os.path.join(os.path.dirname(__file__), 'viewClubsPopulation.html')
self.response.out.write(template.render(path, template_values))
class checkMemberStatus(webapp2.RequestHandler):
def get(self):
error = self.request.get('error')
if error == '1':
error = 'Looks like you missed something'
elif error == '2':
error = 'Student ID needs to be a number'
elif error == '3':
error = 'Student ID match not found'
template_values = {
}
path = os.path.join(os.path.dirname(__file__), 'checkMemberStatusSelector.html')
self.response.out.write(template.render(path, template_values))
class checkMemberStatus_Submit(webapp2.RequestHandler):
def post(self):
error = ''
try:
studentID = self.request.get('studentid')
if studentID:
studentID = int(studentID)
authcate = self.request.get('authcate')
except:
error = '2'
if error == '':
#try:
person = ''
logging.info('1')
if studentID or authcate:
logging.info('2')
if studentID:
logging.info('3')
person = db.get(person_key(studentID))
match = False
if person == '':
authcate = self.request.get('authcate')
persons = db.GqlQuery("SELECT * "
"FROM Person "
"WHERE authcate = :1",authcate)
logging.info('4')
for foundPeople in persons:
person = foundPeople
logging.info('5')
if person:
name = person.firstName + ' ' + person.lastName
email = person.email
campus = person.campus
phoneNumber = person.phoneNumber
if campus == 1:
campus = 'Clayton'
elif campus == 2:
campus = 'Caulfield'
elif campus == 3:
campus = 'Peninsula'
elif campus == 4:
campus = 'Parkville'
elif campus == 5:
campus = 'Gippsland'
elif campus == 6:
campus = 'Berwick'
elif campus == 7:
campus = 'India'
elif campus == 8:
campus = 'South Africa'
elif campus == 9:
campus = 'Italy'
elif campus == 10:
campus = 'Sunway, Malaysia'
elif campus == 11:
campus = 'China'
authcate = person.authcate
studentID = person.studentID
address = person.address
type = ['Student','Staff','Non-Student']
index = 0
if person.personType:
index = person.personType - 1
type = type[index]
tableString = ''
MSAMemberStatus = 'N'
clubMemberships = db.GqlQuery("SELECT * "
"FROM PersonClubStatus "
"WHERE studentID = :1",
studentID)
clubList = []
clubs = securityManager.getClubsUserIsAdminOf()
for club in clubs:
clubList.append(club)
now = datetime.now()
year = now.year
for membership in clubMemberships:
clubKey = membership.clubKey
clubName = ''
if membership.year == year and clubKey == 0:
MSAMemberStatus = 'Y'
for club in clubList:
if club.primaryKey == clubKey:
club = db.get(club_key(str(clubKey)))
if club:
clubName = club.name
else:
clubName = 'Error, not found. Key:' + str(clubKey)
addedBy = membership.addedBy
if addedBy is None:
addedBy = 'N/A'
date = membership.joiningDate
if date is None:
date = 'N/A'
else:
before = ESTTime()
after = MelbourneTime()
date = membership.joiningDate
date = date.replace(tzinfo=before)
date = date.astimezone(after)
year = membership.year
if year is None:
year = 'None'
tableString = tableString + '<tr><td>' + clubName + '</td><td>' + str(year) + '</td><td>' + addedBy + '</td><td>' + str(date) + '</td></tr>'
if tableString == '' and users.is_current_user_admin() == False:
self.redirect('/')
template_values = {
'type' : type,
'name' : name,
'email' : email,
'authcate' : authcate,
'address' : address,
'campus' : campus,
'studentID' : studentID,
'phoneNumber' : phoneNumber,
'memberships' : tableString,
'MSAMemberStatus' : MSAMemberStatus
}
path = os.path.join(os.path.dirname(__file__), 'showMemberStatus.html')
self.response.out.write(template.render(path, template_values))
else:
error = '3'
else:
error = '1'
#except:
# error = '4'
if error != '':
self.redirect('/checkMemberStatus?error=%s' % error)
class addMSACard(webapp2.RequestHandler):
def get(self):
if users.is_current_user_admin() == False:
self.redirect('/')
error = self.request.get('error')
if error == '0':
error = 'Success!'
elif error == '1':
error = 'Looks like you missed something'
elif error == '2':
error = 'Student ID needs to be a number'
elif error == '3':
error = 'Student ID match not found'
elif error == '4':
error = 'Already found for year'
template_values = {
'error': error,
}