diff --git a/infogami/infobase/_dbstore/read.py b/infogami/infobase/_dbstore/read.py index e7dbe045..f4e2dce9 100644 --- a/infogami/infobase/_dbstore/read.py +++ b/infogami/infobase/_dbstore/read.py @@ -64,8 +64,7 @@ def recentchanges(self, limit=100, offset=0, **kwargs): # noqa: PLR0912 order = 't.created DESC' wheres = ["1 = 1"] - if offset < 0: - offset = 0 + offset = max(offset, 0) if (key := kwargs.pop('key', None)) is not None: thing_id = self.get_thing_id(key) diff --git a/infogami/infobase/readquery.py b/infogami/infobase/readquery.py index 55ef5f65..39ca91d9 100644 --- a/infogami/infobase/readquery.py +++ b/infogami/infobase/readquery.py @@ -138,8 +138,7 @@ def make_query(store, query, prefix=""): q.prefix = prefix q.offset = common.safeint(query.pop('offset', None), 0) q.limit = common.safeint(query.pop('limit', 20), 20) - if q.limit > 1000: - q.limit = 1000 + q.limit = min(q.limit, 1000) sort = query.pop('sort', None) nested = prefix != "" @@ -256,8 +255,7 @@ def make_versions_query(store, query): q.offset = common.safeint(query.pop('offset', None), 0) q.limit = common.safeint(query.pop('limit', 20), 20) - if q.limit > 1000: - q.limit = 1000 + q.limit = min(q.limit, 1000) q.sort = query.pop('sort', '-created') columns = [ diff --git a/infogami/utils/macro.py b/infogami/utils/macro.py index 91d951be..5bcbf625 100644 --- a/infogami/utils/macro.py +++ b/infogami/utils/macro.py @@ -10,7 +10,7 @@ import web -from infogami.utils import storage, template +from infogami.utils import features, storage, template from infogami.utils.markdown import markdown # macros loaded from disk @@ -104,8 +104,7 @@ def call_macro(name, args): macro_string = name + "(" + args + ")" result = macro_eval(macro, macro_string) except Exception as e: - i = web.input(_method="GET", debug="false") - if i.debug.lower() == "true": + if features.is_enabled("debug"): raise result = f"{name} failed with error:
{web.websafe(str(e))}
" import traceback diff --git a/infogami/utils/template.py b/infogami/utils/template.py index fdaf37e9..8c71684a 100644 --- a/infogami/utils/template.py +++ b/infogami/utils/template.py @@ -15,7 +15,7 @@ import web -from infogami.utils import storage +from infogami.utils import features, storage # There are some backward-incompatible changes in web.py 0.34 which makes Infogami fail. assert web.__version__ != "0.34", "Please pip install --upgrade web.py" @@ -163,8 +163,7 @@ def saferender(templates, *a, **kw): except Exception as e: # help to debug template errors. # when called with debug=true, the debug error is displayed. - i = web.input(_method='GET', debug="false") - if i.debug.lower() == "true": + if features.is_enabled("debug"): raise from . import delegate, view # avoids circular imports