Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
Friendly error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitpaulk committed May 13, 2015
1 parent 40c456c commit 60cfdd8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion tests/py/test_teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_error_message_for_missing_fields(self):
del data['name']
r = self.post_new(data, expected=400)
assert self.db.one("SELECT COUNT(*) FROM teams") == 0
assert "Please fill out the 'name' field" in r.body
assert "Please fill out the 'Name' field" in r.body

class TestOldTeams(Harness):

Expand Down
16 changes: 12 additions & 4 deletions www/teams/create.json.spt
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,28 @@ from gratipay.models.team import Team
[---]
request.allow('POST')

field_names = {
'name': 'Name',
'homepage': 'Homepage',
'product_or_service': 'Product or Service',
'getting_paid': 'How do you share revenue',
'getting_involved': 'How can other people get involved'
}

if user.ANON:
raise Response(401, _("You must sign in to apply for a new team"))

if not request.body.get('agree_terms', False):
raise Response(400, _("Please agree to the terms and conditions"))
raise Response(400, _("Please agree to the terms and conditions"))

if request.method == 'POST':
fields = {}

# Validate inputs

for field in ['name', 'homepage', 'product_or_service', 'getting_paid', 'getting_involved']:
if not request.body.get(field, ''):
raise Response(400, _("Please fill out the '{0}' field", field))
for field in field_names.keys():
if not request.body.get(field, ''):
raise Response(400, _("Please fill out the '{0}' field", field_names[field]))

fields[field] = request.body.get(field, '')

Expand Down

0 comments on commit 60cfdd8

Please sign in to comment.