Skip to content

Commit a522b76

Browse files
authored
Merge pull request #553 from uclouvain/qa
[PROD] INTERNSHIP-335 display multiple masters when available in xls
2 parents 3b0dfc7 + f61fb6d commit a522b76

File tree

4 files changed

+25
-13
lines changed

4 files changed

+25
-13
lines changed

business/assignment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def _prepare_subcohorts(self):
147147
if self.parent_cohort:
148148
for cohort in [cohort for cohort in self.parent_cohort.subcohorts.all() if cohort != self.cohort]:
149149
self.existing_affectations += list(
150-
InternshipStudentAffectationStat.objects.filter(internship__cohort=cohort)
150+
InternshipStudentAffectationStat.objects.filter(internship__cohort=cohort, organization__fake=False)
151151
)
152152

153153
# keep internship availability occurences in all cohorts

models/master_allocation.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828

2929
from django.contrib import admin
3030
from django.db import models
31-
from django.db.models import Q
31+
from django.db.models import Q, F, Value
32+
from django.db.models.functions import Concat, Upper
3233
from django.utils.datetime_safe import datetime
3334
from django.utils.translation import gettext_lazy as _
3435

@@ -139,4 +140,6 @@ def clean_allocations(cohort, master, postpone):
139140

140141

141142
def find_by_cohort(cohort_from):
142-
return MasterAllocation.objects.filter(Q(organization__cohort=cohort_from) | Q(specialty__cohort=cohort_from))
143+
return MasterAllocation.objects.annotate(master_display_name=Concat(
144+
Upper(F('master__person__last_name')), Value(' '), F('master__person__first_name')
145+
)).filter(Q(organization__cohort=cohort_from) | Q(specialty__cohort=cohort_from))

utils/exporting/organization_affectation_hospital.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,16 @@
2323
# see http://www.gnu.org/licenses/.
2424
#
2525
##############################################################################
26-
from django.db.models import OuterRef, Subquery
26+
from django.contrib.postgres.aggregates import StringAgg
27+
from django.db.models import OuterRef, Subquery, F, Value
28+
from django.db.models.functions import Concat, Upper
2729
from django.utils.translation import gettext_lazy as _
2830
from openpyxl import Workbook
2931
from openpyxl.styles import Font
3032

3133
from internship import models
3234
from internship.models.enums import organization_report_fields
35+
from internship.models.enums.role import Role
3336
from internship.models.internship_student_information import InternshipStudentInformation
3437
from internship.models.master_allocation import MasterAllocation
3538
from internship.utils.exporting.spreadsheet import columns_resizing, add_row
@@ -69,14 +72,22 @@ def _add_students(worksheet, cohort, organization):
6972
cohort, organization
7073
).select_related('student__person')
7174

72-
master_allocation_subquery = MasterAllocation.objects.filter(
75+
master_names = MasterAllocation.objects.filter(
7376
organization_id=OuterRef('organization_id'),
74-
specialty_id=OuterRef('speciality_id')
75-
)
77+
specialty_id=OuterRef('speciality_id'),
78+
role=Role.MASTER.name,
79+
).annotate(
80+
full_name=Concat(
81+
Upper(F('master__person__last_name')),
82+
Value(' '),
83+
F('master__person__first_name')
84+
)
85+
).values('organization_id').annotate(
86+
all_names=StringAgg('full_name', delimiter=', ')
87+
).values('all_names')
7688

7789
students_stat = students_stat.annotate(
78-
master_last_name=Subquery(master_allocation_subquery.values('master__person__last_name')[:1]),
79-
master_first_name=Subquery(master_allocation_subquery.values('master__person__first_name')[:1])
90+
masters=Subquery(master_names[:1])
8091
)
8192

8293
rep_seq = list(organization.report_sequence())
@@ -98,8 +109,7 @@ def _add_students(worksheet, cohort, organization):
98109
organization_report_fields.LAST_NAME: student_info.person.last_name,
99110
organization_report_fields.FIRST_NAME: student_info.person.first_name,
100111
organization_report_fields.SPECIALTY: student_stat.speciality.name,
101-
organization_report_fields.MASTER:
102-
f"{student_stat.master_first_name[0].upper()}. {student_stat.master_last_name.upper()}",
112+
organization_report_fields.MASTER: student_stat.masters,
103113
organization_report_fields.BIRTHDATE: student_info.person.birth_date.strftime("%d-%m-%Y")
104114
if student_info.person.birth_date else None,
105115
organization_report_fields.EMAIL: student_info.person.email,

views/place.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,7 @@ def _get_affec_by_specialties_for_cohorts(cohorts, organization_id):
230230
)
231231
_add_student_information(affectation, internship_student_info)
232232
if master_allocation:
233-
allocation = master_allocation.first()
234-
affectation.master = allocation.master
233+
affectation.master = ", ".join(master_allocation.values_list('master_display_name', flat=True))
235234
return affec_by_specialties, organization
236235

237236

0 commit comments

Comments
 (0)