• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python model.DBSession类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tracim.model.DBSession的典型用法代码示例。如果您正苦于以下问题:Python DBSession类的具体用法?Python DBSession怎么用?Python DBSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了DBSession类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: delete

    def delete(self, token):
        """Delete lock.

        Returns True on success. False, if token does not exist, or is expired.
        """
        self._lock.acquireWrite()
        try:
            lock_db = self.__base_query().filter(Lock.token == token).one_or_none()
            _logger.debug("delete %s" % lockString(from_base_to_dict(lock_db)))
            if lock_db is None:
                return False
            # Remove url to lock mapping
            url2token = DBSession.query(Url2Token).filter(
                Url2Token.path == lock_db.root,
                Url2Token.token == token).one_or_none()
            if url2token is not None:
                DBSession.delete(url2token)
            # Remove the lock
            DBSession.delete(lock_db)
            transaction.commit()

            self._flush()
        finally:
            self._lock.release()
        return True
开发者ID:Nonolost,项目名称:tracim,代码行数:25,代码来源:lock_storage.py


示例2: test_create_user

    def test_create_user(self):
        self._connect_user(
            '[email protected]',
            '[email protected]',
        )

        user_count = DBSession.query(User) \
            .filter(User.email == '[email protected]').count()
        eq_(0, user_count, 'User should not exist yet')

        # Create a new user
        try_post_user = self.app.post(
            '/admin/users',
            OrderedDict([
                ('name', 'TEST'),
                ('email', '[email protected]'),
                ('password', 'password'),
                ('is_tracim_manager', 'off'),
                ('is_tracim_admin', 'off'),
                ('send_email', 'off'),
            ])
        )

        eq_(try_post_user.status_code, 302,
            "Code should be 302, but is %d" % try_post_user.status_code)

        user = DBSession.query(User) \
            .filter(User.email == '[email protected]').one()
        ok_(user, msg="User should exist now")
        ok_(user.validate_password('password'))

        # User must have webdav digest
        ok_(user.webdav_left_digest_response_hash)
开发者ID:buxx,项目名称:tracim,代码行数:33,代码来源:test_admin.py


示例3: test_new_revision

    def test_new_revision(self):
        admin = DBSession.query(User).filter(User.email == '[email protected]').one()
        workspace = self._create_workspace_and_test(name='workspace_1', user=admin)
        folder = self._create_content_and_test(name='folder_1', workspace=workspace, type=ContentType.Folder)
        page = self._create_content_and_test(
            workspace=workspace,
            parent=folder,
            name='file_1',
            description='content of file_1',
            type=ContentType.Page,
            owner=admin
        )

        DBSession.flush()

        # Model create a new instance with list of column
        new_revision_by_model = ContentRevisionRO.new_from(page.revision)
        # Test create a new instance from dynamic listing of model columns mapping
        new_revision_by_test = self._new_from(page.revision)

        new_revision_by_model_dict = self._get_dict_representation(new_revision_by_model)
        new_revision_by_test_dict = self._get_dict_representation(new_revision_by_test)

        # They must be identical
        eq_(new_revision_by_model_dict, new_revision_by_test_dict)
开发者ID:lebouquetin,项目名称:tracim,代码行数:25,代码来源:test_content_revision.py


示例4: test_create

    def test_create(self, key='1'):
        eq_(0, DBSession.query(ContentRevisionRO).filter(ContentRevisionRO.label == 'TEST_CONTENT_%s' % key).count())
        eq_(0, DBSession.query(Workspace).filter(Workspace.label == 'TEST_WORKSPACE_%s' % key).count())

        user_admin = DBSession.query(User).filter(User.email == '[email protected]').one()
        workspace = Workspace(label="TEST_WORKSPACE_%s" % key)
        DBSession.add(workspace)
        DBSession.flush()
        eq_(1, DBSession.query(Workspace).filter(Workspace.label == 'TEST_WORKSPACE_%s' % key).count())

        created_content = self._create_content(
            owner=user_admin,
            workspace=workspace,
            type=ContentType.Page,
            label='TEST_CONTENT_%s' % key,
            description='TEST_CONTENT_DESCRIPTION_%s' % key,
            revision_type=ActionDescription.CREATION
        )

        eq_(1, DBSession.query(ContentRevisionRO).filter(ContentRevisionRO.label == 'TEST_CONTENT_%s' % key).count())

        content = DBSession.query(Content).filter(Content.id == created_content.id).one()
        eq_('TEST_CONTENT_%s' % key, content.label)
        eq_('TEST_CONTENT_DESCRIPTION_%s' % key, content.description)

        return created_content
