diff --git a/db.py b/db.py index b3728b7..bfb382c 100644 --- a/db.py +++ b/db.py @@ -15,7 +15,7 @@ class User(Base): credit = Column(Integer) name_re = r"[a-z]+" - card_re = r"((ntnu)?[0-9]+)?" + card_re = r"(([Nn][Tt][Nn][Uu])?[0-9]+)?" def __init__(self, name, card, credit=0): self.name = name diff --git a/helpers.py b/helpers.py index cf14a3f..156d5d9 100644 --- a/helpers.py +++ b/helpers.py @@ -6,6 +6,7 @@ import os import signal def search_user(string, session): + string = string.lower() exact_match = session.query(User).filter(or_(User.name==string, User.card==string)).first() if exact_match: return exact_match diff --git a/text_based.py b/text_based.py index f78758b..bad0030 100755 --- a/text_based.py +++ b/text_based.py @@ -546,6 +546,7 @@ class AddUserMenu(Menu): self.print_header() username = self.input_str('Username (should be same as PVV username)> ', User.name_re, (1,10)) cardnum = self.input_str('Card number (optional)> ', User.card_re, (0,10)) + cardnum = cardnum.lower() user = User(username, cardnum) self.session.add(user) try: @@ -576,6 +577,7 @@ user (write an empty line to remove the card number). user.card = self.input_str('Card number (currently %s)> ' % card_str, User.card_re, (0,10), empty_string_is_none=True) + user.card = user.card.lower() try: self.session.commit() print 'User %s stored' % user.name