Exemplo n.º 1
0
    def update_version(document, user_id, comment, update_types,
                       changed_langs):
        assert user_id
        assert update_types

        meta_data = HistoryMetaData(comment=comment, user_id=user_id)
        archive = DocumentRest._get_document_archive(document, update_types)
        geometry_archive = \
            DocumentRest._get_geometry_archive(document, update_types)

        langs = DocumentRest._get_langs_to_update(document, update_types,
                                                  changed_langs)
        locale_versions = []
        for lang in langs:
            locale = document.get_locale(lang)
            locale_archive = DocumentRest._get_locale_archive(
                locale, changed_langs)

            version = DocumentVersion(
                document_id=document.document_id,
                lang=locale.lang,
                document_archive=archive,
                document_geometry_archive=geometry_archive,
                document_locales_archive=locale_archive,
                history_metadata=meta_data)
            locale_versions.append(version)

        DBSession.add(archive)
        DBSession.add(meta_data)
        DBSession.add_all(locale_versions)
        DBSession.flush()
Exemplo n.º 2
0
    def create_new_version(document, user_id, written_at=None):
        assert user_id
        archive = document.to_archive()
        archive_locales = document.get_archive_locales()
        archive_geometry = document.get_archive_geometry()

        meta_data = HistoryMetaData(comment='creation',
                                    user_id=user_id,
                                    written_at=written_at)
        versions = []
        for locale in archive_locales:
            version = DocumentVersion(
                document_id=document.document_id,
                lang=locale.lang,
                document_archive=archive,
                document_locales_archive=locale,
                document_geometry_archive=archive_geometry,
                history_metadata=meta_data)
            versions.append(version)

        DBSession.add(archive)
        DBSession.add_all(archive_locales)
        DBSession.add(meta_data)
        DBSession.add_all(versions)
        DBSession.flush()
Exemplo n.º 3
0
    def _update_version(self, document, comment, update_types, changed_langs):
        assert update_types

        meta_data = HistoryMetaData(comment=comment)
        archive = self._get_document_archive(document, update_types)
        geometry_archive = \
            self._get_geometry_archive(document, update_types)

        cultures = \
            self._get_cultures_to_update(document, update_types, changed_langs)
        locale_versions = []
        for culture in cultures:
            locale = document.get_locale(culture)
            locale_archive = self._get_locale_archive(locale, changed_langs)

            version = DocumentVersion(
                document_id=document.document_id,
                culture=locale.culture,
                document_archive=archive,
                document_geometry_archive=geometry_archive,
                document_locales_archive=locale_archive,
                history_metadata=meta_data)
            locale_versions.append(version)

        DBSession.add(archive)
        DBSession.add(meta_data)
        DBSession.add_all(locale_versions)
        DBSession.flush()
Exemplo n.º 4
0
    def migrate(self):
        self._migrate(
            'history_metadata',
            metadata_query_count, metadata_query, HistoryMetaData,
            self.get_meta_data)
        self._migrate(
            'documents_versions',
            versions_query_count, versions_query, DocumentVersion,
            self.get_version)

        # there are a couple of users that did not have a profile (see
        # MigrateUserProfiles). now also create a version for the created
        # profiles.
        with transaction.manager:
            profileless_users = self.connection_source.execute(
                text(MigrateUserProfiles.query_profileless_users))
            last_metadata_id = self.connection_source.execute(
                text('select max(history_metadata_id) '
                     'from app_history_metadata;')).fetchone()[0]
            last_version_id = self.connection_source.execute(
                text('select max(documents_versions_id) '
                     'from app_documents_versions;')).fetchone()[0]

            for row in profileless_users:
                user_id = row[0]
                last_metadata_id += 1
                last_version_id += 1

                archive = self.session_target.query(ArchiveDocument).filter(
                    ArchiveDocument.document_id == user_id).one()
                locale = self.session_target.query(ArchiveDocumentLocale). \
                    filter(ArchiveDocumentLocale.document_id == user_id).one()

                meta_data = HistoryMetaData(
                    id=last_metadata_id,
                    comment='creation', user_id=user_id)
                version = DocumentVersion(
                    id=last_version_id,
                    document_id=user_id,
                    lang=locale.lang,
                    document_archive=archive,
                    document_locales_archive=locale,
                    history_metadata=meta_data
                )
                self.session_target.add(version)
Exemplo n.º 5
0
    def _create_new_version(self, document):
        archive = document.to_archive()
        archive_locales = document.get_archive_locales()
        archive_geometry = document.get_archive_geometry()

        meta_data = HistoryMetaData(comment='creation')
        versions = []
        for locale in archive_locales:
            version = DocumentVersion(
                document_id=document.document_id,
                culture=locale.culture,
                document_archive=archive,
                document_locales_archive=locale,
                document_geometry_archive=archive_geometry,
                history_metadata=meta_data)
            versions.append(version)

        DBSession.add(archive)
        DBSession.add_all(archive_locales)
        DBSession.add(meta_data)
        DBSession.add_all(versions)
        DBSession.flush()
Exemplo n.º 6
0
def main(argv=sys.argv):
    settings_file = os.path.join(
        os.path.dirname(os.path.abspath(__file__)), 'loadtests.ini')
    settings = get_appsettings(settings_file)

    engine = engine_from_config(settings, 'sqlalchemy.')

    logging.basicConfig()
    logging.getLogger('sqlalchemy.engine').setLevel(logging.WARN)

    Session = sessionmaker()  # noqa
    register(Session)
    session = Session(bind=engine)

    with transaction.manager:
        for i in range(1, NB_USERS_TO_CREATE + 1):
            username = BASE_USERNAME + str(i)
            password = username
            email = username + '@foo.bar'
            lang = 'fr'

            profile = UserProfile(
                categories=['amateur'],
                geometry=DocumentGeometry(
                    version=1, geom=None, geom_detail=None),
                locales=[DocumentLocale(lang=lang, title='')]
            )
            user = User(
                username=username,
                forum_username=username,
                name=username,
                email=email,
                lang=lang,
                password=password,
                profile=profile
            )
            # make sure user account is directly validated
            user.clear_validation_nonce()
            user.email_validated = True

            session.add(user)
            session.flush()

            # also create a version for the profile
            # code from DocumentRest.create_new_version
            archive = user.profile.to_archive()
            archive_locales = user.profile.get_archive_locales()
            archive_geometry = user.profile.get_archive_geometry()
            meta_data = HistoryMetaData(comment='creation', user_id=user.id)
            versions = []
            for locale in archive_locales:
                version = DocumentVersion(
                    document_id=user.profile.document_id,
                    lang=locale.lang,
                    document_archive=archive,
                    document_locales_archive=locale,
                    document_geometry_archive=archive_geometry,
                    history_metadata=meta_data
                )
                versions.append(version)
            session.add(archive)
            session.add_all(archive_locales)
            session.add(meta_data)
            session.add_all(versions)
            session.flush()

    print('Created %d users with base username `%s`' % (
        NB_USERS_TO_CREATE, BASE_USERNAME))