Пример #1
0
    def handleRemoveUser(self):
        for selected in self.LST_users.selectedItems():
            user = Person.fromPk(str(selected.text()))

            if not user:
                continue

            user.set('perm_group', PermissionGroup.DEFAULT)
Пример #2
0
    def handleAddUser(self):
        dialog = QDialog(self)
        layout = QVBoxLayout()
        user = QLineEdit(dialog)
        buttonLayout = QHBoxLayout()
        cancel = QPushButton('Cancel')
        create = QPushButton('Add')
        completer = QCompleter([p.username for p in hxdb.getUsers()], user)

        cancel.clicked.connect(dialog.reject)
        create.clicked.connect(dialog.accept)
        create.setDefault(True)

        user.setCompleter(completer)
        layout.addWidget(user)
        buttonLayout.addWidget(cancel)
        buttonLayout.addWidget(create)
        buttonLayout.insertStretch(0)
        layout.addLayout(buttonLayout)
        dialog.setWindowTitle('Add User')
        dialog.setLayout(layout)

        if dialog.exec_() == QDialog.Accepted:
            name = str(user.text()).strip()

            if name:
                user = Person.fromPk(name)

                if not user:
                    raise ValueError('User: {} does not exist'.format(user))

                group = str(self.LST_groups.selectedItems()[0].text())

                user.set('perm_group', group)
                self.LST_users.addItem(name)
                self.LST_users.clearSelection()
                self.LST_users.setCurrentRow(self.LST_users.count() - 1)