Skip to content

Commit e7f8d42

Browse files
Merge pull request #68 from GeoNodeUserGroup-DE/issue_#66_Bug_not_for_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
2 parents 11c7e59 + 8c5c71d commit e7f8d42

File tree

7 files changed

+55
-15
lines changed

7 files changed

+55
-15
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ show all datasets:
104104

105105
patch dataset:
106106
```
107-
geonodectl ds patch 36 --set 'category={"identifier": "farming"}'
107+
geonodectl ds patch 36 --set '{"category":{"identifier":"biota"}}'
108108
...
109109
```
110110

geonodectl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ To use this tool you have to set the following environment variables before star
190190
datasets_list = datasets_subparsers.add_parser("list", help="list datasets")
191191
datasets_list.add_argument(
192192
"--filter",
193+
nargs="*",
193194
action=kwargs_append_action,
194195
dest="filter",
195196
type=str,
@@ -284,6 +285,7 @@ To use this tool you have to set the following environment variables before star
284285
documents_list = documents_subparsers.add_parser("list", help="list documents")
285286
documents_list.add_argument(
286287
"--filter",
288+
nargs="*",
287289
action=kwargs_append_action,
288290
dest="filter",
289291
type=str,
@@ -358,6 +360,7 @@ To use this tool you have to set the following environment variables before star
358360
maps_list = maps_subparsers.add_parser("list", help="list documents")
359361
maps_list.add_argument(
360362
"--filter",
363+
nargs="*",
361364
action=kwargs_append_action,
362365
dest="filter",
363366
type=str,
@@ -435,6 +438,7 @@ To use this tool you have to set the following environment variables before star
435438
geoapps_list = geoapps_subparsers.add_parser("list", help="list geoapps")
436439
geoapps_list.add_argument(
437440
"--filter",
441+
nargs="*",
438442
action=kwargs_append_action,
439443
dest="filter",
440444
type=str,
@@ -531,6 +535,7 @@ To use this tool you have to set the following environment variables before star
531535
users_list = users_subparsers.add_parser("list", help="list documents")
532536
users_list.add_argument(
533537
"--filter",
538+
nargs="*",
534539
action=kwargs_append_action,
535540
dest="filter",
536541
type=str,
@@ -618,6 +623,7 @@ To use this tool you have to set the following environment variables before star
618623
uploads_list = uploads_subparsers.add_parser("list", help="list uploads")
619624
uploads_list.add_argument(
620625
"--filter",
626+
nargs="*",
621627
action=kwargs_append_action,
622628
dest="filter",
623629
type=str,
@@ -640,6 +646,7 @@ To use this tool you have to set the following environment variables before star
640646
)
641647
executionrequest_list.add_argument(
642648
"--filter",
649+
nargs="*",
643650
action=kwargs_append_action,
644651
dest="filter",
645652
type=str,

geonoderest/executionrequest.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from typing import Dict, List
22

33
from geonoderest.geonodetypes import GeonodeCmdOutListKey, GeonodeCmdOutObjectKey
4+
from geonoderest.geonodeobject import GeonodeObjectHandler as GOH
45
from geonoderest.rest import GeonodeRest
6+
57
from geonoderest.cmdprint import print_list_on_cmd, print_json
68

79

@@ -36,3 +38,23 @@ def get(self, exec_id: str, **kwargs) -> Dict:
3638
"""
3739
r = self.http_get(endpoint=f"{self.ENDPOINT_NAME}/{exec_id}")
3840
return r[self.SINGULAR_RESOURCE_NAME]
41+
42+
def cmd_list(self, **kwargs):
43+
"""show list of geonode obj on the cmdline"""
44+
obj = self.list(**kwargs)
45+
if kwargs["json"]:
46+
print_json(obj)
47+
else:
48+
print_list_on_cmd(obj, self.LIST_CMDOUT_HEADER)
49+
50+
def list(self, **kwargs) -> Dict:
51+
"""returns dict of execution requests from geonode
52+
53+
Returns:
54+
Dict: request response
55+
"""
56+
endpoint = f"{self.ENDPOINT_NAME}/"
57+
58+
params = self.__handle_http_params__({}, kwargs)
59+
r = self.http_get(endpoint=endpoint, params=params)
60+
return r[self.JSON_OBJECT_NAME]

geonoderest/geonodeobject.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,6 @@ class GeonodeObjectHandler(GeonodeRest):
2222
ENDPOINT_NAME: str = ""
2323
SINGULAR_RESOURCE_NAME: str = ""
2424

25-
def __handle_http_params__(self, params: Dict, kwargs: Dict) -> Dict:
26-
if "page_size" in kwargs:
27-
params["page_size"] = kwargs["page_size"]
28-
if "page" in kwargs:
29-
params["page"] = kwargs["page"]
30-
31-
if "filter" in kwargs and kwargs["filter"] is not None:
32-
for field, value in kwargs["filter"].items():
33-
field = "filter{" + field + "}"
34-
params[field] = value
35-
36-
return params
37-
3825
def cmd_list(self, **kwargs):
3926
"""show list of geonode obj on the cmdline"""
4027
obj = self.list(**kwargs)
@@ -52,7 +39,6 @@ def list(self, **kwargs) -> Dict:
5239
endpoint = f"{self.ENDPOINT_NAME}/"
5340

5441
params = self.__handle_http_params__({}, kwargs)
55-
5642
r = self.http_get(endpoint=endpoint, params=params)
5743
return r[self.JSON_OBJECT_NAME]
5844

geonoderest/rest.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@ class GeonodeRest(object):
2222
def __init__(self, env: GeonodeApiConf):
2323
self.gn_credentials = env
2424

25+
def __handle_http_params__(self, params: Dict, kwargs: Dict) -> Dict:
26+
if "page_size" in kwargs:
27+
params["page_size"] = kwargs["page_size"]
28+
if "page" in kwargs:
29+
params["page"] = kwargs["page"]
30+
31+
if "filter" in kwargs and kwargs["filter"] is not None:
32+
for field, value in kwargs["filter"].items():
33+
field = "filter{" + field + "}"
34+
params[field] = value
35+
36+
return params
37+
2538
@staticmethod
2639
def network_exception_handling(func: NetworkExceptionHandlingTypes):
2740
def inner(*args, **kwargs):

json-examples/keywords.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"keywords": [
3+
{
4+
"name": "test"
5+
}
6+
]
7+
}

json-examples/license.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"license": {
3+
"identifier": "CC-0"
4+
}
5+
}

0 commit comments

Comments
 (0)