From: smbaker Date: Tue, 13 Sep 2011 03:31:16 +0000 (-0700) Subject: add user selection to create slice screen X-Git-Tag: sface-0.1-19~8 X-Git-Url: http://git.onelab.eu/?p=sface.git;a=commitdiff_plain;h=62dde09f684bc81e571f8c0d8439b39ec9b5cf2f add user selection to create slice screen --- diff --git a/sface/screens/userscreen.py b/sface/screens/userscreen.py index 9eb2e6c..6b800b7 100644 --- a/sface/screens/userscreen.py +++ b/sface/screens/userscreen.py @@ -59,6 +59,9 @@ class UserView(QTableView): node_data = node_index.data().toString() self.emit(SIGNAL('hostnameClicked(QString)'), node_data) + def hideUnusableColumns(self): + self.hideColumn(SERVER_MEMBERSHIP_STATUS_COLUMN) + class UserModel(QStandardItemModel): def __init__(self, rows=0, columns=4, parent=None): QStandardItemModel.__init__(self, rows, columns, parent) @@ -126,6 +129,19 @@ class UserModel(QStandardItemModel): return change + def getResearchers(self): + researchers = [] + item = self.invisibleRootItem() + children = item.rowCount() + for row in range(0, children): + childName = str(item.child(row, NAME_COLUMN).data(Qt.DisplayRole).toString()) + childStatus = str(item.child(row, MEMBERSHIP_STATUS_COLUMN).data(Qt.DisplayRole).toString()) + + if (childStatus == user_status['add']) or (childStatus == user_status['in']): + researchers.append(childName) + + return researchers + def readUserRecord(self, i): rec_file = config.getAuthorityListFile(i) if os.path.exists(rec_file): diff --git a/sface/sficreate.py b/sface/sficreate.py index b3de732..0405e3e 100644 --- a/sface/sficreate.py +++ b/sface/sficreate.py @@ -9,6 +9,7 @@ from PyQt4.QtCore import * from PyQt4.QtGui import * from sface.config import config from sface.sfiprocess import SfiProcess +from sface.screens.userscreen import UserView, UserModel class CreateWindow(QDialog): def __init__(self, parent=None): @@ -23,12 +24,18 @@ class CreateWindow(QDialog): self.hrnEdit = QLineEdit() urlLabel = QLabel("Project URL:") self.urlEdit = QLineEdit() - descLabel = QLabel("Description") + descLabel = QLabel("Description:") self.descEdit = QTextEdit() + self.descEdit.setMinimumWidth(400) + self.descEdit.setMaximumHeight(100) + + self.userLabel = QLabel("Researchers:") + self.userView = UserView() self.status = QLabel("") self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) + self.buttonBox.addButton("refresh", QDialogButtonBox.ActionRole) self.buttonBox.button(QDialogButtonBox.Ok).setDefault(True) layout = QVBoxLayout() @@ -38,12 +45,33 @@ class CreateWindow(QDialog): layout.addWidget(self.urlEdit) layout.addWidget(descLabel) layout.addWidget(self.descEdit) + layout.addWidget(self.userLabel) + layout.addWidget(self.userView) layout.addWidget(self.status) layout.addWidget(self.buttonBox) self.setLayout(layout) + self.userModel = UserModel(parent=self) + self.connect(self.buttonBox, SIGNAL("accepted()"), self, SLOT("accept()")) self.connect(self.buttonBox, SIGNAL("rejected()"), self, SLOT("reject()")) + self.connect(self.buttonBox, SIGNAL("clicked(QAbstractButton *)"), self.clicked) + + self.updateView() + + if (self.userModel.rowCount() == 0): + self.refreshAuthority() + + def clicked(self, button): + if button.text() == "refresh": + self.refreshAuthority() + + def refreshAuthority(self): + self.refreshProcess = SfiProcess(self) + self.connect(self.refreshProcess, SIGNAL('finished()'), self.getAuthorityRecordFinished) + + self.refreshProcess.listRecords(config.getAuthority(), "user", config.getAuthorityListFile()) + self.setStatus("Refreshing user list...") def accept(self): auth = config.getAuthority() @@ -52,6 +80,8 @@ class CreateWindow(QDialog): type = "slice" url = str(self.urlEdit.text()) + researchers = self.userModel.getResearchers() + if not hrn.startswith(auth): QMessageBox.warning(self, "Invalid HRN", "HRN must be within your current authority (%s)" % auth) return @@ -64,6 +94,10 @@ class CreateWindow(QDialog): QMessageBox.warning(self, "Invalid Description", "Description is too short") return + if not researchers: + QMessageBox.warning(self, "Invalid Researchers", "Please add at least one researcher by double-clicking on a researcher name") + return + self.setStatus("Registering Slice...") self.createProcess = SfiProcess(self) @@ -71,10 +105,16 @@ class CreateWindow(QDialog): self.buttonBox.setEnabled(False) + researcherXml = "" + "".join(researchers) + "" + newSliceRecord = os.path.expanduser("~/.sfi/newslice.record") - file(newSliceRecord, "w").write('' % (auth, desc, hrn, type, url)) + file(newSliceRecord, "w").write('%s' % (auth, desc, hrn, type, url, researcherXml)) self.createProcess.addRecord(newSliceRecord) + def getAuthorityRecordFinished(self): + self.setStatus("User list refreshed.") + self.updateView() + def setStatus(self, x): self.status.setText(x) @@ -97,3 +137,10 @@ class CreateWindow(QDialog): def getHrn(self): return self.hrnEdit.text() + def updateView(self): + self.userModel.updateModel(None) + + self.userView.setModel(self.userModel) + self.userView.hideUnusableColumns() + self.userView.resizeColumnToContents(0) +