本文整理汇总了Python中stalker.db.session.DBSession类的典型用法代码示例。如果您正苦于以下问题:Python DBSession类的具体用法?Python DBSession怎么用?Python DBSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DBSession类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_status_list_attribute_is_skipped_and_there_is_a_db_setup_but_no_suitable_StatusList
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"}
)
开发者ID:Industriromantik,项目名称:stalker,代码行数:30,代码来源:test_statusMixin.py
示例2: test_status_list_attribute_is_skipped_and_there_is_a_db_setup
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
)
开发者ID:Industriromantik,项目名称:stalker,代码行数:32,代码来源:test_statusMixin.py
示例3: test_version_number_attribute_is_set_to_a_lower_then_it_should_be
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)
开发者ID:noflame,项目名称:stalker,代码行数:25,代码来源:test_version.py
示例4: test_update_paths_will_preserve_extension
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)
开发者ID:noflame,项目名称:stalker,代码行数:30,代码来源:test_version.py
示例5: accept
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()
开发者ID:eoyilmaz,项目名称:anima,代码行数:31,代码来源:project_users_dialog.py
示例6: setup
def setup(settings=None):
"""Utility function that helps to connect the system to the given database.
if the database is None then the it setups using the default database in
the settings file.
:param settings: This is a dictionary which has keys prefixed with
"sqlalchemy" and shows the settings. The most important one is the
engine. The default is None, and in this case it uses the settings from
stalker.config.Config.database_engine_settings
"""
if settings is None:
settings = defaults.database_engine_settings
logger.debug("no settings given, using the default: %s" % settings)
logger.debug("settings: %s" % settings)
# create engine
engine = engine_from_config(settings, "sqlalchemy.")
logger.debug("engine: %s" % engine)
# create the Session class
DBSession.remove()
DBSession.configure(bind=engine, extension=None)
# create the database
logger.debug("creating the tables")
Base.metadata.create_all(engine)
# update defaults
update_defaults_with_studio()
开发者ID:GreenEminence,项目名称:stalker,代码行数:32,代码来源:__init__.py
示例7: tearDown
def tearDown(self):
os.rmdir(self.test_repo.linux_path)
os.rmdir(self.test_repo.windows_path)
os.rmdir(self.test_repo.osx_path)
DBSession.remove()
testing.tearDown()
开发者ID:Dr-Rakcha,项目名称:stalker-pyramid,代码行数:7,代码来源:test_version.py
示例8: export_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
开发者ID:eoyilmaz,项目名称:anima,代码行数:53,代码来源:__init__.py
示例9: test_timeLog_prevents_auto_flush_when_expanding_task_schedule_timing
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)
开发者ID:Industriromantik,项目名称:stalker,代码行数:13,代码来源:test_time_log.py
示例10: create_entity_statuses
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()
开发者ID:GreenEminence,项目名称:stalker,代码行数:49,代码来源:__init__.py
示例11: get_alembic_version
def get_alembic_version():
"""returns the alembic version of the database
"""
# try to query the version value
conn = DBSession.connection()
engine = conn.engine
if engine.dialect.has_table(conn, 'alembic_version'):
sql_query = 'select version_num from alembic_version'
try:
return DBSession.connection().execute(sql_query).fetchone()[0]
except (OperationalError, ProgrammingError, TypeError):
DBSession.rollback()
return None
else:
return None
开发者ID:Industriromantik,项目名称:stalker,代码行数:15,代码来源:__init__.py
示例12: __create_admin__
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()
开发者ID:GreenEminence,项目名称:stalker,代码行数:58,代码来源:__init__.py
示例13: list_all
def list_all(self):
"""lists other representations
"""
base_take_name = self.get_base_take_name(self.version)
# find any version that starts with the base_repr_name
# under the same task
from stalker import Version
from stalker.db.session import DBSession
from sqlalchemy import distinct
take_names = map(
lambda x: x[0],
DBSession.query(distinct(Version.take_name))
.filter(Version.task == self.version.task)
.all()
)
take_names.sort()
repr_names = []
for take_name in take_names:
if take_name.startswith(base_take_name):
if take_name != base_take_name:
repr_names.append(
take_name[len(base_take_name) +
len(self.repr_separator):]
)
else:
repr_names.append(self.base_repr_name)
return repr_names
开发者ID:eoyilmaz,项目名称:anima,代码行数:29,代码来源:representation.py
示例14: get_filtered_entities
def get_filtered_entities(self):
"""returns the filtered entities according to the filter selection
"""
project_id = self.get_project_id()
entity_type = self.filter_by_entity_type_combo_box.currentText()
sequence_id = self.get_sequence_id()
task_type_id = self.get_task_type_id()
resource_id = self.get_resource_id()
from stalker import db, Task
from stalker.db.session import DBSession
query = DBSession.query(Task.id, Task.name)
if project_id != -1:
query = query.filter(Task.project_id == project_id)
if task_type_id != -1:
query = query.filter(Task.type_id == task_type_id)
if entity_type != self.generic_selection_text:
query = query.filter(Task.entity_type == entity_type)
# if entity_type == 'Shot':
# from stalker.models.shot import Shot_Sequences
# query = query.filter(Shot_Sequences)
# query the child tasks
query = query.order_by(Task.name)
return query.all()
开发者ID:eoyilmaz,项目名称:anima,代码行数:30,代码来源:task_manager.py
示例15: project_changed
def project_changed(self, project_name):
"""runs when the project in the combo box changed
"""
try:
project_id = self.projects_combo_box.currentData()
except AttributeError:
index = self.projects_combo_box.currentIndex()
project_id = self.projects_combo_box.itemData(index)
# refresh the items on the double list widget
self.users_double_list_widget.clear()
# get users not in the project
from stalker.db.session import DBSession
from stalker import User
from stalker.models.project import ProjectUser
project_users = DBSession.query(User.id, User.name).join(ProjectUser)\
.filter(ProjectUser.project_id == project_id)\
.filter(User.id == ProjectUser.user_id)\
.all()
project_user_ids = [u.id for u in project_users]
if project_user_ids:
users_not_in_project = [
u.name
for u in DBSession.query(User.name)
.filter(~User.id.in_(project_user_ids)).all()
]
else:
users_not_in_project = [
u.name
for u in DBSession.query(User.name).all()
]
self.users_double_list_widget.add_primary_items(
users_not_in_project
)
users_in_project = \
[u.name for u in project_users]
self.users_double_list_widget.add_secondary_items(
users_in_project
)
开发者ID:eoyilmaz,项目名称:anima,代码行数:46,代码来源:project_users_dialog.py
示例16: setUp
def setUp(self):
self.config = testing.setUp()
db.setup({'sqlalchemy.url': 'sqlite:///:memory:'})
self.test_status1 = Status(name='Test Status 1', code='TS1')
self.test_status2 = Status(name='Test Status 2', code='TS2')
self.test_status3 = Status(name='Test Status 3', code='TS3')
self.test_project_status_list = StatusList(
target_entity_type='Project',
statuses=[
self.test_status1,
self.test_status2,
self.test_status3
]
)
self.test_repo = Repository(
name='Test Repository',
windows_path='T:/',
linux_path='/mnt/T',
osx_path='/Volumes/T'
)
self.test_project = Project(
name='Test Project 1',
code='TP1',
status_list=self.test_project_status_list,
repository=self.test_repo
)
DBSession.add(self.test_project)
transaction.commit()
DBSession.add(self.test_project)
self.params = {
'mode': 'CREATE'
}
self.matchdict = {
'project_id': self.test_project.id
}
self.request = testing.DummyRequest(params=self.params)
self.request.matchdict = self.matchdict
开发者ID:Dr-Rakcha,项目名称:stalker-pyramid,代码行数:45,代码来源:test_asset.py
示例17: get_current_resource_id
def get_current_resource_id(self):
"""returns the current resource
"""
resource_name = self.resource_combo_box.currentText()
from stalker import User
from stalker.db.session import DBSession
return DBSession.query(User.id)\
.filter(User.name == resource_name)\
.first()
开发者ID:eoyilmaz,项目名称:anima,代码行数:9,代码来源:time_log_dialog.py
示例18: login
def login(self):
"""does the nasty details for user to login
"""
# check the given user password
from stalker import User
# get the user first
login = self.login_or_email_lineEdit.text()
password = self.password_lineEdit.text()
# check with the login or email attribute
user = User.query \
.filter(or_(User.login == login, User.email == login)) \
.first()
if user:
self.success = user.check_password(password)
if self.success:
from stalker.models.auth import LocalSession
session = LocalSession()
session.store_user(user)
session.save()
# also store a log
import datetime
from stalker.models.auth import LOGIN, AuthenticationLog
al = AuthenticationLog(
user=user,
date=datetime.datetime.now(),
action=LOGIN
)
from stalker.db.session import DBSession
DBSession.add(al)
DBSession.commit()
self.accept()
else:
QtWidgets.QMessageBox.critical(
self,
"Error",
"login or password is incorrect"
)
开发者ID:eoyilmaz,项目名称:anima,代码行数:44,代码来源:login_dialog.py
示例19: setup
def setup(settings=None):
"""Utility function that helps to connect the system to the given database.
if the database is None then the it setups using the default database in
the settings file.
:param settings: This is a dictionary which has keys prefixed with
"sqlalchemy" and shows the settings. The most important one is the
engine. The default is None, and in this case it uses the settings from
stalker.config.Config.database_engine_settings
"""
if settings is None:
settings = defaults.database_engine_settings
logger.debug('no settings given, using the default: %s' % settings)
logger.debug("settings: %s" % settings)
# create engine
engine = engine_from_config(settings, 'sqlalchemy.')
logger.debug('engine: %s' % engine)
# create the Session class
DBSession.remove()
DBSession.configure(
bind=engine,
extension=None
)
# check alembic versions of the database
# and raise an error if it is not matching with the system
check_alembic_version()
# create the database
logger.debug("creating the tables")
Base.metadata.create_all(engine)
# update defaults
update_defaults_with_studio()
# create repo env variables
create_repo_vars()
开发者ID:Industriromantik,项目名称:stalker,代码行数:42,代码来源:__init__.py
示例20: test_absolute_full_path_works_properly
def test_absolute_full_path_works_properly(self):
"""testing if the absolute_full_path attribute works properly
"""
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()
new_version1.extension = ".ma"
self.assertEqual(new_version1.extension, ".ma")
self.assertEqual(new_version1.absolute_full_path, "/mnt/T/tp/SH001/Task1/Task1_TestTake_v001.ma")
开发者ID:noflame,项目名称:stalker,代码行数:20,代码来源:test_version.py
注:本文中的stalker.db.session.DBSession类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论