<commit_before># -*- encoding: utf-8 -*-

from globaleaks.db.migrations.update import MigrationBase

from globaleaks.models.config import NodeFactory
from globaleaks.models.l10n import EnabledLanguage


class MigrationScript(MigrationBase):
    def migrate_User(self):
        default_language = NodeFactory(self.store_old).get_val('default_language')
        enabled_languages = EnabledLanguage.list(self.store_old)

        old_objs = self.store_old.find(self.model_from['User'])
        for old_obj in old_objs:
            new_obj = self.model_to['User']()
            for _, v in new_obj._storm_columns.iteritems():
                if v.name == 'language' and getattr(old_obj, v.name) not in enabled_languages:
                    # fix users that have configured a language that has never been there
                    #setattr(new_obj, v.name, default_language)
                    continue

                setattr(new_obj, v.name, getattr(old_obj, v.name))

            self.store_new.add(new_obj)<commit_msg>Decomment line in migration script 35<commit_after># -*- encoding: utf-8 -*-

from globaleaks.db.migrations.update import MigrationBase

from globaleaks.models.config import NodeFactory
from globaleaks.models.l10n import EnabledLanguage


class MigrationScript(MigrationBase):
    def migrate_User(self):
        default_language = NodeFactory(self.store_old).get_val('default_language')
        enabled_languages = EnabledLanguage.list(self.store_old)

        old_objs = self.store_old.find(self.model_from['User'])
        for old_obj in old_objs:
            new_obj = self.model_to['User']()
            for _, v in new_obj._storm_columns.iteritems():
                if v.name == 'language' and getattr(old_obj, v.name) not in enabled_languages:
                    # fix users that have configured a language that has never been there
                    setattr(new_obj, v.name, default_language)
                    continue

                setattr(new_obj, v.name, getattr(old_obj, v.name))

            self.store_new.add(new_obj)
{'fraction_non_alphanumeric': 0.09073265405143134, 'fraction_numerical': 0.0038816108685104317, 'mean_word_length': 2.7355072463768115, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '822879', 'n_tokens_mistral': 614, 'n_tokens_neox': 590, 'n_words': 134}