Skip to content

Commit

Permalink
Fix: Cannot set omitMapResults when downloadAsCSV is true
Browse files Browse the repository at this point in the history
Use df.drop instead of del with the pandas dataframe
  • Loading branch information
bshankar committed Aug 19, 2024
1 parent 760c656 commit db96a47
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
5 changes: 5 additions & 0 deletions backend/api/projects/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,11 @@ def get(self):

search_dto = self.setup_search_dto()

if search_dto.omit_map_results and search_dto.download_as_csv:
return {
"Error": "omitMapResults and downloadAsCSV cannot be both set to true"
}, 400

if (
search_dto.partnership_from is not None
or search_dto.partnership_to is not None
Expand Down
16 changes: 11 additions & 5 deletions backend/services/project_search_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,17 @@ def search_projects_as_csv(search_dto: ProjectSearchDTO, user) -> str:
]

df = pd.json_normalize(results_as_dto)

del df["locale"]
del df["shortDescription"]
del df["organisationLogo"]
del df["campaigns"]
df.drop(
columns=[
"locale",
"shortDescription",
"organisationName",
"organisationLogo",
"campaigns",
],
inplace=True,
axis=1,
)

return df.to_csv(index=False)

Expand Down

0 comments on commit db96a47

Please sign in to comment.