开发者ID:Nonolost,项目名称:tracim,代码行数:26,代码来源:test_content.py


示例5: ensure_calendar_exist

    def ensure_calendar_exist(self, workspace: Workspace) -> None:
        # Note: Cyclic imports
        from tracim.lib.calendar import CalendarManager
        from tracim.model.organisational import WorkspaceCalendar

        calendar_manager = CalendarManager(self._user)

        try:
            calendar_manager.enable_calendar_file(
                calendar_class=WorkspaceCalendar,
                related_object_id=workspace.workspace_id,
                raise_=True,
            )
        # If previous calendar file no exist, calendar must be created
        except FileNotFoundError:
            self._user.ensure_auth_token()

            # Ensure database is up-to-date
            DBSession.flush()
            transaction.commit()

            calendar_manager.create_then_remove_fake_event(
                calendar_class=WorkspaceCalendar,
                related_object_id=workspace.workspace_id,
            )
开发者ID:lebouquetin,项目名称:tracim,代码行数:25,代码来源:workspace.py


示例6: test_unit__rename_content__ok

    def test_unit__rename_content__ok(self):
        provider = self._get_provider()
        environ = self._get_environ(
            provider,
            '[email protected]',
        )
        w1f1d1 = provider.getResourceInst(
            '/w1/w1f1/w1f1d1.txt',
            environ,
        )

        content_w1f1d1 = DBSession.query(ContentRevisionRO) \
            .filter(Content.label == 'w1f1d1') \
            .one()  # It must exist only one revision, cf fixtures
        ok_(content_w1f1d1, msg='w1f1d1 should be exist')
        content_w1f1d1_id = content_w1f1d1.content_id

        w1f1d1.moveRecursive('/w1/w1f1/w1f1d1_RENAMED.txt')

        # Database content is renamed
        content_w1f1d1 = DBSession.query(ContentRevisionRO) \
            .filter(ContentRevisionRO.content_id == content_w1f1d1_id) \
            .order_by(ContentRevisionRO.revision_id.desc()) \
            .first()
        eq_(
            'w1f1d1_RENAMED',
            content_w1f1d1.label,
            msg='File should be labeled w1f1d1_RENAMED, not {0}'.format(
                content_w1f1d1.label
            )
        )
开发者ID:lebouquetin,项目名称:tracim,代码行数:31,代码来源:test_webdav.py


示例7: test_update_password

    def test_update_password(self):
        self._connect_user(
            '[email protected]',
            'foobarbaz',
        )

        user = DBSession.query(User) \
            .filter(User.email == '[email protected]').one()
        webdav_digest = user.webdav_left_digest_response_hash

        try_post_user = self.app.post(
            '/user/{user_id}/password?_method=PUT'.format(
                user_id=user.user_id
            ),
            OrderedDict([
                ('current_password', 'foobarbaz'),
                ('new_password1', 'new-password'),
                ('new_password2', 'new-password'),
            ])
        )
        eq_(try_post_user.status_code, 302,
            "Code should be 302, but is %d" % try_post_user.status_code)

        user = DBSession.query(User) \
            .filter(User.email == '[email protected]').one()
        ok_(user.validate_password('new-password'))
        ok_(
            webdav_digest != user.webdav_left_digest_response_hash,
            msg='Webdav digest should be updated',
        )
开发者ID:buxx,项目名称:tracim,代码行数:30,代码来源:test_user.py


