mlh api to v3, shirt size and needs
This commit is contained in:
parent
872212ad49
commit
e9931fb723
3 changed files with 89 additions and 31 deletions
53
flask_app.py
53
flask_app.py
|
@ -35,6 +35,8 @@ class Hacker(db.Model):
|
|||
first_name = db.Column(db.String(100))
|
||||
last_name = db.Column(db.String(100))
|
||||
email = db.Column(db.String(100))
|
||||
shirt_size = db.Column(db.String(4))
|
||||
special_needs = db.Column(db.String(300))
|
||||
|
||||
|
||||
class AutoPromoteKeys(db.Model):
|
||||
|
@ -82,10 +84,36 @@ def resumepost():
|
|||
session['mymlh']['id']) + '.' + resume.filename.split('.')[-1].lower()
|
||||
filename = secure_filename(filename)
|
||||
resume.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
|
||||
return "Resume uploaded!"
|
||||
return 'Resume uploaded! <a href="/dashboard">Return to dashboard</a>'
|
||||
return "Something went wrong. If this keeps happening, slack message @bkayastha"
|
||||
|
||||
|
||||
@app.route('/shirtpost', methods=['GET'])
|
||||
def shirtpost():
|
||||
if not REGISTRATION_OPEN:
|
||||
return 'Registration is currently closed.', 403
|
||||
if not is_logged_in():
|
||||
return 'Not signed in'
|
||||
|
||||
"""MLH removed t-shirt and accommodations fields of profile in V3, this is our hacky substitute"""
|
||||
if request.method == 'GET':
|
||||
size = request.args.get('size')
|
||||
special_needs = request.args.get('special_needs')
|
||||
id = session['mymlh']['id']
|
||||
|
||||
upd = {}
|
||||
if size:
|
||||
upd['shirt_size'] = size
|
||||
if special_needs:
|
||||
upd['special_needs'] = special_needs
|
||||
|
||||
if db.session.query(db.exists().where(Hacker.mlh_id == id)).scalar():
|
||||
db.session.query(Hacker).filter(Hacker.mlh_id == id).update(upd)
|
||||
db.session.commit()
|
||||
return 'Info saved! <a href="../dashboard">Return to dashboard</a>'
|
||||
return "Something went wrong. If this keeps happening, email mikel@wpi.edu"
|
||||
|
||||
|
||||
@app.route('/register', methods=['GET', 'POST'])
|
||||
def register():
|
||||
if not REGISTRATION_OPEN:
|
||||
|
@ -103,7 +131,7 @@ def register():
|
|||
return redirect(
|
||||
'https://my.mlh.io/oauth/authorize?client_id=' + api_keys['mlh']['client_id'] + '&redirect_uri=' +
|
||||
api_keys['mlh'][
|
||||
'callback'] + '&response_type=code&scope=email+phone_number+demographics+birthday+education+event')
|
||||
'callback'] + '&response_type=code&scope=email+phone_number+demographics+birthday+education')
|
||||
|
||||
if is_logged_in():
|
||||
return render_template('register.html', name=session['mymlh']['first_name'])
|
||||
|
@ -117,8 +145,9 @@ def register():
|
|||
|
||||
if oauth_redirect.status_code == 200:
|
||||
access_token = json.loads(oauth_redirect.text)['access_token']
|
||||
user_info_request = requests.get('https://my.mlh.io/api/v2/user.json?access_token=' + access_token)
|
||||
user_info_request = requests.get('https://my.mlh.io/api/v3/user.json?access_token=' + access_token)
|
||||
if user_info_request.status_code == 200:
|
||||
print(user_info_request.text)
|
||||
user = json.loads(user_info_request.text)['data']
|
||||
session['mymlh'] = user
|
||||
if db.session.query(db.exists().where(Hacker.mlh_id == user['id'])).scalar():
|
||||
|
@ -247,7 +276,7 @@ def admin():
|
|||
else:
|
||||
majors[hacker['major']] += 1
|
||||
|
||||
shirt_count[hacker['shirt_size'].split(' - ')[1].lower()] += 1
|
||||
#shirt_count[hacker['shirt_size'].split(' - ')[1].lower()] += 1
|
||||
|
||||
hackers.append({
|
||||
'checked_in': obj.checked_in,
|
||||
|
@ -259,15 +288,15 @@ def admin():
|
|||
'first_name': hacker['first_name'],
|
||||
'last_name': hacker['last_name'],
|
||||
'phone_number': hacker['phone_number'],
|
||||
'dietary_restrictions': hacker['dietary_restrictions'],
|
||||
'special_needs': hacker['special_needs'],
|
||||
#'dietary_restrictions': hacker['dietary_restrictions'],
|
||||
#'special_needs': hacker['special_needs'],
|
||||
'school': hacker['school']
|
||||
})
|
||||
|
||||
return render_template('admin.html', hackers=hackers, total_count=total_count, waitlist_count=waitlist_count,
|
||||
check_in_count=check_in_count, shirt_count=shirt_count, female_count=female_count,
|
||||
male_count=male_count, schools=schools, majors=majors,
|
||||
mlh_url='https://my.mlh.io/api/v2/users.json?client_id=' + api_keys['mlh'][
|
||||
mlh_url='https://my.mlh.io/api/v3/users.json?client_id=' + api_keys['mlh'][
|
||||
'client_id'] + '&secret=' + api_keys['mlh'][
|
||||
'secret'])
|
||||
|
||||
|
@ -443,8 +472,10 @@ def dashboard():
|
|||
if not is_logged_in():
|
||||
return redirect(url_for('register'))
|
||||
|
||||
hacker = db.session.query(Hacker).filter(Hacker.mlh_id == session['mymlh']['id']).one_or_none()
|
||||
print(hacker)
|
||||
return render_template('dashboard.html', name=session['mymlh']['first_name'], id=session['mymlh']['id'],
|
||||
admin=is_admin())
|
||||
admin=is_admin(), shirt_size=hacker.shirt_size, special_needs=hacker.special_needs)
|
||||
|
||||
@app.route('/tos', methods=['GET'])
|
||||
def tos():
|
||||
|
@ -512,7 +543,7 @@ def get_mlh_user(mlh_id):
|
|||
if not isinstance(mlh_id, int):
|
||||
mlh_id = int(mlh_id)
|
||||
req = requests.get(
|
||||
'https://my.mlh.io/api/v2/users.json?client_id=' + api_keys['mlh']['client_id'] + '&secret=' + api_keys['mlh'][
|
||||
'https://my.mlh.io/api/v3/users.json?client_id=' + api_keys['mlh']['client_id'] + '&secret=' + api_keys['mlh'][
|
||||
'secret'])
|
||||
if req.status_code == 200:
|
||||
hackers = req.json()['data']
|
||||
|
@ -526,7 +557,7 @@ def get_mlh_users():
|
|||
num_pages = 1
|
||||
users = []
|
||||
while page_index <= num_pages:
|
||||
req = requests.get('https://my.mlh.io/api/v2/users.json?client_id={client_id}&secret={secret}&page={page}'.format(
|
||||
req = requests.get('https://my.mlh.io/api/v3/users.json?client_id={client_id}&secret={secret}&page={page}'.format(
|
||||
client_id=api_keys['mlh']['client_id'],
|
||||
secret=api_keys['mlh']['secret'],
|
||||
page=page_index
|
||||
|
@ -568,4 +599,4 @@ def allowed_file(filename):
|
|||
|
||||
if __name__ == '__main__':
|
||||
app.run(host=SERVER_LISTEN_ADDR, port=SERVER_PORT, threaded=True)
|
||||
|
||||
|
||||
|
|
|
@ -7,30 +7,57 @@
|
|||
<div class="row center justify-content-center" style="margin-top: 10%;">
|
||||
<h1>Hi {{ name }}!</h1>
|
||||
{% if waitlisted %}
|
||||
<h1>You are waitlisted, if space opens up we ill let you know...</h1>
|
||||
<h1>You are waitlisted, if space opens up we will let you know...</h1>
|
||||
{% else %}
|
||||
<h1>You are fully registered! We look forward to seeing you!</h1>
|
||||
Let us know if you have any questions by sending them to hack@wpi.edu
|
||||
<h1>You are fully registered! We look forward to seeing you!</h1>
|
||||
Let us know if you have any questions by sending them to hack@wpi.edu
|
||||
<br>
|
||||
Forgot to upload your resume while registering? No worries, submit it below.
|
||||
</div>
|
||||
<div class="row center justify-content-center" style="background-color: #EE6E73; padding: 20;">
|
||||
<form method="get" action="/shirtpost">
|
||||
<br>
|
||||
Forgot to upload your resume while registering? No worries, submit it here:
|
||||
</div>
|
||||
<div class="row center justify-content-center">
|
||||
<form method="post" action="/resumepost" enctype="multipart/form-data">
|
||||
<p><b>If you'd like, add your resume to send to sponsors... </b></p>
|
||||
<div class="file-field input-field">
|
||||
<div class="btn">
|
||||
<span>File</span>
|
||||
<input id="resume" name="resume" type="file"/>
|
||||
</div>
|
||||
<div class="file-path-wrapper">
|
||||
<input class="file-path validate" type="text">
|
||||
</div>
|
||||
<p><b>Optional Info:</b></p>
|
||||
<div>
|
||||
<p>Shirt Size (Currently selected: {{shirt_size.upper()}})</p>
|
||||
<input type="radio" id="shirtxs" name="size" value="xs">
|
||||
<label for="shirtxs">XS</label>
|
||||
<input type="radio" id="shirts" name="size" value="s">
|
||||
<label for="shirts">S</label>
|
||||
<input type="radio" id="shirtm" name="size" value="m">
|
||||
<label for="shirtm">M</label>
|
||||
<input type="radio" id="shirtl" name="size" value="l">
|
||||
<label for="shirtl">L</label>
|
||||
<input type="radio" id="shirtxl" name="size" value="xl">
|
||||
<label for="shirtxl">XL</label>
|
||||
<input type="radio" id="shirtxxl" name="size" value="xxl">
|
||||
<label for="shirtxxl">XXL</label>
|
||||
<input type="radio" id="no" name="size" value="no">
|
||||
<label for="no">Don't want one</label>
|
||||
<p>Special Needs/Accommodations:</p>
|
||||
<input type="text" name="special_needs" id="special_needs" value="{{ special_needs }}">
|
||||
</div>
|
||||
<input name="submit" class="btn btn-lg btn-primary btn-invert" type="submit" value="Submit"/>
|
||||
<br><br>
|
||||
<input name="save" class="btn btn-lg btn-primary btn-invert" type="submit" value="Save"/>
|
||||
<br><br><br>
|
||||
</form>
|
||||
</div>
|
||||
<div class="row center justify-content-center">
|
||||
<form method="post" action="/resumepost" enctype="multipart/form-data">
|
||||
<p><b>If you'd like, add your resume to send to sponsors... </b></p>
|
||||
<div class="file-field input-field">
|
||||
<div class="btn">
|
||||
<span>File</span>
|
||||
<input id="resume" name="resume" type="file"/>
|
||||
</div>
|
||||
<div class="file-path-wrapper">
|
||||
<input class="file-path validate" type="text">
|
||||
</div>
|
||||
</div>
|
||||
<input name="submit" class="btn btn-lg btn-primary btn-invert" type="submit" value="Submit"/>
|
||||
</form>
|
||||
{% endif %}
|
||||
<br>
|
||||
|
||||
</div>
|
||||
{% if admin %}
|
||||
<br>
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
<a class="navbar-brand" href="/">HACK@WPI</a>
|
||||
</div>
|
||||
<ul class="nav justify-content-end">
|
||||
<li class="nav-item">
|
||||
<!-- <li class="nav-item">
|
||||
{% if registration_open or registration_open is not defined %}
|
||||
<a class="nav-link active" href="/register">Register</a>
|
||||
{% else %}
|
||||
|
@ -31,7 +31,7 @@
|
|||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="../static/assets/Hack@WPI-SponsorshipInformation-2020.pdf">Sponsorship Packet</a>
|
||||
</li>
|
||||
</li> -->
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="https://static.mlh.io/docs/mlh-code-of-conduct.pdf">Code of Conduct</a>
|
||||
</li>
|
||||
|
|
Loading…
Add table
Reference in a new issue