From: Drew Fisher Date: Fri, 3 Jul 2009 07:15:30 +0000 (-0500) Subject: Use QWizard to create the new person wizard. Integrated LDAP lookup. No return... X-Git-Url: http://git.zarvox.org/dispatcher.js?a=commitdiff_plain;h=0802b62497c3ecf5b6d2b3d59cfd697689b27c91;p=wp3.git Use QWizard to create the new person wizard. Integrated LDAP lookup. No return values yet. --- diff --git a/ldapsearcher.py b/ldapsearcher.py index cac4ac5..5a2bb91 100644 --- a/ldapsearcher.py +++ b/ldapsearcher.py @@ -6,7 +6,7 @@ class LDAPSearcher(): who = "" cred = "" self.l = ldap.open(server) - self.l.simple_bind_s(who, cred) + self.l.simple_bind(who, cred) #print "bound successfully" def lookup(self,username=""): @@ -16,17 +16,21 @@ class LDAPSearcher(): retrieve_attributes = ["sn", "givenName", "mail", "major", "classification"] count = 0 result_set = [] - timeout = 0 + all = 0 + timeout = 5.0 toreturn = {} #print "searching" result_id = self.l.search(base, scope, filter, retrieve_attributes) - while 1: - result_type, result_data = self.l.result(result_id, timeout) - if (result_data == []): - break - else: - if result_type == ldap.RES_SEARCH_ENTRY: - result_set.append(result_data) + while True: + try: + result_type, result_data = self.l.result(result_id, all, timeout) + if (result_data == []): + break + else: + if result_type == ldap.RES_SEARCH_ENTRY: + result_set.append(result_data) + except ldap.TIMEOUT: + return { "netid" : username } if len(result_set) == 0: # print "No matching NetID" return {} diff --git a/ldapstep.py b/ldapstep.py deleted file mode 100644 index 0de4740..0000000 --- a/ldapstep.py +++ /dev/null @@ -1,23 +0,0 @@ -from PyQt4 import QtCore -from PyQt4.QtGui import * - -from ldapsearcher import LDAPSearcher - -class LDAPStep(QWidget): - def __init__(self, parent=None): - QWidget.__init__(self,parent) - self.title = QLabel("

Looking you up in LDAP...

") - self.grid = QGridLayout() - self.grid.addWidget(self.title,0,0,1,1) - self.setLayout(self.grid) - self.ldap = LDAPSearcher() - self.data = {} - - def lookup(self, netid=""): - self.data = self.ldap.lookup(netid) - print self.data - self.emit(QtCore.SIGNAL("ready()")) - self.emit(QtCore.SIGNAL("submit()")) - # Later we'll actually do something with this data - - diff --git a/netidstep.py b/netidstep.py deleted file mode 100644 index 1c83fb5..0000000 --- a/netidstep.py +++ /dev/null @@ -1,30 +0,0 @@ -from PyQt4 import QtCore -from PyQt4.QtGui import * - -class NetIDStep(QWidget): - def __init__(self, parent=None): - QWidget.__init__(self,parent) - self.title = QLabel("

Whitepages v3

Collecting contact information for the dorm