示例8: test_func__rights_read_workspace_calendar__fail__as_unauthorized

    def test_func__rights_read_workspace_calendar__fail__as_unauthorized(self):
        lawrence = DBSession.query(User).filter(
            User.email == '[email protected]'
        ).one()
        workspace = WorkspaceApi(lawrence).create_workspace(
            'workspace_1',
            save_now=False
        )
        workspace.calendar_enabled = True
        DBSession.flush()

        workspace_calendar_url = CalendarManager.get_workspace_calendar_url(
            workspace.workspace_id
        )

        transaction.commit()

        radicale_base_url = CalendarManager.get_base_url()
        client = caldav.DAVClient(
            radicale_base_url,
            username='[email protected]',
            password='foobarbaz'
        )
        caldav.Calendar(
            parent=client,
            client=client,
            url=workspace_calendar_url
        ).events()
开发者ID:lebouquetin,项目名称:tracim,代码行数:28,代码来源:test_calendar.py


示例9: create

    def create(self, content_type: str, workspace: Workspace, parent: Content=None, label:str ='', do_save=False, is_temporary: bool=False) -> Content:
        assert content_type in ContentType.allowed_types()

        if content_type == ContentType.Folder and not label:
            label = self.generate_folder_label(workspace, parent)

        content = Content()
        content.owner = self._user
        content.parent = parent
        content.workspace = workspace
        content.type = content_type
        content.label = label
        content.is_temporary = is_temporary
        content.revision_type = ActionDescription.CREATION

        if content.type in (
                ContentType.Page,
                ContentType.Thread,
        ):
            content.file_extension = '.html'

        if do_save:
            DBSession.add(content)
            self.save(content, ActionDescription.CREATION)
        return content
开发者ID:lebouquetin,项目名称:tracim,代码行数:25,代码来源:content.py


示例10: _load

 def _load(self, fixture_class):
     if fixture_class not in self._loaded:
         fixture = fixture_class(DBSession)
         fixture.insert()
         self._loaded.append(fixture_class)
         DBSession.flush()
         transaction.commit()
开发者ID:Nonolost,项目名称:tracim,代码行数:7,代码来源:__init__.py


示例11: _get_content_by_label

    def _get_content_by_label(self, label: str) -> Content:
        revision = DBSession.query(ContentRevisionRO) \
            .filter(ContentRevisionRO.label == label) \
            .one()

        return DBSession.query(Content) \
            .filter(Content.id == revision.content_id) \
            .one()
开发者ID:buxx,项目名称:tracim,代码行数:8,代码来源:test_integrity.py


示例12: tearDown

 def tearDown(self):
     """Tear down test fixture for each functional test method."""
     DBSession.close()
     daemons.execute_in_thread('radicale', lambda: transaction.commit())
     teardown_db()
     transaction.commit()
     DBSession.close_all()
     config['tg.app_globals'].sa_engine.dispose()
开发者ID:lebouquetin,项目名称:tracim,代码行数:8,代码来源:__init__.py


示例13: restore_one

    def restore_one(self, workspace_id, flush=True):
        workspace = DBSession.query(Workspace).filter(Workspace.is_deleted==True).filter(Workspace.workspace_id==workspace_id).one()
        workspace.is_deleted = False

        if flush:
            DBSession.flush()

        return workspace
开发者ID:lebouquetin,项目名称:tracim,代码行数:8,代码来源:workspace.py


示例14: _base_query

    def _base_query(self):
        if self._user.profile.id>=Group.TIM_ADMIN:
            return DBSession.query(Workspace).filter(Workspace.is_deleted==False)

        return DBSession.query(Workspace).\
            join(Workspace.roles).\
            filter(UserRoleInWorkspace.user_id==self._user.user_id).\
            filter(Workspace.is_deleted==False)
开发者ID:DarkDare,项目名称:tracim,代码行数:8,代码来源:workspace.py


示例15: test_ldap_auth_sync

    def test_ldap_auth_sync(self):
        # User is unknown in tracim database
        eq_(0, DBSession.query(User).filter(User.email == '[email protected]').count())

        self._connect_user('[email protected]', 'rms')

        # User is registered in tracim database
        eq_(1, DBSession.query(User).filter(User.email == '[email protected]').count())
