-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadminHome.py
914 lines (681 loc) · 26 KB
/
adminHome.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
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
import os
import webapp2
import logging
#---------------- Import from Google ------------------
#
from google.appengine.api import users, images
from google.appengine.ext import db
from google.appengine.ext.webapp import template
#
#------------------------------------------------------
#----------------- Custom Classes & -------------------
#----------------- Datastore Schema -------------------
#
from commonFunction import createEventLog
from commonFunction import dateFromNow, oneDayOrDate
from commonFunction import getCommonUiParams
from commonFunction import invalidateTokenList
from commonFunction import findAccount, findAccountByNickname
from commonFunction import returnJsonResult
from commonFunction import retrieveEventLogFullSet, retrieveApplicationSettings
from commonFunction import retrieveRestrictedNicknameList
from commonFunction import updateApplicationSettings
from decorator import AdminOnly
from decorator import UserNicknameRequired
import schema
#
#------------------------------------------------------
class AdminManagementHandler(webapp2.RequestHandler):
@AdminOnly
def get(self):
self.response.headers['Content-Type'] = "text/html"
path = os.path.join(os.path.dirname(__file__), "template/adminManagement.html")
self.response.out.write(template.render(path, getCommonUiParams(self)))
#
class ListAdminHandler(webapp2.RequestHandler):
def get(self):
self.redirect('/')
@AdminOnly
def post(self):
self.response.headers['Content-Type'] = "text/html"
path = os.path.join(os.path.dirname(__file__), "template/adminAdminList.json")
account = findAccount()
adminAccountQuery = schema.Account.all().filter("level = ", 'admin')
result_length = 1000
admins = adminAccountQuery.fetch(result_length)
result_length = min(result_length, len(admins))
adminList = []
index = 0
for a in admins:
if result_length-1 == index:
noComma = 'True'
else:
index = index + 1
noComma = 'False'
adminInfo = {
'nickname': a.nickname,
'noComma': noComma
}
adminList.append(adminInfo)
if result_length == 0:
adminList.append({
'endOfList': 'True',
'noComma': 'True'
})
resultList = {
'adminList': adminList,
}
self.response.out.write(template.render(path, resultList))
#
class AddAdminHandler(webapp2.RequestHandler):
def get(self):
self.redirect('/')
@AdminOnly
def post(self):
self.response.headers['Content-Type'] = "application/json;charset=UTF-8"
if self.request.get('admin', None) is not None:
account = findAccount()
admin = findAccountByNickname(self.request.get('admin'))
if admin is None:
returnJsonResult(self, 'false', 'no such account')
return
admin.level = 'admin'
admin.put()
createEventLog(account.nickname, 'ADMIN_CREATE', 'admin = ' + admin.nickname , '' )
returnJsonResult(self, 'true')
else:
returnJsonResult(self, 'false', 'blank')
#
class RemoveAdminHandler(webapp2.RequestHandler):
def get(self):
self.redirect('/')
@AdminOnly
def post(self):
self.response.headers['Content-Type'] = "application/json;charset=UTF-8"
if self.request.get('admin', None) is not None:
account = findAccount()
admin = findAccountByNickname(self.request.get('admin'))
if admin is None:
returnJsonResult(self, 'false', 'no such account')
return
admin.level = 'user'
admin.put()
createEventLog(account.nickname, 'ADMIN_DELETE', 'admin = ' + admin.nickname , '' )
returnJsonResult(self, 'true')
else:
returnJsonResult(self, 'false', 'blank')
#
class UserManagementHandler(webapp2.RequestHandler):
@AdminOnly
def get(self):
self.response.headers['Content-Type'] = "text/html"
path = os.path.join(os.path.dirname(__file__), "template/adminUserManagement.html")
self.response.out.write(template.render(path, getCommonUiParams(self)))
#
class ListUserHandler(webapp2.RequestHandler):
def get(self):
self.redirect('/')
@AdminOnly
def post(self):
self.response.headers['Content-Type'] = "application/json;charset=UTF-8"
type = self.request.get('type', '')
value = self.request.get('value', '')
accountList = []
if type != '' and value != '':
if type == 'nickname':
userAccountQuery = schema.Account.all().filter("nickname = ", value)
result_length = 1000
accounts = userAccountQuery.fetch(result_length)
result_length = min(result_length, len(accounts))
index = 0
for a in accounts:
if result_length-1 == index:
noComma = 'True'
else:
index = index + 1
noComma = 'False'
accountInfo = {
'id': a.key().id(),
'nickname': a.nickname,
'itemCount': db.GqlQuery("SELECT __key__ FROM ShopItem WHERE owner = :1 ", a.nickname).count(),
'status': a.status,
'noComma': noComma
}
accountList.append(accountInfo)
if result_length == 0:
accountList.append({
'endOfList': 'True',
'noComma': 'True'
})
elif type == 'id':
if not value.isdigit() or int(value) < 1:
returnJsonResult(self, 'false', 'Bad request')
return
account = schema.Account.get_by_id(int(value))
if account is None:
returnJsonResult(self, 'false', 'Account not found')
return
else:
accountList.append({
'id': account.key().id(),
'nickname': account.nickname,
'itemCount': db.GqlQuery("SELECT __key__ FROM ShopItem WHERE owner = :1 ", account.nickname).count(),
'status': account.status,
'noComma': 'True'
})
else:
accountList.append({
'endOfList': 'True',
'noComma': 'True'
})
else:
userAccountQuery = schema.Account.all()
result_length = 1000
accounts = userAccountQuery.fetch(result_length)
result_length = min(result_length, len(accounts))
index = 0
for a in accounts:
if result_length-1 == index:
noComma = 'True'
else:
index = index + 1
noComma = 'False'
accountInfo = {
'id': a.key().id(),
'nickname': a.nickname,
'itemCount': db.GqlQuery("SELECT __key__ FROM ShopItem WHERE owner = :1 ", a.nickname).count(),
'status': a.status,
'noComma': noComma
}
accountList.append(accountInfo)
if result_length == 0:
accountList.append({
'endOfList': 'True',
'noComma': 'True'
})
resultList = {
'accountList': accountList,
}
path = os.path.join(os.path.dirname(__file__), "template/adminUserList.json")
self.response.out.write(template.render(path, resultList))
#
class UpdateUserStatusHandler(webapp2.RequestHandler):
def get(self):
self.redirect('/')
@AdminOnly
def post(self):
type = self.request.get('type', '')
value = self.request.get('value', '')
self.response.headers['Content-Type'] = "application/json;charset=UTF-8"
account = findAccount()
if type != '' and value != '':
user = findAccountByNickname(value)
if user is None:
returnJsonResult(self, 'false', 'Account not exist')
return
if type == 'activate':
user.status='Active'
user.put()
createEventLog(account.nickname, 'ACCOUNT_ACTIVATE', 'account = ' + user.nickname , '' )
returnJsonResult(self, 'true')
# update account item status to Suspend if status = Suspend
shopItemQuery = schema.ShopItem.all().filter("owner = ", user.nickname).filter("status = ", 'Suspend')
shopItems = shopItemQuery.fetch(999999)
for item in shopItems:
item.status = 'Active'
item.put()
return
elif type == 'deactivate':
user.status='Suspend'
user.put()
createEventLog(account.nickname, 'ACCOUNT_DEACTIVATE', 'account = ' + user.nickname , '' )
logging.info("account " + user.nickname + " is suspended")
# update account item status to Suspend if status = Active
shopItemQuery = schema.ShopItem.all().filter("owner = ", user.nickname).filter("status = ", 'Active')
shopItems = shopItemQuery.fetch(999999)
for item in shopItems:
item.status = 'Suspend'
item.put()
returnJsonResult(self, 'true')
return
returnJsonResult(self, 'false', 'Bad Request')
class ListItemHandler(webapp2.RequestHandler):
def get(self):
self.redirect('/')
@AdminOnly
def post(self):
self.response.headers['Content-Type'] = "application/json;charset=UTF-8"
type = self.request.get('type', '')
value = self.request.get('value', '')
itemList = []
if type != '' and value != '':
if type == 'nickname':
logging.info("type = nickname")
itemQuery = schema.ShopItem.all().filter("owner = ", value)
result_length = 1000
items = itemQuery.fetch(result_length)
result_length = min(result_length, len(items))
index = 0
for a in items:
if result_length-1 == index:
noComma = 'True'
else:
index = index + 1
noComma = 'False'
itemInfo = {
'id': a.key().id(),
'title': a.title,
'owner': a.owner,
'viewCount': a.viewCount,
'status': a.status,
'noComma': noComma
}
itemList.append(itemInfo)
if result_length == 0:
itemList.append({
'endOfList': 'True',
'noComma': 'True'
})
elif type == 'id':
logging.info("type = id")
if not value.isdigit() or int(value) < 1:
returnJsonResult(self, 'false', 'Bad request')
return
item = schema.ShopItem.get_by_id(int(value))
if item is None:
returnJsonResult(self, 'false', 'Item not found')
return
else:
itemList.append({
'id': item.key().id(),
'title': item.title,
'owner': item.owner,
'viewCount': item.viewCount,
'status': item.status,
'noComma': 'True'
})
else:
logging.info("else")
itemList.append({
'endOfList': 'True',
'noComma': 'True'
})
else:
itemList.append({
'endOfList': 'True',
'noComma': 'True'
})
resultList = {
'itemList': itemList,
}
path = os.path.join(os.path.dirname(__file__), "template/adminItemList.json")
self.response.out.write(template.render(path, resultList))
#
class DeleteItemHandler(webapp2.RequestHandler):
def get(self):
self.redirect('/')
@AdminOnly
def post(self):
self.response.headers['Content-Type'] = "application/json;charset=UTF-8"
account = findAccount()
#TODO run in transaction
itemId = self.request.get('value', '')
if not itemId.isdigit() or int(itemId) < 1:
returnJsonResult(self, 'false', 'Bad request')
return
item = schema.ShopItem.get_by_id(int(itemId))
if item is not None:
# Remove associated photos/ videos
if item.profilePicBlobKey != '':
images.delete_serving_url(item.profilePicBlobKey)
blobstore.delete(item.profilePicBlobKey)
#TODO? update associated message conversations
# delete record in KeywordRepo
keywordRepoQuery = schema.KeywordRepo.all().filter("shopItemId = ", itemId)
keywordRepoList = keywordRepoQuery.fetch(999999)
for k in keywordRepoList:
k.delete()
item.delete()
# Event Log
createEventLog(account.nickname, 'ADMIN_DELETE_ITEM', 'itemId = '+ itemId , '')
returnJsonResult(self, 'true')
else:
returnJsonResult(self, 'false', 'Item does not exist')
class ItemManagementHandler(webapp2.RequestHandler):
@AdminOnly
def get(self):
self.response.headers['Content-Type'] = "text/html"
path = os.path.join(os.path.dirname(__file__), "template/adminItemManagement.html")
self.response.out.write(template.render(path, getCommonUiParams(self)))
#
class EventManagementHandler(webapp2.RequestHandler):
@AdminOnly
def get(self):
self.response.headers['Content-Type'] = "text/html"
params = {
'actor': self.request.get('actor', ''),
'actionType': self.request.get('actionType', '')
}
path = os.path.join(os.path.dirname(__file__), "template/adminEventLog.html")
self.response.out.write(template.render(path, getCommonUiParams(self, params, retrieveEventLogFullSet()) ))
#
class EventLogListHandler(webapp2.RequestHandler):
def get(self):
self.redirect('/')
@AdminOnly
def post(self):
self.response.headers['Content-Type'] = "application/json;charset=UTF-8"
path = os.path.join(os.path.dirname(__file__), "template/adminEventLogList.json")
account = findAccount()
eventLogQuery = schema.EventLog.all()
actor = self.request.get('actor', '')
actionType = self.request.get('actionType', '')
if actor != '':
eventLogQuery.filter('actor = ', actor)
if actionType != '':
eventLogQuery.filter('actionType = ', actionType)
#
eventLogQuery.order("-date")
result_length = 1000
eventLogs = eventLogQuery.fetch(result_length)
result_length = min(result_length, len(eventLogs))
eventLogList = []
index = 0
endOfList = ''
for e in eventLogs:
if result_length-1 == index:
noComma = 'True'
else:
index = index + 1
noComma = 'False'
datetime = oneDayOrDate(e.date)
date_fromnow = dateFromNow(e.date)
exactDate = e.date
eventLogInfo = {
'eventType': e.actionType,
'actorName': e.actor,
'eventTarget': e.target,
'eventDetails': e.content,
'datetime': datetime,
'exactDate': exactDate,
'date_fromnow': date_fromnow,
'endOfList': endOfList,
'noComma': noComma
}
eventLogList.append(eventLogInfo)
if len(eventLogList) == 0:
eventLogList.append({
'endOfList': 'True',
'noComma': 'True'
})
resultList = {
'eventLogList': eventLogList,
}
self.response.out.write(template.render(path, resultList))
return
#
class ApplicationSettingsViewHandler(webapp2.RequestHandler):
@AdminOnly
def get(self):
self.response.headers['Content-Type'] = "text/html"
params = {
'item_max_activeDays': retrieveApplicationSettings('env', 'item_max_activeDays'),
'item_min_activeDays': retrieveApplicationSettings('env', 'item_min_activeDays'),
'item_max_price': retrieveApplicationSettings('env', 'item_max_price'),
'item_min_price': retrieveApplicationSettings('env', 'item_min_price'),
'item_max_quantity': retrieveApplicationSettings('env', 'item_max_quantity'),
'item_min_quantity': retrieveApplicationSettings('env', 'item_min_quantity'),
'nickname_max_chars': retrieveApplicationSettings('env', 'nickname_max_chars'),
'nickname_min_chars': retrieveApplicationSettings('env', 'nickname_min_chars'),
'item_expire_alert_daysBefore': retrieveApplicationSettings('env', 'item_expire_alert_daysBefore'),
'search_result_length': retrieveApplicationSettings('env', 'search_result_length'),
'conversation_group_size': retrieveApplicationSettings('env', 'conversation_group_size'),
'restrictedNicknameList': self.request.get('actor', ''),
'cron_item_expiryDateChecker': retrieveApplicationSettings('cron', 'cron_item_expiryDateChecker'),
'cron_account_expiryDateChecker': retrieveApplicationSettings('cron', 'cron_account_expiryDateChecker')
}
path = os.path.join(os.path.dirname(__file__), "template/adminApplicationSettings.html")
self.response.out.write(template.render(path, getCommonUiParams(self, params, retrieveEventLogFullSet()) ))
#
class ApplicationSettingsUpdateHandler(webapp2.RequestHandler):
def get(self):
self.redirect('/')
@AdminOnly
def post(self):
account = findAccount()
self.response.headers['Content-Type'] = "application/json;charset=UTF-8"
type = self.request.get('type', '')
name = self.request.get('name', '')
value = self.request.get('value', 0)
remarks = self.request.get('remarks', '')
if type == '' or value == '':
returnJsonResult(self, 'false', 'Required values cannot be blank')
return
if type != 'nickname' and type!='delete-restricted' and name == '': # only skip the case for restricted nicknames
returnJsonResult(self, 'false', 'Required values cannot be blank')
return
updateApplicationSettings(type, name, remarks, value)
createEventLog(account.nickname, 'APP_SETTINGS_UPDATE', name + ' = '+ str(value) , '')
returnJsonResult(self, 'true', 'Changes saved')
#
class RestrictedNicknameListHandler(webapp2.RequestHandler):
def get(self):
self.post()
#self.redirect('/')
@AdminOnly
def post(self):
self.response.headers['Content-Type'] = "application/json;charset=UTF-8"
nicknameList = []
for name in retrieveRestrictedNicknameList():
nicknameList.append({
'type': 'system_default',
'value': name,
'remarks': '',
'endOfList': ''
})
nicknameQuery = schema.ApplicationSettings.all().filter('type = ', 'nickname')
restrictedList = nicknameQuery.fetch(999999)
for record in restrictedList:
nicknameList.append({
'type': 'restricted',
'value': record.value,
'remarks': record.remarks,
'endOfList': ''
})
nicknameList.append({
'endOfList': 'True',
'noComma': 'True'
})
resultList = {
'nicknameList': nicknameList,
}
path = os.path.join(os.path.dirname(__file__), "template/adminRestrictedNicknameList.json")
self.response.out.write(template.render(path, resultList ))
#
class APISettingsListViewHandler(webapp2.RequestHandler):
@AdminOnly
def get(self):
self.post()
@AdminOnly
def post(self):
self.response.headers['Content-Type'] = "application/json;charset=UTF-8"
type = self.request.get('type', '')
# retrieve a list of api (access token given by other applications)
if type != "partner" and type != "own":
returnJsonResult(self, 'false', 'API type is missing')
return
# TODO get from cache. If cache miss, get from datastore.
# TODO cache miss
apiQuery = schema.ApplicationApiSettings.all().filter("apiType = ", type)
apiResult = apiQuery.fetch(999999)
apiList = []
for api in apiResult:
apiList.append({
'id': api.key().id(),
'domain': api.domain,
'key': api.token,
'remarks': api.remarks
})
apiList.append({
'endOfList': 'True',
'noComma': 'True'
})
resultList = {
'apiList': apiList
}
path = os.path.join(os.path.dirname(__file__), "template/adminApiList.json")
self.response.out.write(template.render(path, resultList ))
#
class APISettingsUpdateHandler(webapp2.RequestHandler):
def get(self):
self.post()
#self.redirect('/')
@AdminOnly
def post(self):
self.response.headers['Content-Type'] = "application/json;charset=UTF-8"
account = findAccount()
action = self.request.get('action', '')
if action == 'add':
type = self.request.get('type', '')
if type is None:
returnJsonResult(self, 'false', 'missing api type')
return
domain = self.request.get('domain', '')
key = self.request.get('key', '')
remarks = self.request.get('remarks', '')
if domain == '' or key == '':
returnJsonResult(self, 'false', 'missing domain or key')
return
apiRecord = schema.ApplicationApiSettings(
domain = domain,
token = key,
apiType = type,
remarks = remarks
)
apiRecord.put()
invalidateTokenList()
createEventLog(account.nickname, 'ADMIN_API_UPDATE', domain + ', token = '+ str(key) , 'api id = '+ str(apiRecord.key().id()))
returnJsonResult(self, 'true', 'API added')
elif action == 'delete':
id = self.request.get('id', '')
apiRecord = schema.ApplicationApiSettings.get_by_id(int( id ))
if apiRecord is None:
returnJsonResult(self, 'false', 'api record not found')
return
apiRecord.delete()
createEventLog(account.nickname, 'ADMIN_API_DELETE', 'api id = '+ str(id) , '')
invalidateTokenList()
returnJsonResult(self, 'true', 'API deleted')
else:
returnJsonResult(self, 'false', 'missing action type')
#pass
# update other application's data. for API calls.
# effective immediately. reload cache
#
class WishlistManagementHandler(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = "text/html"
path = os.path.join(os.path.dirname(__file__), "template/adminWishlistManagement.html")
self.response.out.write(template.render(path, getCommonUiParams(self)))
#
class WishlistSearchHandler(webapp2.RequestHandler):
def get(self):
self.post()
#self.redirect('/')
@AdminOnly
def post(self):
self.response.headers['Content-Type'] = "application/json;charset=UTF-8"
account = findAccount() # current logged in account
# both can be blank. returning all result
itemid = self.request.get('itemid', '')
nickname = self.request.get('account', '')
#if itemid == '' and nickname = '':
# returnJsonResult(self, 'false', 'Must give some information here')
#TODO validate itemid and account
# wrong itemid/ account will result in no returning result
wishlistQuery = schema.WishList.all()
if itemid != '':
wishlistQuery = wishlistQuery.filter("shopItemId = ", itemid)
logging.debug("shopItemId = " + str(itemid))
if nickname != '':
wishlistQuery = wishlistQuery.filter("nickname = ", nickname)
logging.debug("nickname = " + nickname)
wishlists = wishlistQuery.fetch(999999)
wishlistItemList = []
for wishlist in wishlists:
item = schema.ShopItem.get_by_id(int(wishlist.shopItemId))
# item should not be None here. All wishlist item should be able to map with one existing item.
# report error, skip getting item information
#TODO remove associated wishlist item when item owner attempts to remove one item
if item is None:
logging.error("Error while getting wishlist item information. Item (id = "+ str(wishlist.shopItemId) +") does not exist.")
continue
itemTitle = item.title
wishlistItemList.append({
'itemid': str(wishlist.shopItemId),
'itemTitle': itemTitle,
'wishlistOwnerAccount': wishlist.nickname
})
wishlistItemList.append({
'endOfList': 'True',
'noComma': 'True'
})
resultList = {
'wishlistItemList': wishlistItemList,
}
path = os.path.join(os.path.dirname(__file__), "template/adminWishlistItemList.json")
self.response.out.write(template.render(path, resultList ))
class WishlistDeleteHandler(webapp2.RequestHandler):
def get(self):
self.post()
#self.redirect('/')
@AdminOnly
def post(self):
self.response.headers['Content-Type'] = "application/json;charset=UTF-8"
account = findAccount() # current logged in account
# all fields required
itemid = self.request.get('itemid', '')
nickname = self.request.get('account', '')
if itemid == '' or nickname == '':
returnJsonResult(self, 'false', 'Must give all information here')
#TODO validate itemid and account
# wrong itemid/ account will result in no returning result
wishlistQuery = schema.WishList.all()
if itemid != '':
wishlistQuery = wishlistQuery.filter("shopItemId = ", itemid)
if nickname != '':
wishlistQuery = wishlistQuery.filter("nickname = ", nickname)
# should return at most one record
wishlist = wishlistQuery.get()
if wishlist is not None:
wishlist.delete()
# Event Log
createEventLog(account.nickname, 'WISHLIST_ADMIN_REMOVE', 'itemId = '+ itemid + ', account = ' + nickname , '')
returnJsonResult(self, 'true', 'Wishlist item was removed')
else:
returnJsonResult(self, 'false', 'Wishlist item could not be found')
#
#
app = webapp2.WSGIApplication([
('/admin/manage', AdminManagementHandler),
('/admin/listAdmin', ListAdminHandler),
('/admin/addAdmin', AddAdminHandler),
('/admin/removeAdmin', RemoveAdminHandler),
('/admin/user', UserManagementHandler),
('/admin/userList', ListUserHandler),
('/admin/updateStatus', UpdateUserStatusHandler),
('/admin/item', ItemManagementHandler),
('/admin/itemList', ListItemHandler),
('/admin/deleteItem', DeleteItemHandler),
('/admin/wishlist', WishlistManagementHandler),
('/admin/wishlist/find', WishlistSearchHandler),
('/admin/wishlist/delete', WishlistDeleteHandler),
('/admin/event', EventManagementHandler),
('/admin/eventLogList', EventLogListHandler),
('/admin/apiSettingsList', APISettingsListViewHandler),
('/admin/updateApiSettings', APISettingsUpdateHandler),
('/admin/appSettings', ApplicationSettingsViewHandler),
('/admin/restrictedNicknameList', RestrictedNicknameListHandler),
('/admin/updateAppSettings', ApplicationSettingsUpdateHandler),
('/admin/', AdminManagementHandler)
], debug=True)