") - self.instructions = QLabel("Enter your NetID:") - self.netid = QLineEdit() - self.instructions.setFocusProxy(self.netid) - self.grid = QGridLayout() - self.grid.addWidget(self.title,0,0,1,2) - self.grid.addWidget(self.instructions,1,0,1,1) - self.grid.addWidget(self.netid,1,1,1,1) - self.setLayout(self.grid) - QtCore.QObject.connect(self.netid, QtCore.SIGNAL('textChanged(QString)'), self.textchanged) - QtCore.QObject.connect(self.netid, QtCore.SIGNAL('returnPressed()'), self.submit) - def textchanged(self): - if len(str(self.netid.text())) != 0: - self.emit( QtCore.SIGNAL('ready()')) - else: - self.emit( QtCore.SIGNAL('notReady()')) - print "text changed" - def submit(self): - self.emit( QtCore.SIGNAL('submit()')) - def reset(self): - self.netid.clear() - def getNetID(self): - return str(self.netid.text()) - diff --git a/newpersonwizard.py b/newpersonwizard.py index 6238437..8224a36 100644 --- a/newpersonwizard.py +++ b/newpersonwizard.py @@ -5,78 +5,16 @@ from netidstep import NetIDStep from ldapstep import LDAPStep from donestep import DoneStep -class NewPersonWizard(QDialog): +from pagenewuserdata import PageNewUserData +from pagenetid import PageNetID + +class NewPersonWizard(QWizard): def __init__(self, parent=None): - QDialog.__init__(self, parent) - self.setWindowTitle("Whitepages v3") - self.steps = [] - self.currentstep = 0 - # Here you create the steps, in order - # TODO: determine if steps should have a single interface, or if MainWindow should - # track each by unique name. Right now we do the first. - # I think the latter is better, because then we can keep exactly one copy of the data around - # - inside the step that it refers to. - self.netidstep = NetIDStep() - self.lstep = LDAPStep() - self.donestep = DoneStep() - self.steps.append( self.netidstep ) - self.steps.append( self.lstep ) - self.steps.append( self.donestep ) - self.next_button = QPushButton("&Next") - self.next_button.setEnabled(False) - self.prev_button = QPushButton("&Previous") - self.prev_button.setEnabled(False) - self.layout = QGridLayout() - for s in self.steps: - QtCore.QObject.connect( s, QtCore.SIGNAL('notReady()'), self.next_disabled) - QtCore.QObject.connect( s, QtCore.SIGNAL('ready()'), self.next_enabled) - QtCore.QObject.connect( s, QtCore.SIGNAL('submit()'), self.next) - self.layout.addWidget(s,0,0,2,2) - s.hide() - self.layout.addWidget(self.next_button,2,1,1,1) - self.layout.addWidget(self.prev_button,2,0,1,1) - self.setLayout(self.layout) + QWizard.__init__(self, parent) + self.addPage(PageNetID()) + self.addPage(PageNewUserData()) self.resize(400,300) - self.setModal(True) self.show() - self.steps[0].show() - QtCore.QObject.connect( self.prev_button, QtCore.SIGNAL('clicked()'), self.prev) - QtCore.QObject.connect( self.next_button, QtCore.SIGNAL('clicked()'), self.next) - - def next(self): - if not self.next_button.isEnabled(): - print "Can't advance yet." - return - if self.currentstep + 1 < len(self.steps) : - self.steps[self.currentstep].hide() - self.currentstep = self.currentstep + 1 - self.steps[self.currentstep].show() - self.prev_button.setEnabled(True) - self.next_button.setEnabled(False) - # Perform special actions if particular step - if isinstance(self.steps[self.currentstep],LDAPStep): - self.lstep.lookup(self.netidstep.getNetID()) - print "Next selected" - - def prev(self): - if not self.prev_button.isEnabled(): - print "Can't go back." - return - if self.currentstep > 0: - self.steps[self.currentstep].hide() - self.currentstep = self.currentstep - 1 - self.steps[self.currentstep].show() - self.next_button.setEnabled(True) - self.prev_button.setEnabled( self.currentstep != 0) - print "Prev selected" - def next_enabled(self): - self.next_button.setEnabled(True) - def next_disabled(self): - self.next_button.setEnabled(False) - def reset(self): - for s in self.steps: - s.reset() - if __name__ == "__main__": app = QApplication([""]) diff --git a/pagenetid.py b/pagenetid.py new file mode 100644 index 0000000..3f7abef --- /dev/null +++ b/pagenetid.py @@ -0,0 +1,27 @@ +from PyQt4.QtCore import * +from PyQt4.QtGui import * + +class PageNetID(QWizardPage): + def __init__(self, parent=None): + QWizardPage.__init__(self,parent) + self.completed = False # Is the page done being filled out? + self.instructions = QLabel("&Enter your NetID:") + self.netid = QLineEdit() + self.instructions.setBuddy(self.netid) + self.registerField("netid*", self.netid, "text", SIGNAL("textChanged(QString)")) + self.grid = QGridLayout() + self.grid.addWidget(self.instructions,0,0) + self.grid.addWidget(self.netid,0,1) + self.setLayout(self.grid) + self.setTitle("Move-in Wizard") + self.setSubTitle("Enter your NetID:") + +if __name__ == "__main__": + a = QApplication([""]) + wiz = QWizard() + p = PageNetID() + wiz.addPage(p) + wiz.resize(400,300) + wiz.show() + a.exec_() + diff --git a/pagenewuserdata.py b/pagenewuserdata.py new file mode 100644 index 0000000..57d8489 --- /dev/null +++ b/pagenewuserdata.py @@ -0,0 +1,111 @@ +from PyQt4.QtCore import * +from PyQt4.QtGui import * + +from ldapsearcher import LDAPSearcher + +class PageNewUserData(QWizardPage): + def __init__(self, parent=None): + QWizardPage.__init__(self,parent) + self.completed = False # Is the page done being filled out? + # Create all the subwidgets + self.year_lab = QLabel("Year:") + self.month_lab = QLabel("Month:") + self.day_lab = QLabel("Day:") + self.firstname_lab = QLabel("Preferred name:") + self.surname_lab = QLabel("Last name:") + self.email_lab = QLabel("Email:") + self.phone_lab = QLabel("Phone:") + self.major_lab = QLabel("Major:") + self.hometown_lab = QLabel("Hometown:") + self.room_lab = QLabel("Room number:") + self.bday_lab = QLabel("Birthday:") + self.dorm_lab = QLabel("Dorm:") + # Personal info + self.surname = QLineEdit() + self.firstname = QLineEdit() + self.phone = QLineEdit() + self.email = QLineEdit() + self.major = QLineEdit() + # Birthday + self.year = QComboBox() + self.month = QComboBox() + self.day = QComboBox() + # Residence locations + self.dorm = QComboBox() + self.room = QLineEdit() + # Fill the comboboxes with values, set valid field types + years = QStringList(["1987","1988","1989","1990","1991","1992","1993","1994"]) + months = QStringList(["January","February","March","April","May","June","July","August","September","October","November","December"]) + days = QStringList(["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"]) + dorms = QStringList(["Clements","Lechner","McFadden"]) + self.year.addItems(years) + self.month.addItems(months) + self.day.addItems(days) + self.dorm.addItems(dorms) + self.phone.setInputMask("(999)-999-9999") + self.major.setMaxLength(4) + self.room.setMaxLength(3) + + # Register fields with QWizard + self.registerField("surname*", self.surname, "text", SIGNAL("textChanged(QString)")) + self.registerField("firstname*", self.firstname, "text", SIGNAL("textChanged(QString)")) + self.registerField("phone", self.phone, "text", SIGNAL("textChanged(QString)")) + self.registerField("email*", self.email, "text", SIGNAL("textChanged(QString)")) + self.registerField("major", self.major, "text", SIGNAL("textChanged(QString)")) + self.registerField("dorm", self.dorm, "currentIndex", SIGNAL("currentIndexChanged(int)")) + self.registerField("room*", self.room, "text", SIGNAL("textChanged(QString)")) + self.registerField("year", self.year, "currentIndex", SIGNAL("currentIndexChanged(int)")) + self.registerField("month", self.month, "currentIndex", SIGNAL("currentIndexChanged(int)")) + self.registerField("day", self.day, "currentIndex", SIGNAL("currentIndexChanged(int)")) + + + # Set up layout + self.layout = QGridLayout() + self.bday_layout = QHBoxLayout() + self.bday_layout.addWidget(self.year) + self.bday_layout.addWidget(self.month) + self.bday_layout.addWidget(self.day) + self.layout.addWidget(self.firstname_lab, 1, 0) + self.layout.addWidget(self.firstname, 1, 1) + self.layout.addWidget(self.surname_lab, 2, 0) + self.layout.addWidget(self.surname, 2, 1) + self.layout.addWidget(self.email_lab, 3, 0) + self.layout.addWidget(self.email, 3, 1) + self.layout.addWidget(self.phone_lab, 4, 0) + self.layout.addWidget(self.phone, 4, 1) + self.layout.addWidget(self.bday_lab,5,0) + self.layout.addLayout(self.bday_layout,5,1) + self.layout.addWidget(self.major_lab, 6, 0) + self.layout.addWidget(self.major, 6, 1) + self.layout.addWidget(self.dorm_lab, 7, 0) + self.layout.addWidget(self.dorm, 7, 1) + self.layout.addWidget(self.room_lab, 8, 0) + self.layout.addWidget(self.room, 8, 1) + self.setLayout(self.layout) + self.setTitle("Move-in Wizard") + self.setSubTitle("Enter your contact information:") + + + def initializePage(self): + a = LDAPSearcher() + ldapinfo = a.lookup(str(self.field("netid").toString())) + for key,value in ldapinfo.iteritems(): + if(key == "sn"): + self.surname.setText(value) + elif(key == "givenName"): + self.firstname.setText(value) + elif(key == "mail"): + self.email.setText(value) + elif(key == "major"): + self.major.setText(value) + + +if __name__ == "__main__": + a = QApplication([""]) + wiz = QWizard() + p = PageNewUserData() + wiz.addPage(p) + wiz.resize(400,300) + wiz.show() + a.exec_() +