Browse files

initial commit -- working and deployed

  • Loading branch information...
0 parents commit d278eee4234a4f223b00112771bbcb07a4bcd216 @progrium progrium committed Oct 29, 2009
Showing with 224 additions and 0 deletions.
  1. +4 −0 .gitignore
  2. +16 −0 app.yaml
  3. +11 −0 index.yaml
  4. +108 −0 main.py
  5. BIN static/dojo_icon.png
  6. BIN static/favicon.ico
  7. +2 −0 static/robots.txt
  8. +18 −0 static/style.css
  9. +29 −0 templates/base.html
  10. +25 −0 templates/main.html
  11. +11 −0 templates/success.html
4 .gitignore
@@ -0,0 +1,4 @@
+keys.py
+*.pyc
+**/*.pyc
+.DS_Store
16 app.yaml
@@ -0,0 +1,16 @@
+application: hackerdojo-signup
+version: 1
+runtime: python
+api_version: 1
+
+handlers:
+- url: /favicon.ico
+ static_files: static/favicon.ico
+ upload: static/favicon.ico
+- url: /robots.txt
+ static_files: static/robots.txt
+ upload: static/robots.txt
+- url: /static
+ static_dir: static
+- url: .*
+ script: main.py
11 index.yaml
@@ -0,0 +1,11 @@
+indexes:
+
+# AUTOGENERATED
+
+# This index.yaml is automatically updated whenever the dev_appserver
+# detects that a new type of query is run. If you want to manage the
+# index.yaml file manually, remove the above marker line (the line
+# saying "# AUTOGENERATED"). If you want to manage some indexes
+# manually, move them above the marker line. The index.yaml file is
+# automatically uploaded to the admin console when you next deploy
+# your application using appcfg.py.
108 main.py
@@ -0,0 +1,108 @@
+import wsgiref.handlers
+import time, hashlib, urllib, urllib2, re, os
+from google.appengine.ext import db
+from google.appengine.ext import webapp
+from google.appengine.api import urlfetch
+from google.appengine.ext.webapp import template
+
+try:
+ is_dev = os.environ['SERVER_SOFTWARE'].startswith('Dev')
+except:
+ is_dev = False
+
+import keys
+if is_dev:
+ SPREEDLY_ACCOUNT = 'hackerdojotest'
+ SPREEDLY_APIKEY = keys.hackerdojotest
+ PLAN_IDS = {'full': '1957'}
+else:
+ SPREEDLY_ACCOUNT = 'hackerdojo'
+ SPREEDLY_APIKEY = keys.hackerdojo
+ PLAN_IDS = {'full': '1987', 'hardship': '2537', 'supporter': '1988', 'director': '2539'}
+
+is_prod = not is_dev
+
+class Membership(db.Model):
+ first_name = db.StringProperty(required=True)
+ last_name = db.StringProperty(required=True)
+ email = db.StringProperty(required=True)
+ hash = db.StringProperty()
+ plan = db.StringProperty(required=True)
+ status = db.StringProperty(default='unpaid') # unpaid, active, canceled, pending (approval)
+ referrer = db.StringProperty()
+
+ created = db.DateTimeProperty(auto_now_add=True)
+ updated = db.DateTimeProperty(auto_now=True)
+
+class MainHandler(webapp.RequestHandler):
+ def get(self):
+ self.response.out.write(template.render('templates/main.html', {'is_prod': is_prod, 'plan': self.request.get('plan', 'full')}))
+
+ def post(self):
+ first_name = self.request.get('first_name')
+ last_name = self.request.get('last_name')
+ email = self.request.get('email')
+ plan = self.request.get('plan', 'full')
+
+ if not first_name or not last_name or not email:
+ self.response.out.write(template.render('templates/main.html', {'is_prod': is_prod,'message': "Sorry, we need all three fields."}))
+ else:
+ existing_member = Membership.all().filter('email =', email).get()
+ if existing_member:
+ if existing_member.status == 'unpaid':
+ existing_member.delete()
+ else:
+ self.response.out.write(template.render('templates/main.html', {'is_prod': is_prod,'message': "You're already in our system!"}))
+ return
+ m = Membership(first_name=first_name, last_name=last_name, email=email, plan=plan)
+ m.hash = hashlib.md5(m.email).hexdigest()
+ m.referrer = self.request.get('referrer')
+ m.put()
+ id = str(m.key().id())
+ username = "%s-%s-%s" % (m.first_name.lower(), m.last_name.lower(), id)
+ query_str = urllib.urlencode({'first_name': m.first_name, 'last_name': m.last_name, 'email': m.email, 'return_url': 'http://%s/success/%s' % (self.request.host, m.hash)})
+ self.redirect("https://spreedly.com/%s/subscribers/%s/subscribe/%s/%s?%s" % (SPREEDLY_ACCOUNT, id, PLAN_IDS[m.plan], username, query_str))
+
+class SuccessHandler(webapp.RequestHandler):
+ def get(self):
+ success_html = urlfetch.fetch("http://hackerdojo.pbworks.com/api_v2/op/GetPage/page/SubscriptionSuccess/_type/html").content
+ member = Membership.all().filter('hash =', self.request.path.split('/')[-1]).get()
+ if member:
+ success_html = success_html.replace('joining!', 'joining, %s!' % member.first_name)
+ is_prod = not is_dev
+ self.response.out.write(template.render('templates/success.html', locals()))
+
+class UpdateHandler(webapp.RequestHandler):
+ def post(self):
+ subscriber_ids = self.request.get('subscriber_ids').split(',')
+ for id in subscriber_ids:
+ uri = 'https://spreedly.com/api/v4/%s/subscribers/%s.xml' % (SPREEDLY_ACCOUNT, id)
+ auth_handler = urllib2.HTTPBasicAuthHandler()
+ auth_handler.add_password(realm='Web Password', uri=uri, user=SPREEDLY_APIKEY, passwd='X')
+ opener = urllib2.build_opener(auth_handler)
+ urllib2.install_opener(opener)
+ try:
+ f = urllib2.urlopen(uri)
+ body = f.read()
+ p = re.compile('<customer-id>(\d+)</customer-id>')
+ m = p.search(body)
+ if m:
+ member = Membership.get_by_id(int(m.group(1)))
+ if '<active type="boolean">true</active>' in body:
+ member.status = 'active'
+ member.put()
+ except:
+ pass
+ self.response.out.write("ok")
+
+
+
+def main():
+ application = webapp.WSGIApplication([
+ ('/', MainHandler),
+ ('/success.*', SuccessHandler),
+ ('/update', UpdateHandler),], debug=True)
+ wsgiref.handlers.CGIHandler().run(application)
+
+if __name__ == '__main__':
+ main()
BIN static/dojo_icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN static/favicon.ico
Binary file not shown.
2 static/robots.txt
@@ -0,0 +1,2 @@
+User-agent: *
+Allow: /
18 static/style.css
@@ -0,0 +1,18 @@
+body { font-family: Verdana,Arial,sans-serif; }
+#wrapper { margin-left: auto; margin-right: auto; width: 700px; }
+
+#header { margin-left: auto; margin-right: auto; width: 500px; height: 125px;}
+#header img { margin-right: 10px;}
+#header h1 { font-size: 42px; margin-top: 20px; padding-top: 10px; margin-bottom: 0px; padding-bottom: 0px;}
+#header h2 { font-size: x-large; margin: 0px; }
+
+.step span { color: white; background-color: #b10026; padding: 1px; padding-left: 4px; padding-right: 4px;}
+.step.inactive span { background-color: gray;}
+.step.inactive { color: gray; }
+
+h4 { margin-bottom: 0px;}
+
+table { margin-top: 50px;}
+table .label { text-align: right; width: 210px;}
+
+form div { margin-top: 10px; }
29 templates/base.html
@@ -0,0 +1,29 @@
+<html>
+ <head>
+ <title>Hacker Dojo Member Signup</title>
+ <link href="/static/style.css" type="text/css" rel="stylesheet" />
+ </head>
+ <body>
+ <div id="wrapper">
+ <div id="header">
+ <img src="/static/dojo_icon.png" style="float: left; " />
+ <h1>Hacker Dojo</h1>
+ <h2>Member Signup</h2>
+ </div>
+ <div id="content">
+ {% block content %}{% endblock %}
+ </div>
+ </div>
+ {% if is_prod %}
+ <script type="text/javascript">
+ var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
+ document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
+ </script>
+ <script type="text/javascript">
+ try {
+ var pageTracker = _gat._getTracker("UA-11332872-2");
+ pageTracker._trackPageview();
+ } catch(err) {}</script>
+ {% endif %}
+ </body>
+</html>
25 templates/main.html
@@ -0,0 +1,25 @@
+{% extends 'base.html' %}
+{% block content %}
+<h4>
+ <span class="step"><span>1</span> Member Information &rarr; </span>
+ <span class="step inactive"><span>2</span> Billing Information &rarr; </span>
+ <span class="step inactive"><span>3</span> Welcome to the Dojo!</span>
+</h4>
+
+<form action="/" method="post">
+ <input type="hidden" name="plan" value="{{ plan }}" />
+<table>
+ <tr><td class="label">First name:</td><td><input type="text" name="first_name" /></td></tr>
+ <tr><td class="label">Last name:</td><td><input type="text" name="last_name" /></td></tr>
+ <tr><td class="label">Email:</td><td><input type="text" name="email" /></td></tr>
+ {% if message %}<tr><td>&nbsp;</td><td style="color: red; font-size: smaller;">{{ message }}</td></tr>{% endif %}
+</table>
+<div style="font-size: smaller; margin-left: 216px;">How did you hear about us?<br />
+ <input type="text" name="referrer" /><br />
+ <input type="submit" value="Increment step &rarr;" style="font-size: large; margin-top: 25px;" /><br />
+ <span style="font-size: 11px">You will be taken to <a href="http://spreedly.com/">Spreedly</a> for payment.</span>
+</div>
+
+
+</form>
+{% endblock %}
11 templates/success.html
@@ -0,0 +1,11 @@
+{% extends 'base.html' %}
+{% block content %}
+<h4>
+ <span class="step inactive"><span>1</span> Member Information &rarr; </span>
+ <span class="step inactive"><span>2</span> Billing Information &rarr; </span>
+ <span class="step"><span>3</span> Welcome to the Dojo!</span>
+</h4>
+<div style="margin-left: 50px; padding-top: 10px;">
+{{ success_html }}
+</div>
+{% endblock %}

0 comments on commit d278eee

Please sign in to comment.