#print "Number of columns:",rec.count()
records_merged = 0
while import_q.next():
+ qtestnewnetid = QSqlQuery(self.db)
+ qtestnewnetid.prepare("SELECT * FROM people WHERE netid = :netid")
+ qtestnewnetid.bindValue(":netid", import_q.value(col_netid) )
+ qtestnewnetid.exec_()
+ if qtestnewnetid.next(): # if the person's already in the DB, keep the old data
+ continue
q.prepare("INSERT INTO people (netid, forename, surname, email, birthday, phone, major, dorm, room, createtime, mtime, photo )"
"VALUES (:netid, :forename, :surname, :email, :birthday, :phone, :major, :dorm, :room, :createtime, :mtime, :photo )" )
q.bindValue(":netid", import_q.value(col_netid) )
def __init__(self, parent=None,db=None):
QWizard.__init__(self, parent)
self.db = db
- self.addPage(PageNetID())
- self.addPage(PageNewUserData())
+ self.addPage(PageNetID(self,self.db))
+ self.addPage(PageNewUserData(self))
self.addPage(PageCommit(self,self.db))
self.resize(400,500)
self.show()
from PyQt4.QtCore import *
from PyQt4.QtGui import *
+from PyQt4.QtSql import *
class PageNetID(QWizardPage):
- def __init__(self, parent=None):
+ def __init__(self, parent=None, db=None ):
QWizardPage.__init__(self,parent)
+ self.db = db
self.instructions = QLabel("&Enter your NetID:")
self.netid = QLineEdit()
self.instructions.setBuddy(self.netid)
self.disclaimer = QLabel("This information is being collected to be distributed to residents of the Clements, Lechner, and McFadden dorms for the 2009-2010 school year. By entering your NetID and other information into this database, you give permission for this information to be distributed to other residents who have also shared their personal information.\n\nThe information collected will be used to make the White Pages, a listing of contact information for residents of Clements, Lechner, and McFadden Halls, to be published later this year.")
self.disclaimer.setWordWrap(True)
+ self.dupelabel = QLabel()
self.registerField("netid*", self.netid)
self.grid = QGridLayout()
self.grid.addWidget(self.instructions,0,0)
self.grid.addWidget(self.netid,0,1)
self.grid.addWidget(self.disclaimer,1,0,1,2)
+ self.grid.addWidget(self.dupelabel,2,0,1,2)
self.setLayout(self.grid)
self.setTitle("Move-in Wizard")
self.setSubTitle("Enter your NetID:")
+ def validatePage(self):
+ netid = self.field("netid")
+ q = QSqlQuery()
+ q.prepare("SELECT * FROM people where netid = :netid")
+ q.bindValue(":netid", netid)
+ q.exec_()
+ if q.next():
+ print netid.toString(), "is already in the database"
+ self.dupelabel.setText( netid.toString() + QString(" is already in the database."))
+ return False
+ return True
+
if __name__ == "__main__":
a = QApplication([""])