Fikset noe problemer med store/små bokstaver.

Det ble egentlig gjort for lenge siden, men ble ikke commitet da.
This commit is contained in:
Øystein Ingmar Skartsæterhagen 2010-11-24 16:24:52 +00:00
parent 666c301e14
commit 52198031cd
3 changed files with 4 additions and 1 deletions

2
db.py
View File

@ -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

View File

@ -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

View File

@ -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