Skip to content

Commit fe2a33d

Browse files
committed
Add webui_link property to cbapi.response.Query objects (see carbonblack#76)
1 parent 74424a0 commit fe2a33d

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

src/cbapi/response/query.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ def sort(self, new_sort):
8787
nq._sort_by = new_sort
8888
return nq
8989

90+
@property
91+
def webui_link(self):
92+
return "{0:s}/#/search?{1}".format(self._cb.url, urllib.parse.urlencode(
93+
convert_query_params(self._get_query_parameters())))
94+
9095
def and_(self, new_query):
9196
"""Add a filter to this query. Equivalent to calling :py:meth:`where` on this object.
9297
@@ -134,17 +139,23 @@ def facets(self, *args):
134139
query_params = convert_query_params(qargs)
135140
return self._cb.get_object(self._doc_class.urlobject, query_parameters=query_params).get('facets', {})
136141

137-
def _count(self):
138-
if self._count_valid:
139-
return self._total_results
140-
142+
def _get_query_parameters(self):
141143
if self._raw_query:
142144
args = self._raw_query.copy()
143145
else:
144146
args = self._default_args.copy()
145147
if self._query:
146148
args['q'] = self._query
149+
else:
150+
args['q'] = ''
151+
152+
return args
153+
154+
def _count(self):
155+
if self._count_valid:
156+
return self._total_results
147157

158+
args = self._get_query_parameters()
148159
args['start'] = 0
149160
args['rows'] = 0
150161

@@ -158,19 +169,12 @@ def _count(self):
158169
def _search(self, start=0, rows=0):
159170
# iterate over total result set, 100 at a time
160171

161-
if self._raw_query:
162-
args = self._raw_query.copy()
163-
else:
164-
args = self._default_args.copy()
165-
args['start'] = start
166-
167-
if self._query:
168-
args['q'] = self._query
169-
else:
170-
args['q'] = ''
172+
args = self._get_query_parameters()
173+
args['start'] = start
171174

172175
if self._sort_by:
173176
args['sort'] = self._sort_by
177+
174178
if rows:
175179
args['rows'] = min(rows, self._batch_size)
176180
else:

0 commit comments

Comments
 (0)