RFID support

This commit is contained in:
Terje Schjelderup 2011-04-12 13:58:16 +00:00
parent 2c6a121e21
commit 20d3964900
5 changed files with 31 additions and 13 deletions

View File

@ -1,4 +1,4 @@
db_url = 'postgresql://torjehoa_dibblerdummy:1234@postgres/torjehoa_dibblerdummy' db_url = 'postgresql://terjesc_dibblerdummy:terjesc_dibblerdummy@postgres/terjesc_dibblerdummy'
quit_allowed = True quit_allowed = True
stop_allowed = False stop_allowed = False
show_tracebacks = True show_tracebacks = True

7
db.py
View File

@ -12,16 +12,21 @@ class User(Base):
__tablename__ = 'users' __tablename__ = 'users'
name = Column(String(10), primary_key=True) name = Column(String(10), primary_key=True)
card = Column(String(10)) card = Column(String(10))
rfid = Column(String(10))
credit = Column(Integer) credit = Column(Integer)
name_re = r"[a-z]+" name_re = r"[a-z]+"
card_re = r"(([Nn][Tt][Nn][Uu])?[0-9]+)?" card_re = r"(([Nn][Tt][Nn][Uu])?[0-9]+)?"
rfid_re = r"[0-9]+"
def __init__(self, name, card, credit=0): def __init__(self, name, card, rfid, credit=0):
self.name = name self.name = name
if card == '': if card == '':
card = None card = None
self.card = card self.card = card
if rfid == '':
rfid = None
self.rfid = rfid
self.credit = credit self.credit = credit
def __repr__(self): def __repr__(self):

View File

@ -7,11 +7,12 @@ import signal
def search_user(string, session): def search_user(string, session):
string = string.lower() string = string.lower()
exact_match = session.query(User).filter(or_(User.name==string, User.card==string)).first() exact_match = session.query(User).filter(or_(User.name==string, User.card==string, User.rfid==string)).first()
if exact_match: if exact_match:
return exact_match return exact_match
user_list = session.query(User).filter(or_(User.name.ilike('%'+string+'%'), user_list = session.query(User).filter(or_(User.name.ilike('%'+string+'%'),
User.card.ilike('%'+string+'%'))).all() User.card.ilike('%'+string+'%'),
User.rfid.ilike('%'+string+'%'))).all()
return user_list return user_list
def search_product(string, session): def search_product(string, session):
@ -39,6 +40,8 @@ def system_user_exists(username):
def guess_data_type(string): def guess_data_type(string):
if string.startswith('ntnu') and string[4:].isdigit(): if string.startswith('ntnu') and string[4:].isdigit():
return 'card' return 'card'
if string.isdigit() and len(string) == 10:
return 'rfid'
if string.isdigit() and len(string) in [8,13]: if string.isdigit() and len(string) in [8,13]:
return 'bar_code' return 'bar_code'
# if string.isdigit() and len(string) > 5: # if string.isdigit() and len(string) > 5:

View File

@ -253,7 +253,7 @@ class Menu():
selected_thing = argmax(result_values) selected_thing = argmax(result_values)
if results[selected_thing] == []: if results[selected_thing] == []:
thing_for_type = {'card': 'user', 'username': 'user', thing_for_type = {'card': 'user', 'username': 'user',
'bar_code': 'product'} 'bar_code': 'product', 'rfid': 'rfid'}
type_guess = guess_data_type(search_str) type_guess = guess_data_type(search_str)
if type_guess != None and thing_for_type[type_guess] in add_nonexisting: if type_guess != None and thing_for_type[type_guess] in add_nonexisting:
return self.search_add(search_str) return self.search_add(search_str)
@ -602,7 +602,8 @@ class AddUserMenu(Menu):
username = self.input_str('Username (should be same as PVV username)> ', User.name_re, (1,10)) 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 = self.input_str('Card number (optional)> ', User.card_re, (0,10))
cardnum = cardnum.lower() cardnum = cardnum.lower()
user = User(username, cardnum) rfid = self.input_str('RFID (optional)> ', User.rfid_re, (0,10))
user = User(username, cardnum, rfid)
self.session.add(user) self.session.add(user)
try: try:
self.session.commit() self.session.commit()
@ -616,10 +617,10 @@ class EditUserMenu(Menu):
def __init__(self): def __init__(self):
Menu.__init__(self, 'Edit user', uses_db=True) Menu.__init__(self, 'Edit user', uses_db=True)
self.help_text = ''' self.help_text = '''
The only editable part of a user is its card number. The only editable part of a user is its card number and rfid.
First select an existing user, then enter a new card number for that First select an existing user, then enter a new card number for that
user (write an empty line to remove the card number). user, then rfid (write an empty line to remove the card number or rfid).
''' '''
def _execute(self): def _execute(self):
@ -632,7 +633,15 @@ user (write an empty line to remove the card number).
user.card = self.input_str('Card number (currently %s)> ' % card_str, user.card = self.input_str('Card number (currently %s)> ' % card_str,
User.card_re, (0,10), User.card_re, (0,10),
empty_string_is_none=True) empty_string_is_none=True)
user.card = user.card.lower() if user.card:
user.card = user.card.lower()
rfid_str = '"%s"' % user.rfid
if user.rfid == None:
rfid_str = 'empty'
user.rfid = self.input_str('RFID (currently %s)> ' % rfid_str,
User.rfid_re, (0,10),
empty_string_is_none=True)
try: try:
self.session.commit() self.session.commit()
print 'User %s stored' % user.name print 'User %s stored' % user.name
@ -699,9 +708,10 @@ class ShowUserMenu(Menu):
def _execute(self): def _execute(self):
self.print_header() self.print_header()
user = self.input_user('User name or card number> ') user = self.input_user('User name, card number or RFID> ')
print 'User name: %s' % user.name print 'User name: %s' % user.name
print 'Card number: %s' % user.card print 'Card number: %s' % user.card
print 'RFID: %s' % user.rfid
print 'Credit: %s kr' % user.credit print 'Credit: %s kr' % user.credit
selector = Selector('What do you want to know about %s?' % user.name, selector = Selector('What do you want to know about %s?' % user.name,
items=[('transactions', 'Everything (list of all transactions)'), items=[('transactions', 'Everything (list of all transactions)'),

6
ui.py
View File

@ -125,13 +125,13 @@ class ChargeMenu(SubMenu):
self.textwindow.border() self.textwindow.border()
self.amountwindow.border() self.amountwindow.border()
if self.marked == 0: if self.marked == 0:
self.textwindow.addstr(0,1, "[Username or card number]",curses.A_REVERSE) self.textwindow.addstr(0,1, "[Username, card number or RFID]",curses.A_REVERSE)
self.amountwindow.addstr(0,1,"[Amount to be transferred]") self.amountwindow.addstr(0,1,"[Amount to be transferred]")
elif self.marked == 1: elif self.marked == 1:
self.textwindow.addstr(0,1, "[Username or card number]") self.textwindow.addstr(0,1, "[Username, card number or RFID]")
self.amountwindow.addstr(0,1,"[Amount to be transferred]",curses.A_REVERSE) self.amountwindow.addstr(0,1,"[Amount to be transferred]",curses.A_REVERSE)
else: else:
self.textwindow.addstr(0,1, "[Username or card number]") self.textwindow.addstr(0,1, "[Username, card number or RFID]")
self.amountwindow.addstr(0,1,"[Amount to be transferred]") self.amountwindow.addstr(0,1,"[Amount to be transferred]")
self.resultview.draw() self.resultview.draw()
self.textwindow.addstr(1,1,self.search_text) self.textwindow.addstr(1,1,self.search_text)