Example #1
0
class Tab1(Tab):
    def __init__(self, master):
        Tab.__init__(self, master, u"報到".encode('utf-8'))
        self.web = Web()
        self.db = DBController("/home/pi/pyconapac-rpi/db/pycon2015.db.nofacebook")
        self.reg_no = StringVar()
        self.nickname = StringVar()
        self.uid = StringVar()
        self.tshirt_wtime = StringVar()

        self.tab1_lbl_reg_no = Label(self, bg="red", fg="white", font=('Arial', 16), textvariable=sv_reg_no).pack(fill=X)
        self.tab1_lbl_nickname = Label(self, bg="green", fg="black", font=('Arial', 22), textvariable=sv_nickname).pack(fill=X)
        self.tab1_lbl_uid = Label(self, bg="blue", fg="white", font=('Arial', 20), textvariable=sv_uid).pack(fill=X)
        self.tab1_lbl_status = Label(self, bg="yellow", fg="black", font=('Arial', 22), textvariable=sv_regist_status).pack(side=LEFT, fill=BOTH, expand=YES)

    def load_profile(self, uid):
        print type(self).__name__ + "/" + inspect.stack()[0][3]
        try:
            result = self.web.infoQuery(uid)
            status = result['result']['regist_wtime'] if result['result']['regist_wtime'] != '0' else 'First Check-in'
            reg_no = result['result']['reg_no']
            nickname = result['result']['nickname']
            user_info = self.db.getInfoByReg(reg_no)
            sv_reg_no.set(reg_no + "/" + user_info.ticket_type.split(' ')[-1])
            sv_nickname.set(nickname)
            sv_uid.set(uid)

            sv_regist_status.set(status)
            result = self.web.registerUpdate(reg_no, uid)

            # user_info = self.web.infoQuery(uid)
            # sv_reg_no.set(str(user_info['result']['reg_no']))
            # sv_nickname.set(str(user_info['result']['nickname']))
            # sv_uid.set(str(user_info['result']['uid']))
            # result = self.web.registerUpdate(user_info['result']['reg_no'], uid)
            print result

            # if user_info.regist_wtime == None:
            #     self.db.checkIn(uid)

        except ValueError:
            sv_reg_no.set(VALUE_ERROR)
            sv_nickname.set(VALUE_ERROR)
            sv_uid.set(uid)
Example #2
0
class TestDBAccess(unittest.TestCase):
    def setUp(self):
        subprocess.call(['db/mkdb.sh'])
        conn = sqlite3.connect(DB_NAME)
        conn.isolation_level = None
        cursor = conn.cursor()
        cursor.execute("INSERT INTO regist (reg_no, fullname, nickname, uid, tshirt) VALUES ('01', 'John Dow', 'johndow', 'A1 B2', 'L')")
        cursor.execute("INSERT INTO regist (reg_no, fullname, nickname, uid, tshirt) VALUES ('02', 'Jane Dow', 'janedow', 'C3 D4', 'S')")
        conn.commit()
        self.db = DBController(DB_NAME)

    def tearDown(self):
        os.remove(DB_NAME)

    def test_checkIn(self):
        info = self.db.checkIn("A1 B2")
        self.assertIsNotNone(info.data)
        self.assertEqual("01", info.reg_no)
        self.assertEqual("A1 B2", info.uid)
        self.assertEqual("John Dow", info.fullname)
        self.assertEqual("johndow", info.nickname)
        self.assertIsNotNone(info.regist_wtime)

    def test_replace(self):
        info = self.db.getInfoByReg("02")
        self.assertIsNotNone(info.data)
        self.assertNotEqual("11 22", info.uid)
        info = self.db.pairUidByReg(info.reg_no, "11 22")
        self.assertEqual("11 22", info.uid)
        self.assertIsNotNone(info.regist_wtime)

    def test_tshirt(self):
        info = self.db.getInfoByUid("C3 D4")
        self.assertIsNotNone(info.data)
        self.assertIsNone(info.tshirt_wtime)
        info = self.db.setTshirtTimeByUid(info.uid)
        self.assertIsNotNone(info.tshirt_wtime)

    def test_needUpdate(self):
        self.db.checkIn("A1 B2")
        self.db.checkIn("C3 D4")
        infoList = self.db.getNeedUpdate()
        self.assertNotEqual(0, len(infoList))
        self.assertEqual("01", infoList[0].reg_no)
        self.assertEqual("A1 B2", infoList[0].uid)
        self.assertEqual("John Dow", infoList[0].fullname)
        self.assertEqual("johndow", infoList[0].nickname)
        self.assertFalse(infoList[0].update_status)
        self.assertEqual("02", infoList[1].reg_no)
        self.assertEqual("C3 D4", infoList[1].uid)
        self.assertEqual("Jane Dow", infoList[1].fullname)
        self.assertEqual("janedow", infoList[1].nickname)
        self.assertFalse(infoList[1].update_status)
        infoList = self.db.setUpdated(infoList)
        self.assertNotEqual(0, len(infoList))
        self.assertTrue(infoList[0].update_status)
        self.assertTrue(infoList[1].update_status)

    def test_getInfoByUids(self):
        uidList = ["A1 B2", "C3 D4"]
        infoList = self.db.getInfoByUids(uidList)
        self.assertNotEqual(0, len(infoList))
        self.assertEqual("A1 B2", infoList[0].uid)
        self.assertEqual("C3 D4", infoList[1].uid)
