Skip to content

Commit

Permalink
Merge pull request #68 from GeoNodeUserGroup-DE/issue_#66_Bug_not_for…
Browse files Browse the repository at this point in the history
…_all_geonode_object_types_we_are_able_to_run_--filter

[Fixes #66] Bug: not for all geonode object types we are able to run --filter
  • Loading branch information
mwallschlaeger authored Jun 27, 2024
2 parents 11c7e59 + 8c5c71d commit e7f8d42
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ show all datasets:

patch dataset:
```
geonodectl ds patch 36 --set 'category={"identifier": "farming"}'
geonodectl ds patch 36 --set '{"category":{"identifier":"biota"}}'
...
```

Expand Down
7 changes: 7 additions & 0 deletions geonodectl
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ To use this tool you have to set the following environment variables before star
datasets_list = datasets_subparsers.add_parser("list", help="list datasets")
datasets_list.add_argument(
"--filter",
nargs="*",
action=kwargs_append_action,
dest="filter",
type=str,
Expand Down Expand Up @@ -284,6 +285,7 @@ To use this tool you have to set the following environment variables before star
documents_list = documents_subparsers.add_parser("list", help="list documents")
documents_list.add_argument(
"--filter",
nargs="*",
action=kwargs_append_action,
dest="filter",
type=str,
Expand Down Expand Up @@ -358,6 +360,7 @@ To use this tool you have to set the following environment variables before star
maps_list = maps_subparsers.add_parser("list", help="list documents")
maps_list.add_argument(
"--filter",
nargs="*",
action=kwargs_append_action,
dest="filter",
type=str,
Expand Down Expand Up @@ -435,6 +438,7 @@ To use this tool you have to set the following environment variables before star
geoapps_list = geoapps_subparsers.add_parser("list", help="list geoapps")
geoapps_list.add_argument(
"--filter",
nargs="*",
action=kwargs_append_action,
dest="filter",
type=str,
Expand Down Expand Up @@ -531,6 +535,7 @@ To use this tool you have to set the following environment variables before star
users_list = users_subparsers.add_parser("list", help="list documents")
users_list.add_argument(
"--filter",
nargs="*",
action=kwargs_append_action,
dest="filter",
type=str,
Expand Down Expand Up @@ -618,6 +623,7 @@ To use this tool you have to set the following environment variables before star
uploads_list = uploads_subparsers.add_parser("list", help="list uploads")
uploads_list.add_argument(
"--filter",
nargs="*",
action=kwargs_append_action,
dest="filter",
type=str,
Expand All @@ -640,6 +646,7 @@ To use this tool you have to set the following environment variables before star
)
executionrequest_list.add_argument(
"--filter",
nargs="*",
action=kwargs_append_action,
dest="filter",
type=str,
Expand Down
22 changes: 22 additions & 0 deletions geonoderest/executionrequest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from typing import Dict, List

from geonoderest.geonodetypes import GeonodeCmdOutListKey, GeonodeCmdOutObjectKey
from geonoderest.geonodeobject import GeonodeObjectHandler as GOH
from geonoderest.rest import GeonodeRest

from geonoderest.cmdprint import print_list_on_cmd, print_json


Expand Down Expand Up @@ -36,3 +38,23 @@ def get(self, exec_id: str, **kwargs) -> Dict:
"""
r = self.http_get(endpoint=f"{self.ENDPOINT_NAME}/{exec_id}")
return r[self.SINGULAR_RESOURCE_NAME]

def cmd_list(self, **kwargs):
"""show list of geonode obj on the cmdline"""
obj = self.list(**kwargs)
if kwargs["json"]:
print_json(obj)
else:
print_list_on_cmd(obj, self.LIST_CMDOUT_HEADER)

def list(self, **kwargs) -> Dict:
"""returns dict of execution requests from geonode
Returns:
Dict: request response
"""
endpoint = f"{self.ENDPOINT_NAME}/"

params = self.__handle_http_params__({}, kwargs)
r = self.http_get(endpoint=endpoint, params=params)
return r[self.JSON_OBJECT_NAME]
14 changes: 0 additions & 14 deletions geonoderest/geonodeobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,6 @@ class GeonodeObjectHandler(GeonodeRest):
ENDPOINT_NAME: str = ""
SINGULAR_RESOURCE_NAME: str = ""

def __handle_http_params__(self, params: Dict, kwargs: Dict) -> Dict:
if "page_size" in kwargs:
params["page_size"] = kwargs["page_size"]
if "page" in kwargs:
params["page"] = kwargs["page"]

if "filter" in kwargs and kwargs["filter"] is not None:
for field, value in kwargs["filter"].items():
field = "filter{" + field + "}"
params[field] = value

return params

def cmd_list(self, **kwargs):
"""show list of geonode obj on the cmdline"""
obj = self.list(**kwargs)
Expand All @@ -52,7 +39,6 @@ def list(self, **kwargs) -> Dict:
endpoint = f"{self.ENDPOINT_NAME}/"

params = self.__handle_http_params__({}, kwargs)

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

Expand Down
13 changes: 13 additions & 0 deletions geonoderest/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ class GeonodeRest(object):
def __init__(self, env: GeonodeApiConf):
self.gn_credentials = env

def __handle_http_params__(self, params: Dict, kwargs: Dict) -> Dict:
if "page_size" in kwargs:
params["page_size"] = kwargs["page_size"]
if "page" in kwargs:
params["page"] = kwargs["page"]

if "filter" in kwargs and kwargs["filter"] is not None:
for field, value in kwargs["filter"].items():
field = "filter{" + field + "}"
params[field] = value

return params

@staticmethod
def network_exception_handling(func: NetworkExceptionHandlingTypes):
def inner(*args, **kwargs):
Expand Down
7 changes: 7 additions & 0 deletions json-examples/keywords.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"keywords": [
{
"name": "test"
}
]
}
5 changes: 5 additions & 0 deletions json-examples/license.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"license": {
"identifier": "CC-0"
}
}

0 comments on commit e7f8d42

Please sign in to comment.