Exemple #1
0
    def set_settings(
            self,
            settings: DBSettings,
            accountant,  # TODO: Set type after cyclic dependency fix
    ) -> Tuple[bool, str]:
        given_items = list(settings.keys())
        msg = ''

        # ignore invalid settings
        invalid = []
        all_okay = True
        for x in given_items:
            if x not in VALID_SETTINGS:
                invalid.append(x)
                del settings[x]
                all_okay = False

        if not all_okay:
            msg = 'provided settings: {} are invalid'.format(','.join(invalid))

        if 'main_currency' in settings:
            accountant.set_main_currency(settings['main_currency'])

        self.db.set_settings(settings)
        return True, msg
Exemple #2
0
    def set_settings(
            self,
            settings: DBSettings,
            accountant=None,  # TODO: Set type after cyclic dependency fix
    ) -> Tuple[bool, str]:
        given_items = list(settings.keys())
        msg = ''

        # ignore invalid settings
        invalid = []
        all_okay = True
        for x in given_items:
            if x not in VALID_SETTINGS:
                invalid.append(x)
                del settings[x]
                all_okay = False

            if x in BOOLEAN_SETTINGS:
                if settings[x] is True:
                    settings[x] = 'True'
                elif settings[x] is False:
                    settings[x] = 'False'
                else:
                    raise ValueError(
                        f'Setting {x} should have a True/False value but it has {settings[x]}',
                    )

        if not all_okay:
            msg = 'provided settings: {} are invalid'.format(','.join(invalid))
            log.warning(msg)

        if 'main_currency' in settings:
            accountant.set_main_currency(settings['main_currency'])

        self.db.set_settings(settings)
        return True, msg