Skip to content

Commit

Permalink
Merge pull request #222 from CityOfNewYork/hotfix/OP-1218
Browse files Browse the repository at this point in the history
Hotfix/OP-1218: CSV Generation Missing Requests
  • Loading branch information
zgary authored Sep 11, 2017
2 parents 2c8c4ea + 3a137b0 commit 5d996b0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
10 changes: 8 additions & 2 deletions app/search/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ def search_requests(query,
sort_title,
tz_name,
by_phrase=False,
highlight=False):
highlight=False,
for_csv=False):
"""
The arguments of this function match the request parameters
of the '/search/requests' endpoints.
Expand Down Expand Up @@ -260,6 +261,8 @@ def search_requests(query,
if True, will come at a slight performance cost (in order to
restrict highlights to public fields, iterating over elasticsearch
query results is required)
:param for_csv: search for a csv export
if True, will not check the maximum value of size against MAX_RESULT_SIZE
:return: elasticsearch json response with result information
"""
Expand Down Expand Up @@ -382,6 +385,9 @@ def datestr_local_to_utc(datestr):
}
)

# Calculate result set size
result_set_size = size if for_csv else min(size, MAX_RESULT_SIZE)

# search / run query
results = es.search(
index=current_app.config["ELASTICSEARCH_INDEX"],
Expand All @@ -404,7 +410,7 @@ def datestr_local_to_utc(datestr):
'title',
'agency_request_summary',
'description'],
size=min(size, MAX_RESULT_SIZE),
size=result_set_size,
from_=start,
sort=sort,
)
Expand Down
7 changes: 5 additions & 2 deletions app/search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ def requests_doc(doc_type):
request.args.get('sort_date_submitted'),
request.args.get('sort_date_due'),
request.args.get('sort_title'),
tz_name
tz_name,
for_csv=True
)
total = results["hits"]["total"]
if total != 0:
Expand All @@ -201,6 +202,8 @@ def requests_doc(doc_type):
mailing_address = (r.requester.mailing_address
if r.requester.mailing_address is not None
else {})
date_closed = result['_source'].get('date_closed', '')
date_closed = date_closed if str(date_closed) != str(list()) else ''
writer.writerow([
result["_id"],
result["_source"]["agency_name"],
Expand All @@ -211,7 +214,7 @@ def requests_doc(doc_type):
result["_source"]["date_created"],
result["_source"]["date_submitted"],
result["_source"]["date_due"],
result["_source"].get('date_closed', ''),
date_closed,
result["_source"]["requester_name"],
r.requester.email,
r.requester.title,
Expand Down

0 comments on commit 5d996b0

Please sign in to comment.