Use new StreamToken in pagination config
parent
7bec359408
commit
81a95937de
|
@ -14,6 +14,7 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
from synapse.api.errors import SynapseError
|
from synapse.api.errors import SynapseError
|
||||||
|
from synapse.types import StreamToken
|
||||||
|
|
||||||
|
|
||||||
class PaginationConfig(object):
|
class PaginationConfig(object):
|
||||||
|
@ -21,10 +22,10 @@ class PaginationConfig(object):
|
||||||
"""A configuration object which stores pagination parameters."""
|
"""A configuration object which stores pagination parameters."""
|
||||||
|
|
||||||
def __init__(self, from_tok=None, to_tok=None, direction='f', limit=0):
|
def __init__(self, from_tok=None, to_tok=None, direction='f', limit=0):
|
||||||
self.from_tok = from_tok
|
self.from_tok = StreamToken(from_tok) if from_tok else None
|
||||||
self.to_tok = to_tok
|
self.to_tok = StreamToken(to_tok) if to_tok else None
|
||||||
self.direction = direction
|
self.direction = 'f' if direction == 'f' else 'b'
|
||||||
self.limit = limit
|
self.limit = int(limit)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_request(cls, request, raise_invalid_params=True):
|
def from_request(cls, request, raise_invalid_params=True):
|
||||||
|
@ -47,7 +48,10 @@ class PaginationConfig(object):
|
||||||
elif raise_invalid_params:
|
elif raise_invalid_params:
|
||||||
raise SynapseError(400, "%s parameter is invalid." % qp)
|
raise SynapseError(400, "%s parameter is invalid." % qp)
|
||||||
|
|
||||||
|
try:
|
||||||
return PaginationConfig(**params)
|
return PaginationConfig(**params)
|
||||||
|
except:
|
||||||
|
raise SynapseError(400, "Invalid request.")
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return (
|
return (
|
||||||
|
|
Loading…
Reference in New Issue