ProjectDjango/DjangoSquashMigrationSelectionDialog.py

Mon, 22 Jun 2020 19:32:12 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 22 Jun 2020 19:32:12 +0200
changeset 161
208fced62e00
parent 148
4cb7aa43845d
child 163
1622130167bb
permissions
-rw-r--r--

Removed support for Python2.

75
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
145
104b14713e9e Updated copyright for 2020.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 142
diff changeset
3 # Copyright (c) 2016 - 2020 Detlev Offenbach <detlev@die-offenbachs.de>
75
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a dialog to enter data needed to squash migrations.
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 from __future__ import unicode_literals
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 import os
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 from PyQt5.QtCore import pyqtSlot
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 from PyQt5.QtGui import QIcon
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 from PyQt5.QtWidgets import QDialog, QDialogButtonBox
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
161
208fced62e00 Removed support for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 148
diff changeset
18 from .Ui_DjangoSquashMigrationSelectionDialog import (
75
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 Ui_DjangoSquashMigrationSelectionDialog
161
208fced62e00 Removed support for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 148
diff changeset
20 )
75
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 class DjangoSquashMigrationSelectionDialog(
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 QDialog, Ui_DjangoSquashMigrationSelectionDialog):
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 Class implementing a dialog to enter data needed to squash migrations.
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 """
148
4cb7aa43845d Replaced pixmap icons by vector icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 145
diff changeset
28 def __init__(self, migrations, django, suffix, parent=None):
75
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 """
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 Constructor
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 @param migrations dictionary containing the available migrations
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 @type dict
125
d280acf98fb5 - additions for Django > 1.9.0
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 121
diff changeset
34 @param django reference to the Django project object
d280acf98fb5 - additions for Django > 1.9.0
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 121
diff changeset
35 @type Project
148
4cb7aa43845d Replaced pixmap icons by vector icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 145
diff changeset
36 @param suffix icon suffix
4cb7aa43845d Replaced pixmap icons by vector icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 145
diff changeset
37 @type str
75
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 @param parent reference to the parent widget
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 @type QWidget
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 """
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 super(DjangoSquashMigrationSelectionDialog, self).__init__(parent)
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 self.setupUi(self)
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 self.__appliedIcon = QIcon(os.path.join(
148
4cb7aa43845d Replaced pixmap icons by vector icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 145
diff changeset
45 os.path.dirname(__file__), "icons", "applied-{0}".format(suffix)
4cb7aa43845d Replaced pixmap icons by vector icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 145
diff changeset
46 ))
75
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47
125
d280acf98fb5 - additions for Django > 1.9.0
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 121
diff changeset
48 self.__version = django.getDjangoVersion()
d280acf98fb5 - additions for Django > 1.9.0
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 121
diff changeset
49 self.startMigrationComboBox.setEnabled(self.__version >= (1, 9, 0))
d280acf98fb5 - additions for Django > 1.9.0
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 121
diff changeset
50 self.nameEdit.setEnabled(self.__version >= (2, 0, 0))
75
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 self.__migrations = migrations
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 self.applicationComboBox.addItems(
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 [""] + sorted(self.__migrations.keys()))
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 self.on_applicationComboBox_activated("")
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 msh = self.minimumSizeHint()
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 self.resize(max(self.width(), msh.width()), msh.height())
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 def __updateOkButton(self):
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 """
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 Private slot to set the enabled state of the OK button.
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 """
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 enabled = (
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 bool(self.applicationComboBox.currentText()) and
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 bool(self.endMigrationComboBox.currentText()))
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(enabled)
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 @pyqtSlot(str)
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 def on_applicationComboBox_activated(self, app):
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 """
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 Private slot to update the migrations combo boxes.
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 @param app name of the selected application
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 @type str
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 """
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 self.startMigrationComboBox.clear()
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 self.endMigrationComboBox.clear()
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 if app:
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 for combo in [self.startMigrationComboBox,
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 self.endMigrationComboBox]:
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 combo.addItem("")
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 for applied, migration in self.__migrations[app]:
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 if applied:
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 combo.addItem(self.__appliedIcon, migration)
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 else:
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 combo.addItem(migration)
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 self.__updateOkButton()
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 @pyqtSlot(str)
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 def on_endMigrationComboBox_activated(self, migration):
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 """
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 Private slot handling the selection of a migration.
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 @param migration name of the selected migration
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 @type str
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 """
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 self.__updateOkButton()
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 def getData(self):
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 """
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 Public method to retrieve the data entered by the user.
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 @return tuple containing the selected app, the start migration,
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 the end migration and a flag indicating no optimization is wanted
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 @rtype tuple of three str and a bool
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 """
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 if self.startMigrationComboBox.isEnabled():
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 startMigration = self.startMigrationComboBox.currentText()
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 else:
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 startMigration = ""
125
d280acf98fb5 - additions for Django > 1.9.0
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 121
diff changeset
112 if self.nameEdit.isEnabled():
d280acf98fb5 - additions for Django > 1.9.0
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 121
diff changeset
113 name = self.nameEdit.text()
d280acf98fb5 - additions for Django > 1.9.0
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 121
diff changeset
114 else:
d280acf98fb5 - additions for Django > 1.9.0
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 121
diff changeset
115 name = ""
75
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 return (
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 self.applicationComboBox.currentText(),
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 startMigration,
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 self.endMigrationComboBox.currentText(),
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 self.noOptimizeCheckBox.isChecked(),
125
d280acf98fb5 - additions for Django > 1.9.0
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 121
diff changeset
122 name
75
0165ce437462 Continued adding support for the various migration commands.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 )

eric ide

mercurial