mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-07-13 01:32:24 +03:00
Improve code style
This commit is contained in:
parent
5ec2bcced4
commit
49eaf00e46
|
@ -158,34 +158,27 @@ class DjangoConnectionField(ConnectionField):
|
||||||
):
|
):
|
||||||
first = kwargs.get("first")
|
first = kwargs.get("first")
|
||||||
last = kwargs.get("last")
|
last = kwargs.get("last")
|
||||||
|
if first is not None and first <= 0:
|
||||||
if not (first is None or first > 0):
|
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"`first` argument must be positive, got `{first}`".format(**locals()))
|
"`first` argument must be positive, got `{first}`".format(first=first))
|
||||||
if not (last is None or last > 0):
|
if last is not None and last <= 0:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"`last` argument must be positive, got `{last}`".format(**locals()))
|
"`last` argument must be positive, got `{last}`".format(last=last))
|
||||||
|
|
||||||
if enforce_first_or_last and not (first or last):
|
if enforce_first_or_last and not (first or last):
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"You must provide a `first` or `last` value "
|
"You must provide a `first` or `last` value "
|
||||||
"to properly paginate the `{info.field_name}` connection.".format(**locals()))
|
"to properly paginate the `{info.field_name}` connection.".format(info=info))
|
||||||
|
|
||||||
if max_limit:
|
if max_limit:
|
||||||
if first:
|
|
||||||
assert first <= max_limit, (
|
|
||||||
"Requesting {} records on the `{}` connection exceeds the `first` limit of {} records."
|
|
||||||
).format(first, info.field_name, max_limit)
|
|
||||||
kwargs["first"] = min(first, max_limit)
|
|
||||||
|
|
||||||
if last:
|
|
||||||
assert last <= max_limit, (
|
|
||||||
"Requesting {} records on the `{}` connection exceeds the `last` limit of {} records."
|
|
||||||
).format(last, info.field_name, max_limit)
|
|
||||||
kwargs["last"] = min(last, max_limit)
|
|
||||||
|
|
||||||
if first is None and last is None:
|
if first is None and last is None:
|
||||||
kwargs['first'] = max_limit
|
kwargs['first'] = max_limit
|
||||||
|
else:
|
||||||
|
count = min(i for i in (first, last) if i)
|
||||||
|
if count > max_limit:
|
||||||
|
raise ValueError(("Requesting {count} records "
|
||||||
|
"on the `{info.field_name}` connection "
|
||||||
|
"exceeds the limit of {max_limit} records.").format(
|
||||||
|
count=count, info=info, max_limit=max_limit))
|
||||||
|
|
||||||
iterable = resolver(root, info, **kwargs)
|
iterable = resolver(root, info, **kwargs)
|
||||||
queryset = cls.resolve_queryset(connection, default_manager, info, kwargs)
|
queryset = cls.resolve_queryset(connection, default_manager, info, kwargs)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user