Skip to content
This repository was archived by the owner on Dec 8, 2022. It is now read-only.

Commit e9cfacc

Browse files
committed
Merge branch 'voting-and-design' of https://github.com/codewizardshq/code-challenge into voting-and-design
2 parents 0df12b6 + 905dce3 commit e9cfacc

File tree

4 files changed

+23
-16
lines changed

4 files changed

+23
-16
lines changed

CodeChallenge/__init__.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import os
2+
import re
23

34
import sentry_sdk
4-
from flask import Flask, jsonify, make_response, send_from_directory, redirect
5+
from flask import Flask, jsonify, make_response, send_from_directory
56
from flask_cors import CORS
67
from sentry_sdk.integrations.flask import FlaskIntegration
78
from werkzeug.middleware.proxy_fix import ProxyFix
@@ -22,6 +23,7 @@
2223
from .manage import add_question, del_question # NoQA
2324
from .models import db, init_db # NoQA
2425

26+
STATIC_FILES = re.compile(r"\.(ico|png|xml|json)$")
2527

2628
# Globally accessible libraries
2729

@@ -93,24 +95,12 @@ def send_images(path):
9395
def send_assets(path):
9496
return send_from_directory("assets", path)
9597

96-
@app.route("/landing", defaults={"path": ""})
97-
@app.route("/landing/<path:path>")
98-
def send_landing(path):
99-
100-
# if core.current_rank() != -1:
101-
# return redirect("/")
102-
103-
if path:
104-
return send_from_directory("../landing/", path)
105-
return send_from_directory("../landing/", "index.html")
106-
10798
@app.route("/", defaults={"path": ""})
10899
@app.route("/<path:path>")
109100
def catch_all(path):
110101

111-
# show landing page
112-
if core.current_rank() == -1 and (not path or path == "home"):
113-
return redirect("/landing")
102+
if STATIC_FILES.search(path):
103+
return send_from_directory(app.config["DIST_DIR"], path)
114104

115105
return send_from_directory(app.config["DIST_DIR"], "index.html")
116106

CodeChallenge/api/vote.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,21 @@ def get_contestants():
4848

4949
contestants = []
5050
for ans in p.items: # type: Answer
51+
52+
display = None
53+
if ans.user.studentfirstname \
54+
and ans.user.studentlastname:
55+
display = f"{ans.user.studentfirstname} " \
56+
f"{ans.user.studentlastname[0]}."
57+
5158
contestants.append(dict(
5259
id=ans.id,
5360
text=ans.text,
5461
numVotes=len(ans.votes),
62+
firstName=ans.user.studentfirstname,
63+
lastName=ans.user.studentlastname,
64+
username=ans.user.username,
65+
display=display
5566
))
5667

5768
return jsonify(

CodeChallenge/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class Answer(db.Model):
3636
text = db.Column(db.String(2000))
3737
correct = db.Column(db.Boolean)
3838
question = db.relationship("Question", lazy=True, uselist=False)
39+
user = db.relationship("Users", lazy=True, uselist=False)
3940
votes = db.relationship("Vote", cascade="all,delete",
4041
lazy=True, uselist=True)
4142

tests/test_question.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def register(client, email, username, password, firstname, lastname, studentemai
9090
return client.post("/api/v1/users/register", json=dict(
9191
username=username, parentEmail=email, password=password,
9292
parentFirstName=firstname, parentLastName=lastname, DOB="1994-04-13",
93-
studentEmail=studentemail
93+
studentEmail=studentemail, studentFirstName="Sam", studentLastName="Hoffman"
9494
), follow_redirects=True)
9595

9696

@@ -364,6 +364,11 @@ def test_vote_ballot(client_challenge_lastq):
364364
assert "id" in items[0]
365365
assert "numVotes" in items[0]
366366
assert "text" in items[0]
367+
assert items[0]["firstName"] == "Sam"
368+
assert items[0]["lastName"] == "Hoffman"
369+
assert items[0]["username"] == "cwhqsam"
370+
assert items[0]["display"] == "Sam H."
371+
367372
VALID_ANSWER = items[0]["id"]
368373

369374

0 commit comments

Comments
 (0)