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)
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):
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):
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()
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()
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
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.buttonBox.setEnabled(False)
+ researcherXml = "<researcher>" + "</researcher><researcher>".join(researchers) + "</researcher>"
+
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)
+ def getAuthorityRecordFinished(self):
+ self.setStatus("<font color='green'>User list refreshed.</font>")
+ self.updateView()
+
def setStatus(self, x):
self.status.setText(x)
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)
+