本文整理汇总了Python中stalker.db.DBSession.add方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.add方法的具体用法?Python DBSession.add怎么用?Python DBSession.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stalker.db.DBSession
的用法示例。
在下文中一共展示了DBSession.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_update_with_studio_is_working_properly
# 需要导入模块: from stalker.db import DBSession [as 别名]
# 或者: from stalker.db.DBSession import add [as 别名]
def test_update_with_studio_is_working_properly(self):
"""testing if the default values are updated with the Studio instance
if there is a database connection and there is a Studio in there
"""
import datetime
from stalker import db, defaults
from stalker.db.session import DBSession
from stalker.models.studio import Studio
db.setup()
db.init()
# check the defaults are still using them self
self.assertEqual(
defaults.timing_resolution,
datetime.timedelta(hours=1)
)
studio = Studio(
name='Test Studio',
timing_resolution=datetime.timedelta(minutes=15)
)
DBSession.add(studio)
DBSession.commit()
# now check it again
self.assertEqual(
defaults.timing_resolution,
studio.timing_resolution
)
示例2: test_tasks_are_correctly_scheduled_when_compute_resources_is_True
# 需要导入模块: from stalker.db import DBSession [as 别名]
# 或者: from stalker.db.DBSession import add [as 别名]
def test_tasks_are_correctly_scheduled_when_compute_resources_is_True(self):
"""testing if the tasks are correctly scheduled when the compute
resources is True
"""
tjp_sched = TaskJugglerScheduler(compute_resources=True)
test_studio = Studio(name="Test Studio", now=datetime.datetime(2013, 4, 16, 0, 0))
test_studio.start = datetime.datetime(2013, 4, 16, 0, 0)
test_studio.end = datetime.datetime(2013, 4, 30, 0, 0)
test_studio.daily_working_hours = 9
DBSession.add(test_studio)
tjp_sched.studio = test_studio
tjp_sched.schedule()
db.DBSession.commit()
# check if the task and project timings are all adjusted
self.assertEqual(datetime.datetime(2013, 4, 16, 9, 0), self.test_proj1.computed_start)
self.assertEqual(datetime.datetime(2013, 4, 24, 10, 0), self.test_proj1.computed_end)
self.assertEqual(datetime.datetime(2013, 4, 16, 9, 0), self.test_task1.computed_start)
self.assertEqual(datetime.datetime(2013, 4, 18, 16, 0), self.test_task1.computed_end)
self.assertEqual(
sorted([self.test_user1, self.test_user2], key=lambda x: x.name),
sorted(self.test_task1.computed_resources, key=lambda x: x.name),
)
self.assertEqual(datetime.datetime(2013, 4, 18, 16, 0), self.test_task2.computed_start)
self.assertEqual(datetime.datetime(2013, 4, 24, 10, 0), self.test_task2.computed_end)
self.assertEqual(
sorted([self.test_user4, self.test_user5], key=lambda x: x.name),
sorted(self.test_task2.computed_resources, key=lambda x: x.name),
)
示例3: update_sequence
# 需要导入模块: from stalker.db import DBSession [as 别名]
# 或者: from stalker.db.DBSession import add [as 别名]
def update_sequence(request):
"""runs when adding a new sequence
"""
logged_in_user = get_logged_in_user(request)
sequence_id = request.params.get('sequence_id')
sequence = Sequence.query.filter_by(id=sequence_id).first()
name = request.params.get('name')
code = request.params.get('code')
status_id = request.params.get('status_id')
status = Status.query.filter_by(id=status_id).first()
if sequence and code and name and status:
# get descriptions
description = request.params.get('description')
#update the sequence
sequence.name = name
sequence.code = code
sequence.description = description
sequence.status = status
sequence.updated_by = logged_in_user
sequence.date_updated = datetime.datetime.now()
DBSession.add(sequence)
else:
logger.debug('there are missing parameters')
logger.debug('name : %s' % name)
logger.debug('status : %s' % status)
HTTPServerError()
return HTTPOk()
示例4: update_structure
# 需要导入模块: from stalker.db import DBSession [as 别名]
# 或者: from stalker.db.DBSession import add [as 别名]
def update_structure(request):
"""updates a structure
"""
logged_in_user = get_logged_in_user(request)
# get params
structure_id = request.params.get('structure_id')
structure = Structure.query.filter_by(id=structure_id).first()
name = request.params.get('name')
custom_template = request.params.get('custom_template')
# get all FilenameTemplates
ft_ids = get_multi_integer(request, 'filename_templates')
fts = FilenameTemplate.query.filter(FilenameTemplate.id.in_(ft_ids)).all()
if name:
# update structure
structure.name = name
structure.custom_template = custom_template
structure.templates = fts
structure.updated_by = logged_in_user
structure.date_updated = datetime.datetime.now()
DBSession.add(structure)
return HTTPOk()
示例5: test_creating_a_time_log_for_a_task_whose_dependent_tasks_has_not_finished_yet
# 需要导入模块: from stalker.db import DBSession [as 别名]
# 或者: from stalker.db.DBSession import add [as 别名]
def test_creating_a_time_log_for_a_task_whose_dependent_tasks_has_not_finished_yet(self):
"""testing if a HTTPServer error will be raised when a time log tried
to be created for a Task whose dependent tasks has not finished yet
"""
# create a new task
task2 = Task(
name='Test Task 2',
project=self.proj1,
depends=[self.task1],
resources=[self.user1],
schedule_timing=4,
schedule_unit='d',
schedule_model='effort',
status_list=self.task_status_list
)
DBSession.add(task2)
DBSession.flush()
transaction.commit()
# now because task2 is depending on to the task1
# and task1 is not finished yet (where the status is not
# set to Complete, we should expect an HTTPServerError()
# to be raised
request = testing.DummyRequest()
request.params['task_id'] = task2.id
request.params['resource_id'] = self.user1.id
request.params['start'] = "Fri, 01 Nov 2013 08:00:00 GMT"
request.params['end'] = "Fri, 01 Nov 2013 17:00:00 GMT"
response = time_log.create_time_log(request)
self.assertEqual(
response.status_int, 500
)
示例6: assign_thumbnail
# 需要导入模块: from stalker.db import DBSession [as 别名]
# 或者: from stalker.db.DBSession import add [as 别名]
def assign_thumbnail(request):
"""assigns the thumbnail to the given entity
"""
link_ids = get_multi_integer(request, 'link_ids[]')
entity_id = request.params.get('entity_id', -1)
link = Link.query.filter(Link.id.in_(link_ids)).first()
entity = Entity.query.filter_by(id=entity_id).first()
logger.debug('link_ids : %s' % link_ids)
logger.debug('link : %s' % link)
logger.debug('entity_id : %s' % entity_id)
logger.debug('entity : %s' % entity)
logged_in_user = get_logged_in_user(request)
if entity and link:
entity.thumbnail = link
# resize the thumbnail
file_full_path = convert_file_link_to_full_path(link.full_path)
img = Image.open(file_full_path)
if img.format != 'GIF':
img.thumbnail((1024, 1024))
img.thumbnail((512, 512), Image.ANTIALIAS)
img.save(file_full_path)
DBSession.add(entity)
DBSession.add(link)
return HTTPOk()
示例7: create_image_format
# 需要导入模块: from stalker.db import DBSession [as 别名]
# 或者: from stalker.db.DBSession import add [as 别名]
def create_image_format(request):
"""creates an image format
"""
logged_in_user = get_logged_in_user(request)
name = request.params.get('name')
width = int(request.params.get('width', -1))
height = int(request.params.get('height', -1))
pixel_aspect = float(request.params.get('pixel_aspect', -1))
if name and width and height and pixel_aspect:
# create a new ImageFormat and save it to the database
new_image_format = ImageFormat(
name=name,
width=width,
height=height,
pixel_aspect=pixel_aspect,
created_by=logged_in_user
)
DBSession.add(new_image_format)
logger.debug('created new image format')
logger.debug('new_image_format: %s' % new_image_format)
else:
logger.debug('some data is missing')
return HTTPServerError()
return HTTPOk()
示例8: test_depends_to_argument_is_skipped_raises_error_on_commit
# 需要导入模块: from stalker.db import DBSession [as 别名]
# 或者: from stalker.db.DBSession import add [as 别名]
def test_depends_to_argument_is_skipped_raises_error_on_commit(self):
"""testing if an Integrity error will be raised when the depends_to
argument is skipped and the session is committed
"""
self.kwargs.pop('depends_to')
new_dependency = TaskDependency(**self.kwargs)
DBSession.add(new_dependency)
self.assertRaises(IntegrityError, DBSession.commit)
示例9: update_department
# 需要导入模块: from stalker.db import DBSession [as 别名]
# 或者: from stalker.db.DBSession import add [as 别名]
def update_department(request):
"""updates an Department
"""
logger.debug('***update department method starts ***')
logged_in_user = get_logged_in_user(request)
# get params
came_from = request.params.get('came_from', '/')
department_id = request.matchdict.get('id', -1)
department = Department.query.filter_by(id=department_id).first()
name = request.params.get('name')
logger.debug('department : %s' % department)
logger.debug('department new name : %s' % name)
if department and name:
description = request.params.get('description')
lead_id = request.params.get('lead_id', -1)
lead = User.query.filter_by(id=lead_id).first()
# Tags
tags = get_tags(request)
logger.debug('department new description : %s' % description)
logger.debug('department new lead : %s' % lead)
logger.debug('department new tags : %s' % tags)
# update the department
department.name = name
department.description = description
department.lead = lead
department.tags = tags
department.updated_by = logged_in_user
department.date_updated = datetime.datetime.now()
DBSession.add(department)
logger.debug('department is updated successfully')
request.session.flash(
'success:Department <strong>%s</strong> is updated successfully' % name
)
logger.debug('***update department method ends ***')
else:
logger.debug('not all parameters are in request.params')
log_param(request, 'department_id')
log_param(request, 'name')
HTTPServerError()
return Response('Successfully updated department: %s' % department_id)
示例10: update_group
# 需要导入模块: from stalker.db import DBSession [as 别名]
# 或者: from stalker.db.DBSession import add [as 别名]
def update_group(request):
"""updates the group with data from request
"""
logger.debug('***update group method starts ***')
logged_in_user = get_logged_in_user(request)
# get parameters
post_multi_dict = request.POST
came_from = request.params.get('came_from', '/')
group_id = int(post_multi_dict['group_id'])
group = Group.query.filter_by(id=group_id).first()
name = post_multi_dict['name']
if group and name:
description = post_multi_dict['description']
# remove name and description to leave only permission in the dictionary
post_multi_dict.pop('name')
post_multi_dict.pop('description')
permissions = get_permissions_from_multi_dict(post_multi_dict)
# update the group
group.name = name
group.description = description
group.permissions = permissions
group.updated_by = logged_in_user
group.date_updated = datetime.datetime.now()
DBSession.add(group)
logger.debug('group is updated successfully')
request.session.flash(
'success:Group <strong>%s</strong> is updated successfully' % name
)
logger.debug('***update group method ends ***')
else:
logger.debug('not all parameters are in request.params')
log_param(request, 'group_id')
log_param(request, 'name')
response = Response(
'There are missing parameters: '
'group_id: %s, name: %s' % (group_id, name), 500
)
transaction.abort()
return response
response = Response('successfully updated %s group!' % name)
return response
示例11: assign_reference
# 需要导入模块: from stalker.db import DBSession [as 别名]
# 或者: from stalker.db.DBSession import add [as 别名]
def assign_reference(request):
"""assigns the link to the given entity as a new reference
"""
link_ids = get_multi_integer(request, 'link_ids[]')
removed_link_ids = get_multi_integer(request, 'removed_link_ids[]')
entity_id = request.params.get('entity_id', -1)
entity = Entity.query.filter_by(id=entity_id).first()
links = Link.query.filter(Link.id.in_(link_ids)).all()
removed_links = Link.query.filter(Link.id.in_(removed_link_ids)).all()
# Tags
tags = get_tags(request)
logged_in_user = get_logged_in_user(request)
logger.debug('link_ids : %s' % link_ids)
logger.debug('links : %s' % links)
logger.debug('entity_id : %s' % entity_id)
logger.debug('entity : %s' % entity)
logger.debug('tags : %s' % tags)
logger.debug('removed_links : %s' % removed_links)
# remove all the removed links
for removed_link in removed_links:
# no need to search for any linked tasks here
DBSession.delete(removed_link)
if entity and links:
entity.references.extend(links)
# assign all the tags to the links
for link in links:
link.tags.extend(tags)
# generate thumbnail
thumbnail = generate_thumbnail(link)
link.thumbnail = thumbnail
thumbnail.created_by = logged_in_user
DBSession.add(thumbnail)
DBSession.add(entity)
DBSession.add_all(links)
# return new links as json data
# in response text
return [
{
'id': link.id,
'full_path': link.full_path,
'original_filename': link.original_filename,
'thumbnail': link.thumbnail.full_path
if link.thumbnail else link.full_path,
'tags': [tag.name for tag in link.tags]
} for link in links
]
示例12: test_tasks_of_given_projects_are_correctly_scheduled
# 需要导入模块: from stalker.db import DBSession [as 别名]
# 或者: from stalker.db.DBSession import add [as 别名]
def test_tasks_of_given_projects_are_correctly_scheduled(self):
"""testing if the tasks of given projects are correctly scheduled
"""
# create a dummy project
# create a dummy Project to schedule
dummy_project = Project(name="Dummy Project", code="DP", repository=self.test_repo)
dt1 = Task(
name="Dummy Task 1",
project=dummy_project,
schedule_timing=4,
schedule_unit="h",
resources=[self.test_user1],
)
dt2 = Task(
name="Dummy Task 2",
project=dummy_project,
schedule_timing=4,
schedule_unit="h",
resources=[self.test_user2],
)
db.DBSession.add_all([dummy_project, dt1, dt2])
db.DBSession.commit()
tjp_sched = TaskJugglerScheduler(compute_resources=True, projects=[dummy_project])
test_studio = Studio(name="Test Studio", now=datetime.datetime(2013, 4, 16, 0, 0))
test_studio.start = datetime.datetime(2013, 4, 16, 0, 0)
test_studio.end = datetime.datetime(2013, 4, 30, 0, 0)
test_studio.daily_working_hours = 9
DBSession.add(test_studio)
db.DBSession.commit()
tjp_sched.studio = test_studio
tjp_sched.schedule()
db.DBSession.commit()
# check if the task and project timings are all adjusted
self.assertEqual(self.test_proj1.computed_start, None)
self.assertEqual(self.test_proj1.computed_end, None)
self.assertEqual(self.test_task1.computed_start, None)
self.assertEqual(self.test_task1.computed_end, None)
self.assertEqual(self.test_task1.computed_resources, [self.test_user1, self.test_user2])
self.assertEqual(self.test_task2.computed_start, None)
self.assertEqual(self.test_task2.computed_end, None)
self.assertEqual(self.test_task2.computed_resources, [self.test_user1, self.test_user2])
self.assertEqual(dt1.computed_start, datetime.datetime(2013, 4, 16, 9, 0))
self.assertEqual(dt1.computed_end, datetime.datetime(2013, 4, 16, 13, 0))
self.assertEqual(dt2.computed_start, datetime.datetime(2013, 4, 16, 9, 0))
self.assertEqual(dt2.computed_end, datetime.datetime(2013, 4, 16, 13, 0))
示例13: update_project
# 需要导入模块: from stalker.db import DBSession [as 别名]
# 或者: from stalker.db.DBSession import add [as 别名]
def update_project(request):
"""called when updating a Project
"""
logged_in_user = get_logged_in_user(request)
# parameters
project_id = request.params.get('project_id', -1)
project = Project.query.filter_by(id=project_id).first()
name = request.params.get('name')
fps = int(request.params.get('fps'))
imf_id = request.params.get('image_format', -1)
imf = ImageFormat.query.filter_by(id=imf_id).first()
repo_id = request.params.get('repository_id', -1)
repo = Repository.query.filter_by(id=repo_id).first()
structure_id = request.params.get('structure_id', -1)
structure = Structure.query.filter_by(id=structure_id).first()
lead_id = request.params.get('lead_id', -1)
lead = User.query.filter_by(id=lead_id).first()
status_id = request.params.get('status_id', -1)
status = Status.query.filter_by(id=status_id).first()
# get the dates
start = get_date(request, 'start')
end = get_date(request, 'end')
if project and name and imf and repo and structure and lead and \
status:
project.name = name
project.image_format = imf
project.repository = repo
project.updated_by = logged_in_user
project.date_updated = datetime.datetime.now()
project.fps = fps
project.structure = structure
project.lead = lead
project.status = status
project.start = start
project.end = end
DBSession.add(project)
else:
logger.debug('there are missing parameters')
HTTPServerError()
return HTTPOk()
示例14: test_delete_will_delete_the_session_cache
# 需要导入模块: from stalker.db import DBSession [as 别名]
# 或者: from stalker.db.DBSession import add [as 别名]
def test_delete_will_delete_the_session_cache(self):
"""testing if the LocalSession.delete() will delete the current cache
file
"""
# create a new user
new_user = User(
name='Test User',
login='test_user',
email='[email protected]',
password='secret'
)
# save it to the Database
DBSession.add(new_user)
DBSession.commit()
self.assertTrue(new_user.id is not None)
# save it to the local storage
local_session = LocalSession()
local_session.store_user(new_user)
# save the session
local_session.save()
# check if the file is created
# check if a file is created in the users local storage
self.assertTrue(
os.path.exists(
os.path.join(
defaults.local_storage_path,
defaults.local_session_data_file_name
)
)
)
# now delete the session by calling delete()
local_session.delete()
# check if the file is gone
# check if a file is created in the users local storage
self.assertFalse(
os.path.exists(
os.path.join(
defaults.local_storage_path,
defaults.local_session_data_file_name
)
)
)
# delete a second time
# this should not raise an OSError
local_session.delete()
示例15: test_creating_a_time_log_for_a_task_whose_dependending_tasks_already_has_time_logs
# 需要导入模块: from stalker.db import DBSession [as 别名]
# 或者: from stalker.db.DBSession import add [as 别名]
def test_creating_a_time_log_for_a_task_whose_dependending_tasks_already_has_time_logs(self):
"""testing if a HTTPServer error will be raised when a time log tried
to be for a task whose depending tasks already has time logs created
(This test should be in Stalker)
"""
# create a new task
task2 = Task(
name='Test Task 2',
project=self.proj1,
depends=[self.task1],
resources=[self.user1],
schedule_timing=4,
schedule_unit= 'd',
schedule_model='effort',
status_list=self.task_status_list
)
DBSession.add(task2)
DBSession.flush()
transaction.commit()
# set the status of task1 to complete
self.task1.status = self.status_cmpl
# artificially update task2 status to rts
task2.status = self.status_rts
DBSession.flush()
transaction.commit()
# and now create time logs for task2
request = testing.DummyRequest()
request.params['task_id'] = task2.id
request.params['resource_id'] = self.user1.id
request.params['start'] = "Fri, 01 Nov 2013 08:00:00 GMT"
request.params['end'] = "Fri, 01 Nov 2013 17:00:00 GMT"
response = time_log.create_time_log(request)
self.assertEqual(response.status_int, 200)
DBSession.add(task2)
DBSession.flush()
transaction.commit()
# now because task2 is depending on to the task1
# and task2 has now started, entering any new time logs to task1
# is forbidden
request = testing.DummyRequest()
request.params['task_id'] = self.task1.id
request.params['resource_id'] = self.user1.id
request.params['start'] = "Fri, 02 Nov 2013 08:00:00 GMT"
request.params['end'] = "Fri, 02 Nov 2013 17:00:00 GMT"
response = time_log.create_time_log(request)
self.assertEqual(
response.status_int, 500
)