Skip to content

Commit

Permalink
Author name in project csv export
Browse files Browse the repository at this point in the history
  • Loading branch information
prabinoid committed Dec 19, 2024
1 parent cc16b0a commit 7a7871b
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion backend/services/project_search_service.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pandas as pd
from backend.models.postgis.user import User
from flask import current_app
import math
import geojson
Expand Down Expand Up @@ -92,14 +93,23 @@ 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)
).label("total_area"),
)
.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 = (
Expand Down Expand Up @@ -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 = (
Expand All @@ -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 = {
Expand Down

0 comments on commit 7a7871b

Please sign in to comment.