Beispiel #1
0
 def getConfDelete(self, conf: Audit, parent=None) -> QWidget:
     conf_audit = ConfAuditHandler(parent, self.container, conf).ui
     shortcut = shortcut_service.getShortcut(int(conf.record_id))
     conf_audit.name.setText("Deleted %s" % shortcut.label)
     conf_audit.type.setText("Deleted")
     conf_audit.type.setStyleSheet(
         "background-color: red; padding: 2px 5px; color: white")
     return conf_audit
Beispiel #2
0
 def getConfCreate(self, conf: Audit, parent=None) -> QWidget:
     conf_audit = ConfAuditHandler(parent, self.container, conf).ui
     shortcut = shortcut_service.getShortcut(int(conf.record_id))
     conf_audit.name.setText("Set %s to %s" %
                             (shortcut.label, shortcut.default_value))
     conf_audit.type.setText("Created")
     conf_audit.type.setStyleSheet(
         "background-color: green; padding: 2px 5px; color: white")
     return conf_audit
 def cancel(self):
     shortcut = shortcut_service.getShortcut(self.shortcut.id)
     shortcut.label = self.ui.shortcut_label.text()
     shortcut.default_value = self.ui.default_value.text()
     shortcut.pref_type = self.ui.data_type.currentText()
     shortcut.shortcut = self.ui.shortcut_type.currentText()
     shortcut.mapping_to = self.ui.mapping_to.text()
     shortcut.description = self.ui.description.toPlainText()
     if shortcut_service.hasChanged(shortcut):
         button_reply = QMessageBox.question(self.dialog, 'Preference shortcut', "You have made some changes, \n"
                                                                                 "Do you want to discard all of it?",
                                             QMessageBox.Ok | QMessageBox.Cancel, QMessageBox.Cancel)
         if button_reply == QMessageBox.Ok:
             self.dialog.close()
     else:
         self.dialog.close()
    def finish(self):
        if not self.ui.mapping_to.text() and self.ui.shortcut_type.currentText() != 'Constant':
            message = self._translate(self.template, 'The value of \'Mapping to\' can not be empty')
            QToolTip.showText(self.ui.mapping_to.mapToGlobal(QPoint()), message)
            return
        shortcut_type = self.ui.shortcut_type.currentText()
        mapping_to = self.ui.mapping_to.text()

        # Is create mode
        if self.is_creative_move and self.findShortcut(self.container, shortcut_type, mapping_to):
            msg = QMessageBox()
            msg.setIcon(QMessageBox.Critical)

            msg.setText(self._translate(self.template, "Preference shortcut already exists!!!"))
            msg.setInformativeText('Preference shortcut with type: %s, mapping to: %s is already exist!\n\n'
                                   'Please choose another one' % (shortcut_type, mapping_to))
            msg.setStandardButtons(QMessageBox.Ok)
            return msg.exec_()

        if self.is_creative_move:
            order = PreferencesShortcut.select().where(PreferencesShortcut.container == self.container).count() * 10000
            self.shortcut.order = order

        self.shortcut.container = self.container
        self.shortcut.label = self.ui.shortcut_label.text().strip()
        self.shortcut.default_value = self.ui.default_value.text().strip()
        self.shortcut.pref_type = self.ui.data_type.currentText().strip()
        self.shortcut.shortcut = self.ui.shortcut_type.currentText()
        self.shortcut.mapping_to = self.ui.mapping_to.text().strip()
        self.shortcut.description = self.ui.description.toPlainText().strip()

        if shortcut_service.hasChanged(self.shortcut):
            model = model_to_dict(self.shortcut)
            model_original = model_to_dict(shortcut_service.getShortcut(self.shortcut.id))
            changes = []
            for key in model:
                if model[key] != model_original[key] and key != 'id':
                    # Record changes, except label because it will not affect to the container it self
                    changes.append({'from': model_original[key], 'to': model[key], 'key': key})
            self.shortcut.save()
            if self.is_creative_move:
                auditing_service.audit_create(self.container, self.shortcut.tableName(), self.shortcut.id)
            else:
                for change in changes:
                    auditing_service.audit_update(self.container, self.shortcut.tableName(), self.shortcut.id,
                                                  change['key'], change['from'], change['to'])
        self.dialog.accept()
Beispiel #5
0
 def getConfUpdate(self, conf: AuditUpdate, parent=None) -> QWidget:
     conf_audit = ConfAuditHandler(parent, self.container, conf).ui
     shortcut = shortcut_service.getShortcut(int(conf.record_id))
     if conf.field == "enabled":
         if conf.value_to == "True":
             conf_audit.name.setText(
                 "Enabled %s %s" % (shortcut.label, shortcut.default_value))
         else:
             conf_audit.name.setText(
                 "Disabled %s %s" %
                 (shortcut.label, shortcut.default_value))
     else:
         if shortcut.shortcut == 'Volume Mount':
             conf_audit.name.setText("%s changed to %s" %
                                     (shortcut.label, conf.value_to))
         else:
             conf_audit.name.setText(
                 "%s changed from %s to %s" %
                 (shortcut.label, conf.value_from, conf.value_to))
     conf_audit.type.setText("Updated")
     conf_audit.type.setStyleSheet(
         "background-color: yellow; padding: 2px 5px; color: black")
     return conf_audit