开发者ID:Nonolost,项目名称:tracim,代码行数:8,代码来源:test_ldap_authentication.py


示例16: test_ldap_auth_fail_no_account

    def test_ldap_auth_fail_no_account(self):
        # User is unknown in tracim database
        eq_(0, DBSession.query(User).filter(User.email == '[email protected]').count())

        self._connect_user('[email protected]', 'no-pass')

        # User is registered in tracim database
        eq_(0, DBSession.query(User).filter(User.email == '[email protected]').count())
开发者ID:Nonolost,项目名称:tracim,代码行数:8,代码来源:test_ldap_authentication.py


示例17: test_create_with_group

    def test_create_with_group(self):
        more_args = ['--add-to-group', 'managers', '--add-to-group', 'administrators']
        self._create_user('[email protected]', 'toor', more_args=more_args)
        user = DBSession.query(User).filter(User.email == '[email protected]').one()
        group_managers = DBSession.query(Group).filter(Group.group_name == 'managers').one()
        group_administrators = DBSession.query(Group).filter(Group.group_name == 'administrators').one()

        ok_(user in group_managers.users)
        ok_(user in group_administrators.users)
开发者ID:Nonolost,项目名称:tracim,代码行数:9,代码来源:user.py


示例18: _create_workspace_and_test

    def _create_workspace_and_test(self, name, user) -> Workspace:
        """
        All extra parameters (*args, **kwargs) are for Workspace init
        :return: Created workspace instance
        """
        WorkspaceApi(user).create_workspace(name, save_now=True)

        eq_(1, DBSession.query(Workspace).filter(Workspace.label == name).count())
        return DBSession.query(Workspace).filter(Workspace.label == name).one()
开发者ID:lebouquetin,项目名称:tracim,代码行数:9,代码来源:__init__.py


示例19: create_one

 def create_one(self, user: User, workspace: Workspace, role_level: int, with_notif: bool, flush: bool=True) -> UserRoleInWorkspace:
     role = self.create_role()
     role.user_id = user.user_id
     role.workspace = workspace
     role.role = role_level
     role.do_notify = with_notif
     if flush:
         DBSession.flush()
     return role
开发者ID:lebouquetin,项目名称:tracim,代码行数:9,代码来源:userworkspace.py


示例20: test_change_groups

    def test_change_groups(self):
        # create an user in managers group
        more_args = ['--add-to-group', 'managers']
        self._create_user('[email protected]', 'toor', more_args=more_args)
        user = DBSession.query(User).filter(User.email == '[email protected]').one()
        group_managers = DBSession.query(Group).filter(Group.group_name == 'managers').one()
        group_administrators = DBSession.query(Group).filter(Group.group_name == 'administrators').one()

        ok_(user in group_managers.users)
        ok_(user not in group_administrators.users)

        # Update him and add to administrators group
        add_to_admins_argvs = ['-l', '[email protected]', '--add-to-group', 'administrators']
        self._execute_command(UpdateUserCommand, 'gearbox user update', add_to_admins_argvs)
        user = DBSession.query(User).filter(User.email == '[email protected]').one()
        group_managers = DBSession.query(Group).filter(Group.group_name == 'managers').one()
        group_administrators = DBSession.query(Group).filter(Group.group_name == 'administrators').one()

        ok_(user in group_managers.users)
        ok_(user in group_administrators.users)

        # remove him from administrators group
        remove_from_admins_argvs = ['-l', '[email protected]', '--remove-from-group', 'administrators']
        self._execute_command(UpdateUserCommand, 'gearbox user update', remove_from_admins_argvs)
        user = DBSession.query(User).filter(User.email == '[email protected]').one()
        group_managers = DBSession.query(Group).filter(Group.group_name == 'managers').one()
        group_administrators = DBSession.query(Group).filter(Group.group_name == 'administrators').one()

        ok_(user in group_managers.users)
        ok_(user not in group_administrators.users)
开发者ID:Nonolost,项目名称:tracim,代码行数:30,代码来源:user.py



注:本文中的tracim.model.DBSession类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python data.Content类代码示例发布时间:2022-05-27
下一篇:
Python model.new_revision函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap