-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
65 lines (50 loc) · 1.58 KB
/
app.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
import os
from flask import Flask
from flask import render_template
from flask import request
from flask.ext.sqlalchemy import SQLAlchemy
app = Flask(__name__)
if 'DATABASE_URL' in os.environ:
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URL']
db = SQLAlchemy(app)
class Registration(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(80))
email = db.Column(db.String(120), unique=True)
org = db.Column(db.String(80))
updates = db.Column(db.Boolean())
def __init__(self, name, email, org, updates):
self.name = name
self.email = email
self.org = org
self.updates = updates
def __repr__(self):
return '<Name %r>' % self.name
@app.route('/')
def home():
return render_template('index.html')
@app.route('/reg', methods=['POST'])
def reg():
error = False
name = request.form.get('name')
email = request.form.get('email')
org = request.form.get('org', '')
updates = request.form.get('updates') == 'yes'
if name and email:
try:
registration = Registration(name, email, org, updates)
db.session.add(registration)
db.session.commit()
except:
error = 'dupe'
else:
error = 'blank'
return render_template('thx.html', error=error)
@app.route('/robots.txt')
def robots():
res = app.make_response('User-agent: *\nAllow: /')
res.mimetype = 'text/plain'
return res
if __name__ == '__main__':
port = int(os.environ.get('PORT', 5000))
app.run(host='0.0.0.0', port=port)