From 7a7871b3eb1d6819b755026d664de54b36247392 Mon Sep 17 00:00:00 2001 From: prabinoid <38830224+prabinoid@users.noreply.github.com> Date: Thu, 19 Dec 2024 12:40:40 +0545 Subject: [PATCH] Author name in project csv export --- backend/services/project_search_service.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/backend/services/project_search_service.py b/backend/services/project_search_service.py index bdddc463c9..bdb7633dbc 100644 --- a/backend/services/project_search_service.py +++ b/backend/services/project_search_service.py @@ -1,4 +1,5 @@ import pandas as pd +from backend.models.postgis.user import User from flask import current_app import math import geojson @@ -92,6 +93,8 @@ def create_search_query(user=None, as_csv: bool = False): Project.country, Organisation.name.label("organisation_name"), Organisation.logo.label("organisation_logo"), + User.name.label("author_name"), + User.username.label("author_username"), Project.created.label("creation_date"), func.coalesce( func.sum(func.ST_Area(Project.geometry, True) / 1000000) @@ -99,7 +102,14 @@ def create_search_query(user=None, as_csv: bool = False): ) .filter(Project.geometry is not None) .outerjoin(Organisation, Organisation.id == Project.organisation_id) - .group_by(Organisation.id, Project.id, ProjectInfo.name) + .outerjoin(User, User.id == Project.author_id) + .group_by( + Organisation.id, + Project.id, + ProjectInfo.name, + User.username, + User.name, + ) ) else: query = ( @@ -246,6 +256,7 @@ def search_projects_as_csv(search_dto: ProjectSearchDTO, user) -> str: row["total_contributors"] = Project.get_project_total_contributions( row["id"] ) + row["author"] = row["author_name"] or row["author_username"] if is_user_admin: partners_names = ( @@ -269,6 +280,8 @@ def search_projects_as_csv(search_dto: ProjectSearchDTO, user) -> str: "tasks_validated", "total_tasks", "centroid", + "author_name", + "author_username", ] colummns_to_rename = {