From 0b345c89de06d6c937985b96126a25517b445258 Mon Sep 17 00:00:00 2001 From: Victoria Earl Date: Fri, 17 Jun 2016 02:30:59 -0400 Subject: [PATCH 1/2] Fix dupe_badge_num check The dupe_badge_num sqlalchemy expression was malformed, so that it was returning ANY attendee with a matching badge number, including the one we were checking against. --- uber/model_checks.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/uber/model_checks.py b/uber/model_checks.py index 1192cc034..a3b58374f 100644 --- a/uber/model_checks.py +++ b/uber/model_checks.py @@ -264,7 +264,8 @@ def dealer_needs_group(attendee): @validation.Attendee def dupe_badge_num(attendee): - if attendee.badge_num != 0 and attendee.session.query(Attendee).filter(id != attendee.id)\ + if attendee.badge_num != 0 and attendee.session.query(Attendee)\ + .filter(Attendee.id != attendee.id)\ .filter_by(badge_type=attendee.badge_type, badge_num=attendee.badge_num).count(): return 'Another attendee already exists with that badge number!' From d2535129bce89b15a54d3681b597d25be3d152ea Mon Sep 17 00:00:00 2001 From: Victoria Earl Date: Fri, 17 Jun 2016 02:32:45 -0400 Subject: [PATCH 2/2] Only run badge_num checks if c.NUMBERED_BADGES Although theoretically events without numbered badges will never have numbered badges, data gets munged and this is not reliable. So we now only run checks on badge numbers if the event should care. --- uber/model_checks.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/uber/model_checks.py b/uber/model_checks.py index a3b58374f..b501c374d 100644 --- a/uber/model_checks.py +++ b/uber/model_checks.py @@ -264,7 +264,7 @@ def dealer_needs_group(attendee): @validation.Attendee def dupe_badge_num(attendee): - if attendee.badge_num != 0 and attendee.session.query(Attendee)\ + if c.NUMBERED_BADGES and attendee.badge_num != 0 and attendee.session.query(Attendee)\ .filter(Attendee.id != attendee.id)\ .filter_by(badge_type=attendee.badge_type, badge_num=attendee.badge_num).count(): return 'Another attendee already exists with that badge number!' @@ -272,15 +272,16 @@ def dupe_badge_num(attendee): @validation.Attendee def invalid_badge_num(attendee): - try: - badge_num = int(attendee.badge_num) - except: - return '{!r} is not a valid badge number'.format(attendee.badge_num) - else: - if attendee.badge_num != 0: - min_num, max_num = c.BADGE_RANGES[attendee.badge_type] - if not (min_num <= badge_num <= max_num): - return '{} badge numbers must fall within {} and {}'.format(attendee.badge_type_label, min_num, max_num) + if c.NUMBERED_BADGES: + try: + badge_num = int(attendee.badge_num) + except: + return '{!r} is not a valid badge number'.format(attendee.badge_num) + else: + if attendee.badge_num != 0: + min_num, max_num = c.BADGE_RANGES[attendee.badge_type] + if not (min_num <= badge_num <= max_num): + return '{} badge numbers must fall within {} and {}'.format(attendee.badge_type_label, min_num, max_num) @validation.MPointsForCash