From: Drew Fisher Date: Sat, 22 Aug 2009 02:55:08 +0000 (-0500) Subject: Force new NetIDs to be unique. X-Git-Url: http://git.zarvox.org/shortlog/%7Bdate%7D?a=commitdiff_plain;h=7debca91ec86d2faf1eb2e46b1bde50d9b105def;p=wp3.git Force new NetIDs to be unique. We reject new users that have netids already in the database. When merging two databases, the current database is considered the master copy and a record from the merging database is discarded if there is a netid conflict. --- diff --git a/mainapp.py b/mainapp.py index 3b2d1ac..ae0102c 100644 --- a/mainapp.py +++ b/mainapp.py @@ -106,6 +106,12 @@ class MainApp (QMainWindow): #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) ) diff --git a/newpersonwizard.py b/newpersonwizard.py index 56ebde5..268e945 100644 --- a/newpersonwizard.py +++ b/newpersonwizard.py @@ -9,8 +9,8 @@ class NewPersonWizard(QWizard): 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() diff --git a/pagenetid.py b/pagenetid.py index 48b5447..6ec85a3 100644 --- a/pagenetid.py +++ b/pagenetid.py @@ -1,22 +1,38 @@ 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([""]) diff --git a/pagenewuserdata.py b/pagenewuserdata.py index 066a3a8..6f6a536 100644 --- a/pagenewuserdata.py +++ b/pagenewuserdata.py @@ -7,6 +7,7 @@ class PageNewUserData(QWizardPage): def __init__(self, parent=None): QWizardPage.__init__(self,parent) self.setCommitPage(True) + self.setButtonText(QWizard.CommitButton, "Next") # Create all the subwidgets self.year_lab = QLabel("Year:") self.month_lab = QLabel("Month:")