ProjectDjango/DjangoLoaddataDataDialog.py

branch
eric7
changeset 180
64339135bd61
parent 175
30cb5e553e7e
child 181
2f5c3487139c
equal deleted inserted replaced
179:8413c2429808 180:64339135bd61
22 22
23 class DjangoLoaddataDataDialog(QDialog, Ui_DjangoLoaddataDataDialog): 23 class DjangoLoaddataDataDialog(QDialog, Ui_DjangoLoaddataDataDialog):
24 """ 24 """
25 Class implementing a dialog to enter the data for the 'loaddata' command. 25 Class implementing a dialog to enter the data for the 'loaddata' command.
26 """ 26 """
27
27 def __init__(self, project, parent=None): 28 def __init__(self, project, parent=None):
28 """ 29 """
29 Constructor 30 Constructor
30 31
31 @param project reference to the Django project object 32 @param project reference to the Django project object
32 @type Project 33 @type Project
33 @param parent reference to the parent widget 34 @param parent reference to the parent widget
34 @type QWidget 35 @type QWidget
35 """ 36 """
36 super().__init__(parent) 37 super().__init__(parent)
37 self.setupUi(self) 38 self.setupUi(self)
38 39
39 self.fixtureFileButton.setIcon(UI.PixmapCache.getIcon("open")) 40 self.fixtureFileButton.setIcon(UI.PixmapCache.getIcon("open"))
40 41
41 self.__project = project 42 self.__project = project
42 43
43 self.buttonBox.button( 44 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(False)
44 QDialogButtonBox.StandardButton.Ok).setEnabled(False) 45
45
46 msh = self.minimumSizeHint() 46 msh = self.minimumSizeHint()
47 self.resize(max(self.width(), msh.width()), msh.height()) 47 self.resize(max(self.width(), msh.width()), msh.height())
48 48
49 @pyqtSlot(str) 49 @pyqtSlot(str)
50 def on_fixturesEdit_textChanged(self, txt): 50 def on_fixturesEdit_textChanged(self, txt):
51 """ 51 """
52 Private slot to handle a change of the fixtures text. 52 Private slot to handle a change of the fixtures text.
53 53
54 @param txt text of the line edit (string) 54 @param txt text of the line edit (string)
55 """ 55 """
56 self.buttonBox.button( 56 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(bool(txt))
57 QDialogButtonBox.StandardButton.Ok).setEnabled(bool(txt)) 57
58
59 @pyqtSlot() 58 @pyqtSlot()
60 def on_fixtureFileButton_clicked(self): 59 def on_fixtureFileButton_clicked(self):
61 """ 60 """
62 Private slot to select a fixture file via a file selection dialog. 61 Private slot to select a fixture file via a file selection dialog.
63 """ 62 """
64 fileFilters = self.tr("JSON Files (*.json);;XML Files (*.xml);;") 63 fileFilters = self.tr("JSON Files (*.json);;XML Files (*.xml);;")
65 with contextlib.suppress(ImportError): 64 with contextlib.suppress(ImportError):
66 import yaml # __IGNORE_WARNING__ 65 import yaml # __IGNORE_WARNING__
66
67 fileFilters += self.tr("YAML Files (*.yaml);;") 67 fileFilters += self.tr("YAML Files (*.yaml);;")
68 fileFilters += self.tr("All Files (*)") 68 fileFilters += self.tr("All Files (*)")
69 69
70 fixtureFiles = EricFileDialog.getOpenFileNames( 70 fixtureFiles = EricFileDialog.getOpenFileNames(
71 self, 71 self,
72 self.tr("Select fixture file"), 72 self.tr("Select fixture file"),
73 self.__project.getProjectPath(), 73 self.__project.getProjectPath(),
74 fileFilters) 74 fileFilters,
75 75 )
76
76 if fixtureFiles: 77 if fixtureFiles:
77 self.fixturesEdit.setText(" ".join( 78 self.fixturesEdit.setText(
78 [Utilities.toNativeSeparators(f) for f in fixtureFiles])) 79 " ".join([Utilities.toNativeSeparators(f) for f in fixtureFiles])
79 80 )
81
80 def getData(self): 82 def getData(self):
81 """ 83 """
82 Public method to get the data entered into the dialog. 84 Public method to get the data entered into the dialog.
83 85
84 @return tuple containing the list of fixtures, list of apps to exclude, 86 @return tuple containing the list of fixtures, list of apps to exclude,
85 application to search in and a flag indicating to ignore 87 application to search in and a flag indicating to ignore
86 non-existing fields and models 88 non-existing fields and models
87 @rtype tuple of (list of str, list of str, str, bool) 89 @rtype tuple of (list of str, list of str, str, bool)
88 """ 90 """
89 fixturesStr = self.fixturesEdit.text() 91 fixturesStr = self.fixturesEdit.text()
90 fixtures = fixturesStr.split() 92 fixtures = fixturesStr.split()
91 93
92 excludeStr = self.excludeEdit.text() 94 excludeStr = self.excludeEdit.text()
93 excludes = excludeStr.split() 95 excludes = excludeStr.split()
94 96
95 return (fixtures, excludes, self.appEdit.text(), 97 return (
96 self.ignoreCheckBox.isChecked()) 98 fixtures,
99 excludes,
100 self.appEdit.text(),
101 self.ignoreCheckBox.isChecked(),
102 )

eric ide

mercurial