Example #3
0
class Tab3(Tab):
    def __init__(self, master):
        Tab.__init__(self, master, u"新增".encode('utf-8'))

        self.web = Web()
        self.db = DBController("/home/pi/pyconapac-rpi/db/pycon2015.db")
        self.reg_no = StringVar()
        self.nickname = StringVar()
        self.fullname = StringVar()
        self.uid = StringVar()
        self.pair_status = StringVar()
        self.is_reg_no = False

        self.tab3_fm1 = Frame(self)
        self.txt3_fm1 = Text(self.tab3_fm1, width=3, height=1, font=('Arial', 12))
        self.txt3_fm1.pack(side=TOP, fill=X, expand=YES)
        self.txt3_fm1.focus()

        self.tab3_btn1 = Button(self.tab3_fm1, text='OK')
        self.tab3_btn1.pack(side=TOP, anchor=W, fill=X, expand=YES)
        self.tab3_btn1.bind('<Button-1>', self.load_profile)
        self.tab3_fm1.pack(side=LEFT, fill=BOTH, expand=YES)

        self.tab3_fm2 = Frame(self)
        Label(self.tab3_fm2, bg="red", fg="white", width=12, font=('Arial', 16), textvariable=self.reg_no).pack(side=TOP, fill=BOTH, expand=YES)
        Label(self.tab3_fm2, bg="green", fg="black", width=12, font=('Arial', 10), textvariable=self.nickname).pack(side=TOP, fill=BOTH, expand=YES)
        Label(self.tab3_fm2, bg="blue", fg="white", width=12, font=('Arial', 16), textvariable=self.fullname).pack(side=TOP, fill=BOTH, expand=YES)
        self.tab3_fm2.pack(side=LEFT, padx=10)

        self.tab3_fm3 = Frame(self)
        self.tab3_lbl_uid = Label(self.tab3_fm3, bg="white", fg="black", width=10, font=('Arial', 12), textvariable=sv_uid).pack(side=TOP, anchor=W, fill=X, expand=YES)
        self.tab3_btn1 = Button(self.tab3_fm3, text='Pair', font=('Arial', 10))
        self.tab3_btn1.pack(side=LEFT, anchor=W)
        self.tab3_btn1.bind('<Button-1>', self.pair_uid)
        self.tab3_lbl_pair_status = Label(self.tab3_fm3, bg="yellow", fg="black", width=4, font=('Arial', 24), textvariable=self.pair_status).pack(side=LEFT, fill=BOTH, expand=YES)
        self.tab3_fm3.pack(side=LEFT, fill=BOTH, expand=YES)

    def clear_profile(self):
        self.reg_no.set("")
        self.nickname.set("")
        self.fullname.set("")
        self.txt3_fm1.delete("1.0", "end")

    def clear_pair(self):
        sv_uid.set("")
        self.pair_status.set("")


    def load_profile(self, button):
        print type(self).__name__ + "/" + inspect.stack()[0][3]
        global reg_no
        reg_no = self.txt3_fm1.get("1.0", "end")
        user_info = self.db.getInfoByReg(int(reg_no))
        reg_no = user_info.reg_no
        self.reg_no.set(str(user_info.reg_no) + "/" + user_info.ticket_type.split(' ')[-1])
        self.nickname.set(user_info.nickname)
        self.fullname.set(user_info.fullname)
        self.clear_pair()
        self.is_reg_no = True

    def pair_uid(self, button):
        print type(self).__name__ + "/" + inspect.stack()[0][3]
        # from nfc import NFC
        # NFC('/home/pi/3rd/libnfc-1.7.0-rc7/examples/nfc-poll').read()
        try :
            if self.is_reg_no != True:
                return
            result = self.web.registerUpdate(reg_no, uid)
            print result
            self.pair_status.set(result["status"])
            self.is_reg_no = False
        except NameError:
            print "NameError"
            self.pair_status.set("NameError")
        finally:
            self.clear_profile()
            sv_uid.set("")