本文整理汇总了Python中tracim.model.DBSession.flush方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.flush方法的具体用法?Python DBSession.flush怎么用?Python DBSession.flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tracim.model.DBSession
的用法示例。
在下文中一共展示了DBSession.flush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ensure_calendar_exist
# 需要导入模块: from tracim.model import DBSession [as 别名]
# 或者: from tracim.model.DBSession import flush [as 别名]
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,
)
示例2: test_new_revision
# 需要导入模块: from tracim.model import DBSession [as 别名]
# 或者: from tracim.model.DBSession import flush [as 别名]
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)
示例3: create_workspace
# 需要导入模块: from tracim.model import DBSession [as 别名]
# 或者: from tracim.model.DBSession import flush [as 别名]
def create_workspace(
self,
label: str='',
description: str='',
calendar_enabled: bool=False,
save_now: bool=False,
) -> Workspace:
if not label:
label = self.generate_label()
workspace = Workspace()
workspace.label = label
workspace.description = description
workspace.calendar_enabled = calendar_enabled
# By default, we force the current user to be the workspace manager
# And to receive email notifications
role = RoleApi(self._user).create_one(self._user, workspace,
UserRoleInWorkspace.WORKSPACE_MANAGER,
with_notif=True)
DBSession.add(workspace)
DBSession.add(role)
if save_now:
DBSession.flush()
if calendar_enabled:
self.ensure_calendar_exist(workspace)
else:
self.disable_calendar(workspace)
return workspace
示例4: test_update
# 需要导入模块: from tracim.model import DBSession [as 别名]
# 或者: from tracim.model.DBSession import flush [as 别名]
def test_update(self):
created_content = self.test_create()
content = DBSession.query(Content).filter(Content.id == created_content.id).one()
eq_(1, DBSession.query(ContentRevisionRO).filter(ContentRevisionRO.label == 'TEST_CONTENT_1').count())
with new_revision(content):
time.sleep(0.00001)
content.description = 'TEST_CONTENT_DESCRIPTION_1_UPDATED'
DBSession.flush()
eq_(2, DBSession.query(ContentRevisionRO).filter(ContentRevisionRO.label == 'TEST_CONTENT_1').count())
eq_(1, DBSession.query(Content).filter(Content.id == created_content.id).count())
with new_revision(content):
time.sleep(0.00001)
content.description = 'TEST_CONTENT_DESCRIPTION_1_UPDATED_2'
content.label = 'TEST_CONTENT_1_UPDATED_2'
DBSession.flush()
eq_(1, DBSession.query(ContentRevisionRO).filter(ContentRevisionRO.label == 'TEST_CONTENT_1_UPDATED_2').count())
eq_(1, DBSession.query(Content).filter(Content.id == created_content.id).count())
revision_1 = DBSession.query(ContentRevisionRO)\
.filter(ContentRevisionRO.description == 'TEST_CONTENT_DESCRIPTION_1').one()
revision_2 = DBSession.query(ContentRevisionRO)\
.filter(ContentRevisionRO.description == 'TEST_CONTENT_DESCRIPTION_1_UPDATED').one()
revision_3 = DBSession.query(ContentRevisionRO)\
.filter(ContentRevisionRO.description == 'TEST_CONTENT_DESCRIPTION_1_UPDATED_2').one()
# Updated dates must be different
ok_(revision_1.updated < revision_2.updated < revision_3.updated)
# Created dates must be equal
ok_(revision_1.created == revision_2.created == revision_3.created)
示例5: test_serializer_content__menui_api_context__children
# 需要导入模块: from tracim.model import DBSession [as 别名]
# 或者: from tracim.model.DBSession import flush [as 别名]
def test_serializer_content__menui_api_context__children(self):
folder_without_child = Content()
folder_without_child.type = ContentType.Folder
res = Context(CTX.MENU_API).toDict(folder_without_child)
eq_(False, res['children'])
folder_with_child = Content()
folder_with_child.type = ContentType.Folder
folder_without_child.parent = folder_with_child
DBSession.add(folder_with_child)
DBSession.add(folder_without_child)
DBSession.flush()
res = Context(CTX.MENU_API).toDict(folder_with_child)
eq_(True, res['children'])
for curtype in ContentType.all():
if curtype not in (ContentType.Folder, ContentType.Comment):
item = Content()
item.type = curtype
fake_child = Content()
fake_child.type = curtype
fake_child.parent = item
DBSession.add(item)
DBSession.add(fake_child)
DBSession.flush()
res = Context(CTX.MENU_API).toDict(item)
eq_(False, res['children'])
示例6: test_func__rights_read_workspace_calendar__fail__as_unauthorized
# 需要导入模块: from tracim.model import DBSession [as 别名]
# 或者: from tracim.model.DBSession import flush [as 别名]
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()
示例7: test_create
# 需要导入模块: from tracim.model import DBSession [as 别名]
# 或者: from tracim.model.DBSession import flush [as 别名]
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
示例8: _load
# 需要导入模块: from tracim.model import DBSession [as 别名]
# 或者: from tracim.model.DBSession import flush [as 别名]
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()
示例9: restore_one
# 需要导入模块: from tracim.model import DBSession [as 别名]
# 或者: from tracim.model.DBSession import flush [as 别名]
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
示例10: create_one
# 需要导入模块: from tracim.model import DBSession [as 别名]
# 或者: from tracim.model.DBSession import flush [as 别名]
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
示例11: create_one
# 需要导入模块: from tracim.model import DBSession [as 别名]
# 或者: from tracim.model.DBSession import flush [as 别名]
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
if with_notif is not None:
from tracim.lib.helpers import on_off_to_boolean
role.do_notify = on_off_to_boolean(with_notif)
if flush:
DBSession.flush()
return role
示例12: post
# 需要导入模块: from tracim.model import DBSession [as 别名]
# 或者: from tracim.model.DBSession import flush [as 别名]
def post(self, name, description, calendar_enabled: str='off'):
# FIXME - Check user profile
user = tmpl_context.current_user
workspace_api_controller = WorkspaceApi(user)
calendar_enabled = on_off_to_boolean(calendar_enabled)
workspace = workspace_api_controller.create_workspace(name, description)
workspace.calendar_enabled = calendar_enabled
DBSession.flush()
tg.flash(_('{} workspace created.').format(workspace.label), CST.STATUS_OK)
tg.redirect(self.url())
return
示例13: _create_content_and_test
# 需要导入模块: from tracim.model import DBSession [as 别名]
# 或者: from tracim.model.DBSession import flush [as 别名]
def _create_content_and_test(self, name, workspace, *args, **kwargs) -> Content:
"""
All extra parameters (*args, **kwargs) are for Content init
:return: Created Content instance
"""
content = Content(*args, **kwargs)
content.label = name
content.workspace = workspace
DBSession.add(content)
DBSession.flush()
eq_(1, ContentApi.get_canonical_query().filter(Content.label == name).count())
return ContentApi.get_canonical_query().filter(Content.label == name).one()
示例14: create_user
# 需要导入模块: from tracim.model import DBSession [as 别名]
# 或者: from tracim.model.DBSession import flush [as 别名]
def create_user(self, email=None, groups=[], save_now=False) -> User:
user = User()
if email:
user.email = email
for group in groups:
user.groups.append(group)
DBSession.add(user)
if save_now:
DBSession.flush()
return user
示例15: update_event
# 需要导入模块: from tracim.model import DBSession [as 别名]
# 或者: from tracim.model.DBSession import flush [as 别名]
def update_event(
self,
calendar: Calendar,
event: iCalendarEvent,
event_name: str,
current_user: User,
) -> Content:
"""
Update Content Event
:param calendar: Event calendar owner
:param event: ICS event
:param event_name: Event name (ID) like
20160602T083511Z-18100-1001-1-71_Bastien-20160602T083516Z.ics
:param current_user: Current modification asking user
:return: Updated Content
"""
workspace = None
if isinstance(calendar, WorkspaceCalendar):
workspace = calendar.related_object
elif isinstance(calendar, UserCalendar):
pass
else:
raise UnknownCalendarType('Type "{0}" is not implemented'
.format(type(calendar)))
content_api = ContentApi(
current_user,
force_show_all_types=True,
disable_user_workspaces_filter=True
)
content = content_api.find_one_by_unique_property(
property_name='name',
property_value=event_name,
workspace=workspace
)
with new_revision(content):
self.populate_content_with_event(
content,
event,
event_name
)
content.revision_type = ActionDescription.EDITION
DBSession.flush()
transaction.commit()
return content