当前位置: 首页>>代码示例>>Python>>正文


Python DBSession.query方法代码示例

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


在下文中一共展示了DBSession.query方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: list_all

# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import query [as 别名]
    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,代码行数:31,代码来源:representation.py

示例2: get_filtered_entities

# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import query [as 别名]
    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,代码行数:32,代码来源:task_manager.py

示例3: project_changed

# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import query [as 别名]
    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,代码行数:48,代码来源:project_users_dialog.py

示例4: get_current_resource_id

# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import query [as 别名]
 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,代码行数:11,代码来源:time_log_dialog.py

示例5: user_names_lut

# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import query [as 别名]
 def user_names_lut(self):
     """fills the _user_names_lut
     """
     if not self._user_names_lut:
         from anima.utils import do_db_setup
         do_db_setup()
         from stalker import User
         from stalker.db.session import DBSession
         map(
             lambda x: self._user_names_lut.__setitem__(x[0], x[1]),
             DBSession.query(User.id, User.name).all()
         )
     return self._user_names_lut
开发者ID:eoyilmaz,项目名称:anima,代码行数:15,代码来源:config.py

示例6: fill

# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import query [as 别名]
    def fill(self):
        """fills the tree view with data
        """
        logger.debug('start filling tasks_treeView')
        logger.debug('creating a new model')
        if not self.project:
            from sqlalchemy import alias
            from stalker import Task, Project
            from stalker.db.session import DBSession
            # projects = Project.query.order_by(Project.name).all()
            inner_tasks = alias(Task.__table__)
            subquery = DBSession.query(inner_tasks.c.id).filter(
                inner_tasks.c.project_id == Project.id)
            query = DBSession\
                .query(
                    Project.id, Project.name, Project.entity_type,
                    Project.status_id,
                    subquery.exists().label('has_children')
                )
            if not self.show_completed_projects:
                from stalker import Status
                status_cmpl = \
                    Status.query.filter(Status.code == 'CMPL').first()
                query = query.filter(Project.status != status_cmpl)

            query = query.order_by(Project.name)
            projects = query.all()
        else:
            self.project.has_children = bool(self.project.tasks)
            projects = [self.project]

        logger.debug('projects: %s' % projects)

        # delete the old model if any
        if self.model() is not None:
            self.model().deleteLater()

        task_tree_model = TaskTreeModel()
        task_tree_model.populateTree(projects)
        self.setModel(task_tree_model)
        self.is_updating = False

        self.auto_fit_column()

        logger.debug('finished filling tasks_treeView')
开发者ID:eoyilmaz,项目名称:anima,代码行数:47,代码来源:task.py

示例7: hasChildren

# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import query [as 别名]
 def hasChildren(self, index):
     """returns True or False depending on to the index and the item on the
     index
     """
     logger.debug(
         'TaskTreeModel.hasChildren() is started for index: %s' % index
     )
     if not index.isValid():
         from stalker import Project
         from stalker.db.session import DBSession
         projects_count = DBSession.query(Project.id).count()
         return_value = projects_count > 0
     else:
         item = self.itemFromIndex(index)
         return_value = False
         if item:
             return_value = item.hasChildren()
     logger.debug(
         'TaskTreeModel.hasChildren() is finished for index: %s' % index
     )
     return return_value
开发者ID:eoyilmaz,项目名称:anima,代码行数:23,代码来源:task.py

示例8: fetchMore

# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import query [as 别名]
    def fetchMore(self):
        logger.debug(
            'TaskItem.fetchMore() is started for item: %s' % self.text()
        )

        if self.canFetchMore():
            from sqlalchemy import alias
            from sqlalchemy.dialects.postgresql import array_agg
            from stalker import Task, User
            from stalker.models.task import Task_Resources
            from stalker.db.session import DBSession

            inner_tasks = alias(Task.__table__)
            subquery = DBSession.query(Task.id)\
                .filter(Task.id == inner_tasks.c.parent_id)
            query = DBSession.query(
                Task.id,
                Task.name,
                Task.entity_type,
                Task.status_id,
                subquery.exists().label('has_children'),
                array_agg(User.name).label('resources')
            )\
                .outerjoin(Task_Resources, Task.id == Task_Resources.c.task_id)\
                .outerjoin(User, Task_Resources.c.resource_id == User.id) \
                .group_by(
                    Task.id,
                    Task.name,
                    Task.entity_type,
                    Task.status_id,
                    subquery.exists().label('has_children')
                )

            if self.task.entity_type != 'Project':
                # query child tasks
                query = query.filter(Task.parent_id == self.task.id)
            else:
                # query only root tasks
                query = query.filter(Task.project_id == self.task.id)\
                    .filter(Task.parent_id==None)

            tasks = query.order_by(Task.name).all()

            # # model = self.model() # This will cause a SEGFAULT
            # # TODO: update it later on

            # start = time.time()
            from anima import defaults
            task_items = []
            for task in tasks:
                task_item = TaskItem(0, 4, entity=task)
                task_item.parent = self

                # color with task status
                task_item.setData(
                    QtGui.QColor(
                        *defaults.status_colors_by_id[task.status_id]
                    ),
                    QtCore.Qt.BackgroundRole
                )

                # use black text
                task_item.setForeground(
                    QtGui.QBrush(QtGui.QColor(0, 0, 0))
                )

                task_items.append(task_item)

            if task_items:
                # self.appendRows(task_items)
                for task_item in task_items:
                    # TODO: Create a custom QStandardItem for each data type in different columns
                    entity_type_item = QtGui.QStandardItem()
                    entity_type_item.setData(task_item.task.entity_type, QtCore.Qt.DisplayRole)

                    resources_item = QtGui.QStandardItem()
                    if task_item.task.resources != [None]:
                        resources_item.setData(', '.join(map(str, task_item.task.resources)), QtCore.Qt.DisplayRole)

                    self.appendRow([task_item, entity_type_item, resources_item])

            self.fetched_all = True

        logger.debug(
            'TaskItem.fetchMore() is finished for item: %s' % self.text()
        )
开发者ID:eoyilmaz,项目名称:anima,代码行数:88,代码来源:task.py

示例9: _set_defaults

# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import query [as 别名]
    def _set_defaults(self):
        """setup the default values
        """
        # set size policies
        # self.name_lineEdit

        self.type_comboBox.setSizePolicy(
            QtWidgets.QSizePolicy.Expanding,
            QtWidgets.QSizePolicy.Fixed
        )

        self.status_comboBox.setSizePolicy(
            QtWidgets.QSizePolicy.Expanding,
            QtWidgets.QSizePolicy.Fixed
        )

        self.client_comboBox.setSizePolicy(
            QtWidgets.QSizePolicy.Expanding,
            QtWidgets.QSizePolicy.Fixed
        )

        self.agency_comboBox.setSizePolicy(
            QtWidgets.QSizePolicy.Expanding,
            QtWidgets.QSizePolicy.Fixed
        )

        self.production_company_comboBox.setSizePolicy(
            QtWidgets.QSizePolicy.Expanding,
            QtWidgets.QSizePolicy.Fixed
        )

        # invalidate the name and code fields by default
        self.name_lineEdit.set_invalid('Enter a name')
        self.code_lineEdit.set_invalid('Enter a code')

        # update type field
        from stalker import Type
        from stalker.db.session import DBSession
        project_types = \
            DBSession.query(Type.id, Type.name)\
                .filter(Type.target_entity_type == 'Project')\
                .order_by(Type.name)\
                .all()

        self.type_comboBox.clear()
        self.type_comboBox.addItem('', -1)
        for type_id, type_name in project_types:
            self.type_comboBox.addItem(type_name, type_id)

        self.image_format.fill_combo_box()
        self.fill_repository_combo_box()
        self.fill_structure_combo_box()

        # fill status field
        sql = """select
        "SimpleEntities".id,
        "SimpleEntities".name
    from "Statuses"
    join "SimpleEntities" on "Statuses".id = "SimpleEntities".id
    join "StatusList_Statuses" on "Statuses".id = "StatusList_Statuses".status_id
    join "StatusLists" on "StatusLists".id = "StatusList_Statuses".status_list_id
    where "StatusLists".target_entity_type = 'Project'"""

        all_project_statuses = \
            DBSession.connection().execute(sql).fetchall()

        for st_id, st_name in all_project_statuses:
            self.status_comboBox.addItem(st_name, st_id)
开发者ID:eoyilmaz,项目名称:anima,代码行数:70,代码来源:project_dialog.py


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