ProjectDjango/DjangoDumpdataDataDialog.py

changeset 2
1e97424fda0c
child 9
8fe581309106
diff -r 13a0cced0c6e -r 1e97424fda0c ProjectDjango/DjangoDumpdataDataDialog.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ProjectDjango/DjangoDumpdataDataDialog.py	Sat Mar 23 19:41:38 2013 +0100
@@ -0,0 +1,69 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2013 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module implementing a dialog to enter the data for the 'dumpdata' command.
+"""
+
+from PyQt4.QtGui import QDialog
+
+from .Ui_DjangoDumpdataDataDialog import Ui_DjangoDumpdataDataDialog
+
+
+class DjangoDumpdataDataDialog(QDialog, Ui_DjangoDumpdataDataDialog):
+    """
+    Class implementing a dialog to enter the data for the 'dumpdata' command.
+    """
+    def __init__(self, project, parent=None):
+        """
+        Constructor
+        
+        @param project reference to the Django project object
+        @param parent reference to the parent widget (QWidget)
+        """
+        super().__init__(parent)
+        self.setupUi(self)
+        
+        self.__project = project
+        if self.__project.getDjangoVersion() < (1, 0):
+            self.excludeGroup.setEnabled(False)
+        
+        apps = self.__project.getRecentApplications()
+        self.applicationsCombo.addItems(apps)
+        self.excludeCombo.addItems(apps)
+        self.excludeCombo.setEditText("")
+        
+        self.formatCombo.addItem(self.trUtf8("JSON"), "json")
+        self.formatCombo.addItem(self.trUtf8("XML"), "xml")
+        try:
+            import yaml     # __IGNORE_WARNING__
+            self.formatCombo.addItem(self.trUtf8("YAML"), "yaml")
+        except ImportError:
+            pass
+    
+    def getData(self):
+        """
+        Public method to get the data entered into the dialog.
+        
+        @return tuple of two lists of strings, a string and an integer giving
+            the list of applications to work on, the list of applications to
+            exclude, the dump format and the indentation level
+        """
+        applStr = self.applicationsCombo.currentText()
+        if applStr:
+            self.__project.setMostRecentApplication(applStr)
+            appls = applStr.split()
+        else:
+            appls = []
+        
+        exclStr = self.excludeCombo.currentText()
+        if exclStr:
+            excl = exclStr.split()
+        else:
+            excl = []
+        
+        format = self.formatCombo.itemData(self.formatCombo.currentIndex())
+        
+        return appls, excl, format, self.indentationSpinBox.value()

eric ide

mercurial