-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
109 lines (84 loc) · 2.84 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import os
from datetime import datetime
from flask.ext.sqlalchemy import SQLAlchemy
from sqlalchemy.exc import IntegrityError
from flask import (
Flask,
render_template,
request,
flash,
redirect,
url_for
)
app = Flask(__name__)
app.secret_key = os.environ['FORGE_SECRET_KEY']
app.config.from_object(__name__)
@app.route('/')
def home():
return render_template('application.html')
@app.route('/apply', methods=['GET', 'POST'])
def apply():
if request.method == 'POST':
try:
hacker = Hacker.from_forms(request.form)
print hacker
db.session.add(hacker)
db.session.commit()
flash('Awesome! You should receive an email confirmation immediately')
return redirect(url_for('home'))
except IntegrityError:
flash('Oops. This email address has already been registered.')
return render_template('apply.html')
else:
return render_template('apply.html')
@app.route('/faq')
def faq():
return render_template('faq.html')
@app.route('/teach')
def teach():
if request.method == 'GET':
return render_template('teach.html')
else:
pass
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('DATABASE_URL')
if not app.config['SQLALCHEMY_DATABASE_URI']:
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['FORGE_DATABASE_URL']
db = SQLAlchemy(app)
# Models, models.
class Hacker(db.Model):
id = db.Column(db.Integer, primary_key=True)
# Personal.
fullname = db.Column(db.String, nullable=False)
email = db.Column(db.String, unique=True, nullable=False)
phone = db.Column(db.String, unique=True, nullable=False)
# Social.
github = db.Column(db.String(100), unique=True)
twitter = db.Column(db.String(100), unique=True)
linkedin = db.Column(db.String, unique=True)
# Bio and extras.
ambition = db.Column(db.Text, nullable=False)
program = db.Column(db.Text, nullable=False)
expectation = db.Column(db.Text, nullable=False)
created_at = db.Column(db.DateTime, default=datetime.utcnow)
def __init__(self, fullname, github, email, phone,
ambition, program, expectation, twitter=None, linkedin=None):
self.fullname = fullname
self.github = github
self.email = email
self.phone = phone
self.ambition = ambition
self.program = program
self.expectation = expectation
if twitter:
self.twitter = twitter
if linkedin:
self.linkedin = linkedin
@classmethod
def from_forms(cls, form):
return Hacker(**{
k: v if len(v.strip()) else None for k, v in form.items() if k != 'submit'
})
def __repr__(self):
return '<Hacker %r (%r)>' % (self.fullname, self.github)
if __name__ == '__main__':
app.run(debug=True)