Skip to content
Snippets Groups Projects
distribution_edit_controller.py 1.84 KiB
Newer Older
  • Learn to ignore specific revisions
  • from PyQt5.QtWidgets import QMessageBox
    
    
    from controllers.distribution_overview_controller import DistributionOverview
    from model.team import Team
    
    
    class DistributionEdit(DistributionOverview):
        def __init__(self, mainwindow, distribution, group, parent=None):
    
            """
            :param mainwindow: MainWindow that this belongs to
            :param distribution: Distribution that should be edited
            :param group: Group of the edited distribution
            :param parent: parent widget for qt
            """
    
            teams = {team.name: team.members for team in distribution.teams}
            super(DistributionEdit, self).__init__(mainwindow, teams, group, parent)
            self.distribution = distribution
    
    Jakub Štercl's avatar
    Jakub Štercl committed
            self.distribution_name = distribution.name
            self.titleWidget.label.setText(distribution.name)
    
        def save(self, return_after=True):
    
            """
            save the edited distribution and return back 
            """
    
            teams = []
            for table in self.teamTables:
                team = Team(table.id_, table.name, table.getAllData())
                teams.append(team)
            self.distribution.update(self.distribution_name, teams)
            self.main_window.dataChanged()
    
            if return_after is True:
                self.main_window.goBack()
    
        def returningToPrevious(self):
            if self.saved is False:
                msg = QMessageBox(self)
                msg.setWindowTitle(self.tr("Uložit?"))
                msg.setText(self.tr("Chcete rozdělení uložit?"))
                msg.setInformativeText(self.tr("Pokud rozdělení neuložíte, všechny změny, které jste provedly budou ztraceny."))
                btn_discard = msg.addButton(self.tr("Zahodit změny"), QMessageBox.NoRole)
                btn_save = msg.addButton(self.tr("Uložit"), QMessageBox.YesRole)
                msg.exec_()
                if msg.clickedButton() == btn_save:
                    self.save(False)