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


Python Response.headers[str('Content-Range')]方法代码示例

本文整理汇总了Python中pyramid.response.Response.headers[str('Content-Range')]方法的典型用法代码示例。如果您正苦于以下问题:Python Response.headers[str('Content-Range')]方法的具体用法?Python Response.headers[str('Content-Range')]怎么用?Python Response.headers[str('Content-Range')]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyramid.response.Response的用法示例。


在下文中一共展示了Response.headers[str('Content-Range')]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _get_items

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import headers[str('Content-Range')] [as 别名]
    def _get_items(self, reference_book_type, dgrid_viewmodel):
        session = DBSession()

        items_query = session.query(reference_book_type)

        rel_attrs = filter(lambda c: 'relation' in c, dgrid_viewmodel)
        for rel_attr in rel_attrs:
            relation_field = rel_attr['relation']['relation-field']
            items_query = items_query\
                .outerjoin(relation_field)\
                .options(joinedload(relation_field))

        complex_attrs = filter(lambda c: 'complex' in c, dgrid_viewmodel)
        for complex_attr in complex_attrs:
            for field in complex_attr['fields']:
                if 'relation' in field:
                    relation_field = field['relation-field']
                    items_query = items_query\
                        .outerjoin(relation_field)\
                        .options(joinedload(relation_field))

        sort_keys = filter(lambda k: 'sort(' in k, self.request.GET.keys())
        if sort_keys:
            dojo_order, grid_field_name = re.findall('.+([+,-])(\w+)', self.request.query_string)[0]
            item_config = filter(lambda x: x['grid-property'] == grid_field_name, dgrid_viewmodel)[0]
            if 'relation' in item_config:
                sorting_field = item_config['relation']['sort-field']
            elif 'complex' in item_config:
                sorting_field = item_config['sort-field']
            else:
                field_name = item_config['data-property']
                sorting_field = reference_book_type.__table__.c[field_name]

            if dojo_order == '+':
                items_query = items_query.order_by(sorting_field.asc())
            elif dojo_order == '-':
                items_query = items_query.order_by(sorting_field.desc())

        grid_range = None
        if 'Range' in self.request.headers:
            grid_range = self.request.headers['Range']
            start, stop = re.findall('items=(\d+)-(\d+)', grid_range)[0]
            items_query = items_query.slice(int(start), int(stop) + 1)

        result = []
        for item_db in items_query:
            result_item = self._build_item_for_response(dgrid_viewmodel, item_db)
            result.append(result_item)

        response = Response(json.dumps(result, cls=DateTimeJSONEncoder), content_type=b'application/json')

        id_config_item = filter(lambda c: 'id' in c and c['id'] == True, dgrid_viewmodel)[0]
        if grid_range:
            count_all_rows = session\
                .query(func.count(reference_book_type
                                  .__getattribute__(reference_book_type, id_config_item['data-property'])))\
                .scalar()
            response.headers[str('Content-Range')] = str(grid_range + '/' + str(count_all_rows))

        return response
开发者ID:nextgis,项目名称:nextgisweb_compulink,代码行数:62,代码来源:ReferenceBookViewBase.py


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