]> git.zarvox.org Git - wp3.git/commitdiff
Force new NetIDs to be unique.
authorDrew Fisher <drew.m.fisher@gmail.com>
Sat, 22 Aug 2009 02:55:08 +0000 (21:55 -0500)
committerDrew Fisher <drew.m.fisher@gmail.com>
Sat, 22 Aug 2009 02:55:08 +0000 (21:55 -0500)
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.

mainapp.py
newpersonwizard.py
pagenetid.py
pagenewuserdata.py

index 3b2d1ac24603f3b08a9c0c8183642785baa1ad9e..ae0102c264accc9e813867d08f73ba673af5db67 100644 (file)
@@ -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) )
index 56ebde53b9dcd9830ffcc84a2f61971d6240e66e..268e945c459bbc2eaa3b374e8c2eb7dd4866d6a9 100644 (file)
@@ -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()
index 48b5447181742d1f13afa5bef24739af84febf78..6ec85a3ef7b571c59bbd6b0434830e9398ef27b0 100644 (file)
@@ -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([""])
index 066a3a8517a3fa23920f04885e3e87e74df5cd8a..6f6a536accd1b12fb7214f5fb2a1886f57cf4fca 100644 (file)
@@ -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:")