add user selection to create slice screen
authorsmbaker <smbaker@fc8clean.lan>
Tue, 13 Sep 2011 03:31:16 +0000 (20:31 -0700)
committersmbaker <smbaker@fc8clean.lan>
Tue, 13 Sep 2011 03:31:16 +0000 (20:31 -0700)
sface/screens/userscreen.py
sface/sficreate.py

index 9eb2e6c..6b800b7 100644 (file)
@@ -59,6 +59,9 @@ class UserView(QTableView):
         node_data = node_index.data().toString()
         self.emit(SIGNAL('hostnameClicked(QString)'), node_data)
 
         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)
 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
 
 
         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):
     def readUserRecord(self, i):
         rec_file = config.getAuthorityListFile(i)
         if os.path.exists(rec_file):
index b3de732..0405e3e 100644 (file)
@@ -9,6 +9,7 @@ from PyQt4.QtCore import *
 from PyQt4.QtGui import *
 from sface.config import config
 from sface.sfiprocess import SfiProcess
 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):
 
 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()
         self.hrnEdit = QLineEdit()
         urlLabel = QLabel("Project URL:")
         self.urlEdit = QLineEdit()
-        descLabel = QLabel("Description")
+        descLabel = QLabel("Description:")
         self.descEdit = QTextEdit()
         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.status = QLabel("")
 
         self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
+        self.buttonBox.addButton("refresh", QDialogButtonBox.ActionRole)
         self.buttonBox.button(QDialogButtonBox.Ok).setDefault(True)
 
         layout = QVBoxLayout()
         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.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)
 
         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("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()
 
     def accept(self):
         auth = config.getAuthority()
@@ -52,6 +80,8 @@ class CreateWindow(QDialog):
         type = "slice"
         url = str(self.urlEdit.text())
 
         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
         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
 
             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)
         self.setStatus("Registering Slice...")
 
         self.createProcess = SfiProcess(self)
@@ -71,10 +105,16 @@ class CreateWindow(QDialog):
 
         self.buttonBox.setEnabled(False)
 
 
         self.buttonBox.setEnabled(False)
 
+        researcherXml = "<researcher>" + "</researcher><researcher>".join(researchers) + "</researcher>"
+
         newSliceRecord = os.path.expanduser("~/.sfi/newslice.record")
         newSliceRecord = os.path.expanduser("~/.sfi/newslice.record")
-        file(newSliceRecord, "w").write('<record authority="%s" description="%s" hrn="%s" type="%s" url="%s"></record>' % (auth, desc, hrn, type, url))
+        file(newSliceRecord, "w").write('<record authority="%s" description="%s" hrn="%s" type="%s" url="%s">%s</record>' % (auth, desc, hrn, type, url, researcherXml))
         self.createProcess.addRecord(newSliceRecord)
 
         self.createProcess.addRecord(newSliceRecord)
 
+    def getAuthorityRecordFinished(self):
+        self.setStatus("<font color='green'>User list refreshed.</font>")
+        self.updateView()
+
     def setStatus(self, x):
         self.status.setText(x)
 
     def setStatus(self, x):
         self.status.setText(x)
 
@@ -97,3 +137,10 @@ class CreateWindow(QDialog):
     def getHrn(self):
         return self.hrnEdit.text()
 
     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)
+