本文整理汇总了Python中stalker.db.DBSession类的典型用法代码示例。如果您正苦于以下问题:Python DBSession类的具体用法?Python DBSession怎么用?Python DBSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DBSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete_department
def delete_department(request):
"""deletes the department with the given id
"""
department_id = request.matchdict.get('id')
department = Department.query.get(department_id)
name = department.name
if not department:
transaction.abort()
return Response(
'Can not find a Department with id: %s' % department_id, 500
)
try:
DBSession.delete(department)
transaction.commit()
except Exception as e:
transaction.abort()
c = StdErrToHTMLConverter(e)
transaction.abort()
return Response(c.html(), 500)
request.session.flash(
'success: <strong>%s Department</strong> is deleted '
'successfully' % name
)
return Response('Successfully deleted department: %s' % department_id)
示例2: create_image_format
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()
示例3: test_creating_a_time_log_for_a_task_whose_dependent_tasks_has_not_finished_yet
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
)
示例4: tearDown
def tearDown(self):
"""clean up the test
"""
# clean up test database
from stalker.db.declarative import Base
Base.metadata.drop_all(db.DBSession.connection())
DBSession.commit()
示例5: test_update_with_studio_is_working_properly
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
)
示例6: test_tasks_are_correctly_scheduled_when_compute_resources_is_True
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),
)
示例7: assign_thumbnail
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()
示例8: update_structure
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()
示例9: delete_user
def delete_user(request):
"""deletes the user with the given id
"""
user_id = request.matchdict.get('id')
user = User.query.get(user_id)
if not user:
transaction.abort()
return Response('Can not find a User with id: %s' % user_id, 500)
try:
DBSession.delete(user)
transaction.commit()
request.session.flash(
'success: %s is deleted' % user.name
)
except Exception as e:
transaction.abort()
c = StdErrToHTMLConverter(e)
transaction.abort()
request.session.flash(
c.html()
)
return Response(c.html(), 500)
return Response('Successfully deleted user: %s' % user_id)
示例10: update_sequence
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()
示例11: upload_files
def upload_files(request):
"""uploads a list of files to the server, creates Link instances in server
and returns the created link ids with a response to let the front end
request a linkage between the entity and the uploaded files
"""
# decide if it is single or multiple files
file_params = request.POST.getall('file')
logger.debug('file_params: %s ' % file_params)
try:
new_links = upload_files_to_server(request, file_params)
except IOError as e:
c = StdErrToHTMLConverter(e)
response = Response(c.html())
response.status_int = 500
transaction.abort()
return response
else:
# store the link object
DBSession.add_all(new_links)
logger.debug('created links for uploaded files: %s' % new_links)
return {
'link_ids': [link.id for link in new_links]
}
示例12: delete_group
def delete_group(request):
"""deletes the group with the given id
"""
group_id = request.matchdict.get('id')
group = Group.query.get(group_id)
name = group.name
if not group:
transaction.abort()
return Response('Can not find a Group with id: %s' % group_id, 500)
try:
DBSession.delete(group)
transaction.commit()
except Exception as e:
transaction.abort()
c = StdErrToHTMLConverter(e)
transaction.abort()
return Response(c.html(), 500)
request.session.flash(
'success:<strong>%s Group</strong> is deleted successfully' % name
)
return Response('Successfully deleted group: %s' % group_id)
示例13: test_depends_to_argument_is_skipped_raises_error_on_commit
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)
示例14: setUp
def setUp(self):
"""set up
"""
from stalker.db.declarative import Base
Base.metadata.drop_all(db.DBSession.connection())
DBSession.commit()
super(TaskJugglerScheduler_PostgreSQL_Tester, self).setUp()
示例15: update_department
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)