• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python db.DBSession类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中stalker.db.DBSession的典型用法代码示例。如果您正苦于以下问题:Python DBSession类的具体用法?Python DBSession怎么用?Python DBSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了DBSession类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:Dr-Rakcha,项目名称:stalker-pyramid,代码行数:28,代码来源:department.py


示例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()
开发者ID:Dr-Rakcha,项目名称:stalker-pyramid,代码行数:27,代码来源:format.py


示例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
        )
开发者ID:Dr-Rakcha,项目名称:stalker-pyramid,代码行数:33,代码来源:test_time_log.py


示例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()
开发者ID:tonybarbieri,项目名称:stalker,代码行数:7,代码来源:test_taskJuggler_scheduler.py


示例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
        )
开发者ID:Industriromantik,项目名称:stalker,代码行数:30,代码来源:test_config.py


示例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),
        )
开发者ID:jonntd,项目名称:stalker,代码行数:32,代码来源:test_taskJuggler_scheduler.py


示例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()
开发者ID:Dr-Rakcha,项目名称:stalker-pyramid,代码行数:30,代码来源:link.py


示例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()
开发者ID:Dr-Rakcha,项目名称:stalker-pyramid,代码行数:27,代码来源:structure.py


示例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)
开发者ID:Dr-Rakcha,项目名称:stalker-pyramid,代码行数:27,代码来源:auth.py


示例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()
开发者ID:Dr-Rakcha,项目名称:stalker-pyramid,代码行数:35,代码来源:sequence.py


示例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]
        }
开发者ID:Dr-Rakcha,项目名称:stalker-pyramid,代码行数:26,代码来源:link.py


示例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)
开发者ID:Dr-Rakcha,项目名称:stalker-pyramid,代码行数:25,代码来源:group.py


示例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)
开发者ID:mybikeislost,项目名称:stalker,代码行数:8,代码来源:test_task_dependency.py


示例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()
开发者ID:Industriromantik,项目名称:stalker,代码行数:8,代码来源:test_taskJuggler_scheduler.py


示例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)
开发者ID:Dr-Rakcha,项目名称:stalker-pyramid,代码行数:58,代码来源:department.py


示例16: tearDown

    def tearDown(self):
        """clean up the test
        """
        from stalker.db import DBSession
        DBSession.remove()

        # and remove the temp directory
        shutil.rmtree(self.temp_config_folder)
        # restore defaults.timing_resolution
        stalker.defaults.timing_resolution = datetime.timedelta(hours=1)
开发者ID:Industriromantik,项目名称:stalker,代码行数:10,代码来源:test_config.py


示例17: update_group

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
开发者ID:Dr-Rakcha,项目名称:stalker-pyramid,代码行数:55,代码来源:group.py


示例18: test_tasks_of_given_projects_are_correctly_scheduled

    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))
开发者ID:jonntd,项目名称:stalker,代码行数:54,代码来源:test_taskJuggler_scheduler.py


示例19: update_project

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()
开发者ID:Dr-Rakcha,项目名称:stalker-pyramid,代码行数:54,代码来源:project.py


示例20: 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())
     from sqlalchemy.exc import ProgrammingError
     try:
         DBSession.commit()
     except ProgrammingError:
         DBSession.rollback()
开发者ID:Industriromantik,项目名称:stalker,代码行数:11,代码来源:test_taskJuggler_scheduler.py



注:本文中的stalker.db.DBSession类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python session.DBSession类代码示例发布时间:2022-05-27
下一篇:
Python db.setup函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap