ProjectDjango/DjangoDumpdataDataDialog.py

Sun, 30 Mar 2025 15:25:10 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 30 Mar 2025 15:25:10 +0200
branch
eric7
changeset 206
4dfd8f6f2503
parent 197
2667e16a3379
permissions
-rw-r--r--

Created global tag <release-10.4.0>.

# -*- coding: utf-8 -*-

# Copyright (c) 2013 - 2025 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing a dialog to enter the data for the 'dumpdata' command.
"""

import contextlib

from PyQt6.QtWidgets 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
        @type Project
        @param parent reference to the parent widget
        @type QWidget
        """
        super().__init__(parent)
        self.setupUi(self)

        self.__project = project

        apps = self.__project.getRecentApplications()
        self.applicationsCombo.addItems(apps)
        self.excludeCombo.addItems(apps)
        self.excludeCombo.setEditText("")

        self.formatCombo.addItem(self.tr("JSON"), "json")
        self.formatCombo.addItem(self.tr("XML"), "xml")
        with contextlib.suppress(ImportError):
            import yaml  # __IGNORE_WARNING__

            self.formatCombo.addItem(self.tr("YAML"), "yaml")

        msh = self.minimumSizeHint()
        self.resize(max(self.width(), msh.width()), msh.height())

    def getData(self):
        """
        Public method to get the data entered into the dialog.

        @return tuple giving the list of applications to work on, the list of
            applications to exclude, the dump format and the indentation level
        @rtype tuple of (list of str, list of str, str, int)
        """
        applStr = self.applicationsCombo.currentText()
        if applStr:
            self.__project.setMostRecentApplication(applStr)
            appls = applStr.split()
        else:
            appls = []

        exclStr = self.excludeCombo.currentText()
        excl = exclStr.split() if exclStr else []

        dumpFormat = self.formatCombo.itemData(self.formatCombo.currentIndex())

        return appls, excl, dumpFormat, self.indentationSpinBox.value()

eric ide

mercurial