PageRenderTime 21ms CodeModel.GetById 10ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/iGoOut/admin.py

http://igoout.googlecode.com/
Python | 62 lines | 49 code | 13 blank | 0 comment | 9 complexity | f05ffb7b3f893d30a3441474df687527 MD5 | raw file
 1from db_model import Person, Site, Plan
 2from google.appengine.ext import webapp
 3
 4class Admin(webapp.RequestHandler):
 5
 6	def getPersonNames(self):
 7		names = []
 8		for person in Person.all():
 9			names.append(person.name)
10		return names
11
12	def getPlans(self):
13		plans = []
14		for plan in Plan.all():
15			plans.append("person: %s, site: %s, date: %s" %
16			  (plan.person.name, plan.site.name, plan.date))
17		return plans
18
19	def get(self):
20
21		self.response.out.write("People = %s" % self.getPersonNames())
22		self.response.out.write("<br>")
23		self.response.out.write("Plans = %s" % self.getPlans())
24
25
26from google.appengine.ext import webapp
27from google.appengine.api import users
28
29class AdminServer(webapp.RequestHandler):
30
31	def get(self):
32
33		if not users.GetCurrentUser():
34			loginUrl = users.CreateLoginURL(self.request.uri)
35			self.response.out.write('<a href="%s">Login</a>' % loginUrl)
36			return
37
38		if not users.IsCurrentUserAdmin():
39			self.response.out.write('You must be an admin to view this page.')
40			return
41
42		self._handleRequest()
43 
44	def _handleRequest(self):
45		"""Invokes methods from the Admin class based on the 'action' parameter"""
46		admin = Admin()
47		action = self.request.get('action')
48		if action == 'init':
49			admin.initGifts()
50			admin.initGiftTransactions()
51			msg = "Gifts have been initialized, gift transactions have been cleared."
52			self.response.out.write(msg)
53		elif action == 'list':
54			self.response.out.write("Gifts = %s" % admin.getGiftNames())
55			self.response.out.write("<br>")
56			self.response.out.write("Gift Transactions = %s" % admin.getGiftTransactions())
57		else:
58			html = []
59			html.append('<a href="/admin?action=init">Initialize datastore</a><br>')
60			html.append('<a href="/admin?action=list">List all data in datastore</a>')
61			self.response.out.write(''.join(html))
62