forked from BobRupholdt/Sample-Python-Application
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·76 lines (62 loc) · 2.68 KB
/
main.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
#!/usr/bin/env python
import logging
import os
import httplib2
from google.appengine.dist import use_library
use_library('django', '1.2')
from events import FetchEvent
from models import CompanySubscription
from models import User
from google.appengine.ext import db
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp import util
from google.appengine.ext.webapp.util import run_wsgi_app
from xml.dom import minidom
appDirectLink = "https://www.appdirect.com/purchase/480"
class WelcomeHandler(webapp.RequestHandler):
def get(self):
path = os.path.join(os.path.dirname(__file__), 'welcome.html')
template_values = { 'appDirectLink' : appDirectLink }
self.response.out.write(template.render(path, template_values))
class MainHandler(webapp.RequestHandler):
def get(self):
user = users.get_current_user()
if user:
subscriptions = CompanySubscription.all()
logoutUrl = users.create_logout_url("/")
appUser = User.all()\
.filter('openid =', user.federated_identity()).get()
if appUser == None:
appUser = User.all()\
.filter('email =', user.email()).get()
if appUser:
sub = appUser.subscription
appUsers = User.all().filter('subscription = ', sub)
template_values = { 'appUser' : appUser, \
'companyName' : sub.name, \
'edition' : sub.edition, \
'appUsers' : appUsers, \
'logoutUrl' : logoutUrl }
path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(path, template_values))
else:
# Send the user to AppDirect to purchase the app
self.redirect(appDirectLink)
else:
# Log this user in
self.redirect(users.create_login_url("https://www.appdirect.com/openid/id"))
class EventHandler(webapp.RequestHandler):
def get(self):
self.post()
def post(self):
self.response.out.write(FetchEvent(self.request.get('token')))
def main():
application = webapp.WSGIApplication([('/', WelcomeHandler),\
('/main', MainHandler),\
('/event', EventHandler)],\
debug=True)
util.run_wsgi_app(application)
if __name__ == '__main__':
main()