zoukankan      html  css  js  c++  java
  • webhelpers 1.0 paginate bugs

    Bug 1:
    在使用webhelpers 1.0 的paginate时碰到了
    TypeError("Sorry, your collection type is not supported by the paginate module. "
                "You can either provide a list, a tuple, an SQLAlchemy 0.4 select object or an "
                "SQLAlchemy 0.4 ORM-query object.")
    通过跟踪代码,获知是paginate.py 中 get_wrapper函数所出的问题,导致每次都执行至

    View Code
    raise TypeError("Sorry, your collection type is not supported by the "
    "paginate module. You can provide a list, a tuple, a SQLAlchemy "
    "select object or a SQLAlchemy ORM-query object.")
    将get_wrapper函数修改成如下即可
    View Code
    def get_wrapper(obj, sqlalchemy_session=None):
    """
    Auto-detect the kind of object and return a list/tuple
    to access items from the collection.
    """
    # If the collection is a sequence we can use it directly
    if isinstance(obj, (list, tuple)):
    return obj

    # If object is iterable we can use it directly
    if hasattr(obj, "__iter__") and hasattr(obj, "__len__"):
    return obj

    # Is SQLAlchemy 0.4 or better available? (0.3 is not supported - sorry)
    if sqlalchemy_available[:3] != '0.3':
    # Is the collection a query?
    if isinstance(obj, sqlalchemy.orm.query.Query):
    return _SQLAlchemyQuery(obj)
    # Is the collection an SQLAlchemy select object?
    if isinstance(obj, sqlalchemy.sql.expression.CompoundSelect) \
    or isinstance(obj, sqlalchemy.sql.expression.Select):
    return _SQLAlchemySelect(obj, sqlalchemy_session)

    raise TypeError("Sorry, your collection type is not supported by the "
    "paginate module. You can provide a list, a tuple, a SQLAlchemy "
    "select object or a SQLAlchemy ORM-query object.")

    Bug 2:
    "__getitem__ without slicing not supported"异常究其原因是__init__函数中的
    self.items = list(self.collection)[self.first_item-1:self.last_item]
    所导致,当调用list(self.collection)时,会循环调用self.collection的__getitem__方法,其实也就是
    _SQLAlchemyQuery类的__getitem__方法,此时__getitem__的输入参数类型为int,肯定不会是slice,按照设
    计就导致raise Exception, "__getitem__ without slicing not supported",为解决这一问题,可以修改上述调用更改为:
    View Code
    #self.items = list(self.collection)[self.first_item-1:self.last_item]
    self.items = list(self.collection[self.first_item-1:self.last_item])
  • 相关阅读:
    c#中的对象生命周期
    数据抓取的艺术(三):抓取Google数据之心得
    redmine3.3.0安装问题
    wget 无法建立ssl连接 [ERROR: certificate common name ?..ssl.fastly.net?.doesn?. match requested host name ?.ache.ruby-lang.org?. To connect to cache.ruby-lang.org insecurely, use ?.-no-check-certificate?]
    Centos安装ruby
    Redmine插件的安装与卸载,知识库插件安装。
    Nexus网页直接上传jar包
    mvn deploy命令上传包
    一辈子只有1次成为BAT的机会,你如何把握?
    redmine创建新闻,自动发邮件给项目组所有成员
  • 原文地址:https://www.cnblogs.com/Jerryshome/p/2018775.html
Copyright © 2011-2022 走看看