Skip to content

Commit

Permalink
Merge pull request #40 from GeoNodeUserGroup-DE/issue_#32_make_page_s…
Browse files Browse the repository at this point in the history
…ize_a_default_value_inside_the_project

[Fixes #32] make page size a default value inside the project
  • Loading branch information
mwallschlaeger authored Apr 29, 2024
2 parents 6c3f037 + b488f45 commit 44997ee
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
18 changes: 13 additions & 5 deletions geonodectl
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ GEONODECTL_URL_ENV_VAR: str = "GEONODE_API_URL"
GEONODECTL_BASIC_ENV_VAR: str = "GEONODE_API_BASIC_AUTH"

DEFAULT_CHARSET: str = "UTF-8"

DEFAULT_LIST_PAGE_SIZE: int = 100

DEFAULT_CMD_PAGE_SIZE: int = 80
DEFAULT_CMD_PAGE: int = 1

class AliasedSubParsersAction(argparse._SubParsersAction):
class _AliasedPseudoAction(argparse.Action):
Expand Down Expand Up @@ -117,9 +116,18 @@ To use this tool you have to set the following environment variables before star
parser.add_argument(
"--page-size",
dest="page_size",
default=DEFAULT_LIST_PAGE_SIZE,
help="return output as raw response json as it comes from the rest API",
default=DEFAULT_CMD_PAGE_SIZE,
type=int,
help="Number of results to return per page",
)
parser.add_argument(
"--page",
dest="page",
default=DEFAULT_CMD_PAGE,
type=int,
help=" A page number within the paginated result set",
)

subparsers = parser.add_subparsers(
help="geonodectl commands", dest="command", required=True
)
Expand Down
7 changes: 4 additions & 3 deletions geonoderest/geonodeobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ def list(self, **kwargs) -> Dict:
Returns:
Dict: request response
"""
r = self.http_get(
endpoint=f"{self.ENDPOINT_NAME}/?page_size={kwargs['page_size']}"
)

endpoint = f"{self.ENDPOINT_NAME}/?page_size={kwargs['page_size']}&page={kwargs['page']}"

r = self.http_get(endpoint=endpoint)
return r[self.JSON_OBJECT_NAME]

def cmd_delete(self, pk: int, **kwargs):
Expand Down
5 changes: 4 additions & 1 deletion geonoderest/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@


class GeonodeRest(object):

DEFAULTS = {"page_size": 100, "page": 1}

def __init__(self, env: GeonodeApiConf):
self.gn_credentials = env

Expand Down Expand Up @@ -68,7 +71,7 @@ def http_post(
Args:
endpoint (str): api endpoint
files (Optional[List[GeonodeHTTPFile]], optional): files to post. Defaults to None.
params (Dict, optional): parameter to pust. Defaults to {}.
params (Dict, optional): parameter to post. Defaults to {}.
content_length (Optional[int], optional): optional content length
sometimes its useful to set by yourself. Defaults to None.
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ types-tabulate==0.9.0.20240106
types-urllib3==1.26.25.14
flake8==7.0.0
black==24.4.1
mypy==1.10.0
mypy==1.10.0

0 comments on commit 44997ee

Please sign in to comment.