Ejemplo n.º 1
0
def db_serialize_node(store, language):
    """
    Serialize node info.
    """
    # Contexts and Receivers relationship
    configured = store.find(models.ReceiverContext).count() > 0

    ro_node = NodeFactory(store).public_export()

    misc_dict = {
        'languages_enabled': l10n.EnabledLanguage.list(store),
        'languages_supported': LANGUAGES_SUPPORTED,
        'configured': configured,
        'accept_submissions': GLSettings.accept_submissions,
        'logo': db_get_file(store, u'logo'),
        'favicon': db_get_file(store, u'favicon'),
        'css': db_get_file(store, u'css'),
        'homepage': db_get_file(store, u'homepage'),
        'script': db_get_file(store, u'script')
    }

    l10n_dict = NodeL10NFactory(store).localized_dict(language)

    ret = disjoint_union(ro_node, l10n_dict, misc_dict)

    return ret
Ejemplo n.º 2
0
def db_serialize_node(store, language):
    """
    Serialize node info.
    """
    # Contexts and Receivers relationship
    configured = store.find(models.ReceiverContext).count() > 0

    ro_node = NodeFactory(store).public_export()

    misc_dict = {
        'languages_enabled': l10n.EnabledLanguage.list(store),
        'languages_supported': LANGUAGES_SUPPORTED,
        'configured': configured,
        'accept_submissions': GLSettings.accept_submissions,
        'logo': db_get_file(store, u'logo'),
        'favicon': db_get_file(store, u'favicon'),
        'css': db_get_file(store, u'css'),
        'homepage': db_get_file(store, u'homepage'),
        'script': db_get_file(store, u'script')
    }

    l10n_dict = NodeL10NFactory(store).localized_dict(language)

    ret = disjoint_union(ro_node, l10n_dict, misc_dict)

    if GLSettings.devel_mode:
        ret['submission_minimum_delay'] = 0

    return ret
Ejemplo n.º 3
0
    def epilogue(self):
        old_node = self.store_old.find(self.model_from['Node']).one()
        old_notif = self.store_old.find(self.model_from['Notification']).one()

        with open(os.path.join(GLSettings.client_path, 'favicon.ico'),
                  'r') as favicon_file:
            data = favicon_file.read()
            files.db_add_file(self.store_new, data, u'favicon')
            self.entries_count['File'] += 1

        file_path = os.path.join(GLSettings.static_path,
                                 'custom_homepage.html')
        if os.path.exists(file_path):
            if files.db_get_file(self.store_new, u'homepage') == '':
                with open(file_path, 'r') as homepage_file:
                    data = homepage_file.read()
                    files.db_add_file(self.store_new, data, u'homepage')
                    self.entries_count['File'] += 1

            os.remove(file_path)

        #### Create ConfigL10N table and rows ####
        for lang in old_node.languages_enabled:
            self.store_new.add(l10n.EnabledLanguage(lang))

        self._migrate_l10n_static_config(old_node, 'node')
        self._migrate_l10n_static_config(old_notif, 'templates')

        # TODO assert that localized_keys matches exactly what is stored in the DB

        #### Create Config table and rows ####

        # Migrate Config saved in Node
        for var_name, item_def in GLConfig['node'].iteritems():
            old_val = getattr(old_node, var_name)

            # XXX this can throw errors if the validators run
            item = Config('node', var_name, old_val)
            self.store_new.add(item)

        # Migrate Config saved in Notification
        for var_name, item_def in GLConfig['notification'].iteritems():
            old_val = getattr(old_notif, var_name)

            if var_name == 'exception_email_pgp_key_expiration' and old_val is not None:
                old_val = properties.iso_strf_time(old_val)

            # NOTE this will throw errors if the validators run
            item = Config('notification', var_name, old_val)
            self.store_new.add(item)

        # Migrate private fields
        self.store_new.add(
            Config('private', 'receipt_salt', old_node.receipt_salt))
        self.store_new.add(
            Config('private', 'smtp_password', old_notif.password))

        # Set old verions that will be then handled by the version update
        self.store_new.add(Config('private', 'version', 'X.Y.Z'))
        self.store_new.add(Config('private', 'version_db', 0))
Ejemplo n.º 4
0
    def epilogue(self):
        old_node = self.store_old.find(self.model_from['Node']).one()
        old_notif = self.store_old.find(self.model_from['Notification']).one()

        with open(os.path.join(GLSettings.client_path, 'favicon.ico'), 'r') as favicon_file:
            data = favicon_file.read()
            files.db_add_file(self.store_new, data, u'favicon')
            self.entries_count['File'] += 1

        file_path = os.path.join(GLSettings.static_path, 'custom_homepage.html')
        if os.path.exists(file_path):
            if files.db_get_file(self.store_new, u'homepage') == '':
                with open(file_path, 'r') as homepage_file:
                    data = homepage_file.read()
                    files.db_add_file(self.store_new, data, u'homepage')
                    self.entries_count['File'] += 1

            os.remove(file_path)

        #### Create ConfigL10N table and rows ####
        for lang in old_node.languages_enabled:
            self.store_new.add(l10n.EnabledLanguage(lang))

        self._migrate_l10n_static_config(old_node, 'node')
        self._migrate_l10n_static_config(old_notif, 'templates')

        # TODO assert that localized_keys matches exactly what is stored in the DB

        #### Create Config table and rows ####

        # Migrate Config saved in Node
        for var_name, item_def in GLConfig['node'].iteritems():
            old_val = getattr(old_node, var_name)

            # XXX this can throw errors if the validators run
            item = Config('node', var_name, old_val)
            self.store_new.add(item)

        # Migrate Config saved in Notification
        for var_name, item_def in GLConfig['notification'].iteritems():
            old_val = getattr(old_notif, var_name)

            if var_name == 'exception_email_pgp_key_expiration' and old_val is not None:
                old_val = properties.iso_strf_time(old_val)

            # NOTE this will throw errors if the validators run
            item = Config('notification', var_name, old_val)
            self.store_new.add(item)

        # Migrate private fields
        self.store_new.add(Config('private', 'receipt_salt', old_node.receipt_salt))
        self.store_new.add(Config('private', 'smtp_password', old_notif.password))

        # Set old verions that will be then handled by the version update
        self.store_new.add(Config('private', 'version', 'X.Y.Z'))
        self.store_new.add(Config('private', 'version_db', 0))