本文整理汇总了Python中stalker.db.session.DBSession.commit方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.commit方法的具体用法?Python DBSession.commit怎么用?Python DBSession.commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stalker.db.session.DBSession
的用法示例。
在下文中一共展示了DBSession.commit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_is_latest_published_version_is_working_properly
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import commit [as 别名]
def test_is_latest_published_version_is_working_properly(self):
"""testing if the is_latest_published_version is working properly
"""
new_version1 = Version(**self.kwargs)
DBSession.add(new_version1)
DBSession.commit()
new_version2 = Version(**self.kwargs)
DBSession.add(new_version2)
DBSession.commit()
new_version3 = Version(**self.kwargs)
DBSession.add(new_version3)
DBSession.commit()
new_version4 = Version(**self.kwargs)
DBSession.add(new_version4)
DBSession.commit()
new_version5 = Version(**self.kwargs)
DBSession.add(new_version5)
DBSession.commit()
new_version1.is_published = True
new_version3.is_published = True
new_version4.is_published = True
self.assertFalse(new_version1.is_latest_published_version())
self.assertFalse(new_version2.is_latest_published_version())
self.assertFalse(new_version3.is_latest_published_version())
self.assertTrue(new_version4.is_latest_published_version())
self.assertFalse(new_version5.is_latest_published_version())
示例2: test_status_list_attribute_is_skipped_and_there_is_a_db_setup
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import commit [as 别名]
def test_status_list_attribute_is_skipped_and_there_is_a_db_setup(self):
"""testing if there will be no error and the status_list attribute is
filled with the correct StatusList instance coming from the database
if there is already a database setup and there is a StatusList instance
defined for the StatusListAutoAddClass.
"""
# create a StatusList for StatusListAutoAddClass
test_status_list = StatusList(
name="StatusListAutoAddClass Statuses",
statuses=[
Status(name="Status1", code="Sts1"),
Status(name="Status2", code="Sts2"),
Status(name="Status3", code="Sts3"),
],
target_entity_type=StatusListAutoAddClass,
)
# add it to the db
DBSession.add(test_status_list)
DBSession.commit()
# now try to create a StatusListAutoAddClass without a status_list
# argument
test_StatusListAutoAddClass = StatusListAutoAddClass(
name="Test StatusListAutoAddClass",
)
# now check if the status_list is equal to test_status_list
self.assertEqual(
test_StatusListAutoAddClass.status_list,
test_status_list
)
示例3: accept
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import commit [as 别名]
def accept(self):
"""overridden accept method
"""
# get the project
try:
project_id = self.projects_combo_box.currentData()
except AttributeError:
index = self.projects_combo_box.currentIndex()
project_id = self.projects_combo_box.itemData(index)
from stalker import Project
project = Project.query.get(project_id)
# get the users
user_names = [
item.text() for item in
self.users_double_list_widget.secondary_items()
]
from stalker import User
if user_names:
users = User.query.filter(User.name.in_(user_names))
else:
users = []
# set the project users
project.users = users
from stalker.db.session import DBSession
DBSession.commit()
super(MainDialog, self).accept()
示例4: accept
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import commit [as 别名]
def accept(self):
"""overridden accept method
"""
if not self.name_lineEdit.is_valid:
QtWidgets.QMessageBox.critical(
self,
'Error',
'Please fix <b>name</b> field!'
)
return
name = self.name_lineEdit.text()
windows_path = self.windows_path_lineEdit.text()
linux_path = self.linux_path_lineEdit.text()
osx_path = self.osx_path_lineEdit.text()
from stalker import Repository
from stalker.db.session import DBSession
logged_in_user = self.get_logged_in_user()
if self.mode == 'Create':
# Create a new Repository
try:
repo = Repository(
name=name,
windows_path=windows_path,
linux_path=linux_path,
osx_path=osx_path
)
self.repository = repo
DBSession.add(repo)
DBSession.commit()
except Exception as e:
DBSession.rollback()
QtWidgets.QMessageBox.critical(
self,
'Error',
str(e)
)
return
elif self.mode == 'Update':
# Update the repository
try:
self.repository.name = name
self.repository.windows_path = windows_path
self.repository.linux_path = linux_path
self.repository.osx_path = osx_path
self.repository.updated_by = logged_in_user
DBSession.add(self.repository)
DBSession.commit()
except Exception as e:
DBSession.rollback()
QtWidgets.QMessageBox.critical(
self,
'Error',
str(e)
)
return
super(MainDialog, self).accept()
示例5: test_status_list_attribute_is_skipped_and_there_is_a_db_setup_but_no_suitable_StatusList
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import commit [as 别名]
def test_status_list_attribute_is_skipped_and_there_is_a_db_setup_but_no_suitable_StatusList(
self):
"""testing if a TypeError will be raised even a database is setup
but there is no suitable StatusList for StatusListNoAutoAddClass in
the database
"""
# create a StatusList for StatusListAutoAddClass
test_status_list = StatusList(
name="StatusListAutoAddClass Statuses",
statuses=[
Status(name="Status1", code="Sts1"),
Status(name="Status2", code="Sts2"),
Status(name="Status3", code="Sts3"),
],
target_entity_type=StatusListAutoAddClass,
)
# add it to the db
DBSession.add(test_status_list)
DBSession.commit()
# now try to create a StatusListAutoAddClass without a status_list
# argument
self.assertRaises(
TypeError,
StatusListNoAutoAddClass,
**{"name": "Test StatusListNoAutoAddClass"}
)
示例6: test_version_number_attribute_is_set_to_a_lower_then_it_should_be
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import commit [as 别名]
def test_version_number_attribute_is_set_to_a_lower_then_it_should_be(self):
"""testing if the version_number attribute will be set to a correct
unique value when it is set to a lower number then it should be
"""
self.test_version.version_number = -1
self.assertEqual(self.test_version.version_number, 1)
self.test_version.version_number = -10
self.assertEqual(self.test_version.version_number, 1)
DBSession.add(self.test_version)
DBSession.commit()
self.test_version.version_number = -100
# it should be 1 again
self.assertEqual(self.test_version.version_number, 1)
new_version = Version(**self.kwargs)
self.assertEqual(new_version.version_number, 2)
new_version.version_number = 1
self.assertEqual(new_version.version_number, 2)
new_version.version_number = 100
self.assertEqual(new_version.version_number, 100)
示例7: test_update_paths_will_preserve_extension
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import commit [as 别名]
def test_update_paths_will_preserve_extension(self):
"""testing if update_paths method will preserve the extension.
"""
# create a FilenameTemplate for Task instances
ft = FilenameTemplate(
name="Task Filename Template",
target_entity_type="Task",
path="{{project.code}}/{%- for parent_task in parent_tasks -%}" "{{parent_task.nice_name}}/{%- endfor -%}",
filename="{{task.nice_name}}_{{version.take_name}}"
'_v{{"%03d"|format(version.version_number)}}{{extension}}',
)
self.test_project.structure.templates.append(ft)
new_version1 = Version(**self.kwargs)
DBSession.add(new_version1)
DBSession.commit()
new_version1.update_paths()
self.assertEqual(new_version1.path, "tp/SH001/Task1")
extension = ".ma"
new_version1.extension = extension
self.assertEqual(new_version1.filename, "Task1_TestTake_v001.ma")
# rename the task and update the paths
self.test_task1.name = "Task2"
# now call update_paths and expect the extension to be preserved
new_version1.update_paths()
self.assertEqual(new_version1.filename, "Task2_TestTake_v001.ma")
self.assertEqual(new_version1.extension, extension)
示例8: upload_thumbnail
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import commit [as 别名]
def upload_thumbnail(task, thumbnail_full_path):
"""Uploads the given thumbnail for the given entity
:param task: An instance of :class:`~stalker.models.entity.SimpleEntity`
or a derivative.
:param str thumbnail_full_path: A string which is showing the path
of the thumbnail image
"""
extension = os.path.splitext(thumbnail_full_path)[-1]
# move the file to the task thumbnail folder
# and mimic StalkerPyramids output format
thumbnail_original_file_name = 'thumbnail%s' % extension
thumbnail_final_full_path = os.path.join(
task.absolute_path, 'Thumbnail', thumbnail_original_file_name
)
try:
os.makedirs(os.path.dirname(thumbnail_final_full_path))
except OSError:
pass
# # convert the thumbnail to jpg if it is a format that is not supported by
# # browsers
# ext_not_supported_by_browsers = ['.bmp', '.tga', '.tif', '.tiff', '.exr']
# if extension in ext_not_supported_by_browsers:
# # use MediaManager to convert them
# from anima.utils import MediaManager
# mm = MediaManager()
# thumbnail_full_path = mm.generate_image_thumbnail(thumbnail_full_path)
shutil.copy(thumbnail_full_path, thumbnail_final_full_path)
from stalker import Link, Version, Repository
thumbnail_os_independent_path = \
Repository.to_os_independent_path(thumbnail_final_full_path)
l_thumb = Link.query\
.filter(Link.full_path == thumbnail_os_independent_path).first()
if not l_thumb:
l_thumb = Link(
full_path=thumbnail_os_independent_path,
original_filename=thumbnail_original_file_name
)
task.thumbnail = l_thumb
# get a version of this Task
from stalker.db.session import DBSession
v = Version.query.filter(Version.task == task).first()
if v:
for naming_parent in v.naming_parents:
if not naming_parent.thumbnail:
naming_parent.thumbnail = l_thumb
DBSession.add(naming_parent)
DBSession.add(l_thumb)
DBSession.commit()
示例9: test_latest_version_attribute_is_working_properly
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import commit [as 别名]
def test_latest_version_attribute_is_working_properly(self):
"""testing if the last_version attribute is working properly
"""
new_version1 = Version(**self.kwargs)
DBSession.add(new_version1)
DBSession.commit()
new_version2 = Version(**self.kwargs)
DBSession.add(new_version2)
DBSession.commit()
new_version3 = Version(**self.kwargs)
DBSession.add(new_version3)
DBSession.commit()
new_version4 = Version(**self.kwargs)
DBSession.add(new_version4)
DBSession.commit()
new_version5 = Version(**self.kwargs)
DBSession.add(new_version5)
DBSession.commit()
self.assertEqual(new_version5.version_number, 5)
self.assertEqual(new_version1.latest_version, new_version5)
self.assertEqual(new_version2.latest_version, new_version5)
self.assertEqual(new_version3.latest_version, new_version5)
self.assertEqual(new_version4.latest_version, new_version5)
self.assertEqual(new_version5.latest_version, new_version5)
示例10: reject
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import commit [as 别名]
def reject(self):
QtWidgets.QDialog.reject(self)
from stalker.db.session import DBSession
if self.version:
DBSession.delete(self.version)
DBSession.commit()
DBSession.rollback()
示例11: __create_admin__
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import commit [as 别名]
def __create_admin__():
"""creates the admin
"""
from stalker.models.auth import User
from stalker.models.department import Department
# check if there is already an admin in the database
admin = User.query.filter_by(name=defaults.admin_name).first()
if admin:
# there should be an admin user do nothing
logger.debug("there is an admin already")
return
logger.debug("creating the default administrator user")
# create the admin department
admin_department = Department.query.filter_by(name=defaults.admin_department_name).first()
if not admin_department:
admin_department = Department(name=defaults.admin_department_name)
DBSession.add(admin_department)
# create the admins group
from stalker.models.auth import Group
admins_group = Group.query.filter_by(name=defaults.admin_group_name).first()
if not admins_group:
admins_group = Group(name=defaults.admin_group_name)
DBSession.add(admins_group)
# # create the admin user
# admin = User.query \
# .filter_by(name=defaults.admin_name) \
# .first()
# if not admin:
admin = User(
name=defaults.admin_name,
login=defaults.admin_login,
password=defaults.admin_password,
email=defaults.admin_email,
departments=[admin_department],
groups=[admins_group],
)
admin.created_by = admin
admin.updated_by = admin
# update the department as created and updated by admin user
admin_department.created_by = admin
admin_department.updated_by = admin
admins_group.created_by = admin
admins_group.updated_by = admin
DBSession.add(admin)
DBSession.commit()
示例12: export_as
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import commit [as 别名]
def export_as(self, version):
"""the export action for max environment
"""
import MaxPlus
# check if there is something selected
if MaxPlus.SelectionManager.GetCount() < 1:
raise RuntimeError("There is nothing selected to export")
# check if this is the first version
if version.is_published and not self.allow_publish_on_export:
# it is not allowed to publish the first version (desdur)
raise RuntimeError(
'It is not allowed to Publish while export!!!'
'<br><br>'
'Export it normally. Then open the file and publish it.'
)
# do not save if there are local files
# self.check_external_files(version)
# set the extension to max by default
version.update_paths()
version.extension = self.extensions[0]
# define that this version is created with Max
version.created_with = self.name
# create the folder if it doesn't exists
import os
try:
os.makedirs(version.absolute_path)
except OSError:
# already exists
pass
# workspace_path = os.path.dirname(version.absolute_path)
workspace_path = version.absolute_path
# self.create_workspace_file(workspace_path)
# self.create_workspace_folders(workspace_path)
# export the file
MaxPlus.FileManager.SaveSelected(version.absolute_full_path)
# save the version to database
from stalker.db.session import DBSession
DBSession.add(version)
DBSession.commit()
# create a local copy
self.create_local_copy(version)
return True
示例13: test_timeLog_prevents_auto_flush_when_expanding_task_schedule_timing
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import commit [as 别名]
def test_timeLog_prevents_auto_flush_when_expanding_task_schedule_timing(self):
"""testing timeLog prevents auto flush when expanding task
schedule_timing attribute
"""
from stalker.db.session import DBSession
tlog1 = TimeLog(**self.kwargs)
DBSession.add(tlog1)
DBSession.commit()
# create a new time log
self.kwargs['start'] = self.kwargs['start'] + self.kwargs['duration']
tlog2 = TimeLog(**self.kwargs)
示例14: create_alembic_table
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import commit [as 别名]
def create_alembic_table():
"""creates the default alembic_version table and creates the data so that
any new database will be considered as the latest version
"""
# Now, this is not the correct way of doing, there is a proper way of doing
# it and it is explained nicely in the Alembic library documentation.
#
# But it is simply not working when Stalker is installed as a package.
#
# So as a workaround here we are doing it manually
# don't forget to update the version_num (and the corresponding test
# whenever a new alembic revision is created)
version_num = '2e4a3813ae76'
from sqlalchemy import Table, Column, Text
table_name = 'alembic_version'
conn = DBSession.connection()
engine = conn.engine
# check if the table is already there
table = Table(
table_name, Base.metadata,
Column('version_num', Text),
extend_existing=True
)
if not engine.dialect.has_table(conn, table_name):
logger.debug('creating alembic_version table')
# create the table no matter if it exists or not we need it either way
Base.metadata.create_all(engine)
# first try to query the version value
sql_query = 'select version_num from "alembic_version"'
try:
version_num = \
DBSession.connection().execute(sql_query).fetchone()[0]
except TypeError:
logger.debug('inserting %s to alembic_version table' % version_num)
# the table is there but there is no value so insert it
ins = table.insert().values(version_num=version_num)
DBSession.connection().execute(ins)
DBSession.commit()
logger.debug('alembic_version table is created and initialized')
else:
# the value is there do not touch the table
logger.debug(
'alembic_version table is already there, not doing anything!'
)
示例15: create_ticket_statuses
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import commit [as 别名]
def create_ticket_statuses():
"""creates the default ticket statuses
"""
from stalker import User
# create as admin
admin = User.query.filter(User.login == defaults.admin_name).first()
# create statuses for Tickets
ticket_names = defaults.ticket_status_names
ticket_codes = defaults.ticket_status_codes
create_entity_statuses('Ticket', ticket_names, ticket_codes, admin)
# Again I hate doing this in this way
from stalker import Type
types = Type.query \
.filter_by(target_entity_type="Ticket") \
.all()
t_names = [t.name for t in types]
# create Ticket Types
logger.debug("Creating Ticket Types")
if 'Defect' not in t_names:
ticket_type_1 = Type(
name='Defect',
code='Defect',
target_entity_type='Ticket',
created_by=admin,
updated_by=admin
)
DBSession.add(ticket_type_1)
if 'Enhancement' not in t_names:
ticket_type_2 = Type(
name='Enhancement',
code='Enhancement',
target_entity_type='Ticket',
created_by=admin,
updated_by=admin
)
DBSession.add(ticket_type_2)
try:
DBSession.commit()
except IntegrityError:
DBSession.rollback()
logger.debug("Ticket Types are already in the database!")
else:
# DBSession.flush()
logger.debug("Ticket Types are created successfully")