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

Commit b4394f7

Browse files
authored
Merge pull request #47 from codewizardshq/ballot-names
include firstname+lastname on ballot API
2 parents 515ae0e + a4dc546 commit b4394f7

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

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)