-
Notifications
You must be signed in to change notification settings - Fork 16
/
admin.py
executable file
·60 lines (46 loc) · 1.59 KB
/
admin.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
import logging
import os
import wsgiref.handlers
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext import db
from models import PlaygrubAccount
class AccountsAdmin(webapp.RequestHandler):
def post(self):
service = self.request.get('service')
user = self.request.get('user')
password = self.request.get('password')
q = PlaygrubAccount.gql('where service = :1', service)
if(q.count(1) > 0):
account = q.fetch(1)[0]
else:
account = PlaygrubAccount()
account.service = service
account.user = user
account.password = password
db.put(account)
q = PlaygrubAccount.all()
accounts = q.fetch(100)
template_values = {
'accounts': accounts,
}
path = os.path.join(os.path.dirname(__file__), 'html/admin_accounts.html')
self.response.out.write(template.render(path, template_values))
def get(self):
delete = self.request.get('delete')
if delete:
account = db.get(delete)
account.delete()
q = PlaygrubAccount.all()
accounts = q.fetch(100)
template_values = {
'accounts': accounts,
}
path = os.path.join(os.path.dirname(__file__), 'html/admin_accounts.html')
self.response.out.write(template.render(path, template_values))
def main():
application = webapp.WSGIApplication([('/admin/accounts', AccountsAdmin)],
debug=True)
wsgiref.handlers.CGIHandler().run(application)
if __name__ == '__main__':
main()