本文整理汇总了Python中stalker.db.session.DBSession.add方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.add方法的具体用法?Python DBSession.add怎么用?Python DBSession.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stalker.db.session.DBSession
的用法示例。
在下文中一共展示了DBSession.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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 add [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
)
示例2: upload_thumbnail
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import add [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()
示例3: 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 add [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)
示例4: test_is_latest_published_version_is_working_properly
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import add [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())
示例5: test_update_paths_will_preserve_extension
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import add [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)
示例6: test_latest_version_attribute_is_working_properly
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import add [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)
示例7: accept
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import add [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()
示例8: 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 add [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"}
)
示例9: export_as
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import add [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
示例10: test_timeLog_prevents_auto_flush_when_expanding_task_schedule_timing
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import add [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)
示例11: create_ticket_statuses
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import add [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")
示例12: test_version_number_attribute_is_automatically_generated
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import add [as 别名]
def test_version_number_attribute_is_automatically_generated(self):
"""testing if the version_number attribute is automatically generated
"""
self.assertEqual(self.test_version.version_number, 1)
DBSession.add(self.test_version)
DBSession.commit()
new_version = Version(**self.kwargs)
DBSession.add(new_version)
DBSession.commit()
self.assertEqual(self.test_version.task, new_version.task)
self.assertEqual(self.test_version.take_name, new_version.take_name)
self.assertEqual(new_version.version_number, 2)
new_version = Version(**self.kwargs)
DBSession.add(new_version)
DBSession.commit()
self.assertEqual(self.test_version.task, new_version.task)
self.assertEqual(self.test_version.take_name, new_version.take_name)
self.assertEqual(new_version.version_number, 3)
new_version = Version(**self.kwargs)
DBSession.add(new_version)
DBSession.commit()
self.assertEqual(self.test_version.task, new_version.task)
self.assertEqual(self.test_version.take_name, new_version.take_name)
self.assertEqual(new_version.version_number, 4)
示例13: create_entity_statuses
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import add [as 别名]
def create_entity_statuses(entity_type="", status_names=None, status_codes=None, user=None):
"""creates the default task statuses
"""
if not entity_type:
raise ValueError("Please supply entity_type")
if not status_names:
raise ValueError("Please supply status names")
if not status_codes:
raise ValueError("Please supply status codes")
# create statuses for entity
from stalker import Status, StatusList
logger.debug("Creating %s Statuses" % entity_type)
statuses = Status.query.filter(Status.name.in_(status_names)).all()
status_names_in_db = map(lambda x: x.name, statuses)
for name, code in zip(status_names, status_codes):
if name not in status_names_in_db:
logger.debug("Creating Status: %s (%s)" % (name, code))
new_status = Status(name=name, code=code, created_by=user, updated_by=user)
statuses.append(new_status)
DBSession.add(new_status)
# create the Status List
status_list = StatusList.query.filter(StatusList.target_entity_type == entity_type).first()
if status_list is None:
logger.debug("No %s Status List found, creating new!" % entity_type)
status_list = StatusList(
name="%s Statuses" % entity_type, target_entity_type=entity_type, created_by=user, updated_by=user
)
else:
logger.debug("%s Status List already created, updating statuses" % entity_type)
status_list.statuses = statuses
DBSession.add(status_list)
try:
DBSession.commit()
except IntegrityError as e:
logger.debug("error in DBSession.commit, rolling back: %s" % e)
DBSession.rollback()
else:
logger.debug("Created %s Statuses successfully" % entity_type)
DBSession.flush()
示例14: test_number_attribute_is_automatically_increased
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import add [as 别名]
def test_number_attribute_is_automatically_increased(self):
"""testing if the number attribute is automatically increased
"""
# create two new tickets
ticket1 = Ticket(**self.kwargs)
DBSession.add(ticket1)
DBSession.commit()
ticket2 = Ticket(**self.kwargs)
DBSession.add(ticket2)
DBSession.commit()
self.assertEqual(ticket1.number + 1, ticket2.number)
self.assertEqual(ticket1.number, 2)
self.assertEqual(ticket2.number, 3)
示例15: test_email_argument_should_be_a_unique_value
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import add [as 别名]
def test_email_argument_should_be_a_unique_value(self):
"""testing if the email argument should be a unique value
"""
# this test should include a database
test_email = "[email protected]"
self.kwargs["login"] = "test_user1"
self.kwargs["email"] = test_email
user1 = User(**self.kwargs)
DBSession.add(user1)
DBSession.commit()
self.kwargs["login"] = "test_user2"
user2 = User(**self.kwargs)
DBSession.add(user2)
self.assertRaises(Exception, DBSession.commit)