diff --git a/api/drf_views.py b/api/drf_views.py index a4ec3ed7e..cdc85718c 100644 --- a/api/drf_views.py +++ b/api/drf_views.py @@ -123,6 +123,8 @@ DistrictSerializerRMD, ExportSerializer, ExternalPartnerSerializer, + FieldReportGeneratedTitleSerializer, + FieldReportGenerateTitleSerializer, FieldReportSerializer, GoHistoricalSerializer, HistoricalDisasterSerializer, @@ -151,7 +153,7 @@ UserMeSerializer, UserSerializer, ) -from .utils import is_user_ifrc +from .utils import generate_field_report_title, is_user_ifrc class DeploymentsByEventViewset(viewsets.ReadOnlyModelViewSet): @@ -943,6 +945,41 @@ def get_serializer_class(self): return FieldReportSerializer return FieldReportSerializer + @extend_schema( + request=FieldReportGenerateTitleSerializer, + responses=FieldReportGeneratedTitleSerializer, + ) + @action( + detail=False, + methods=["post"], + url_path="generate-title", + permission_classes=[DenyGuestUserMutationPermission], + ) + def generate_title(self, request): + """ + Generate a title for a Field Report. + """ + serializer = FieldReportGenerateTitleSerializer(data=request.data) + serializer.is_valid(raise_exception=True) + + countries = serializer.validated_data.get("countries") + dtype = serializer.validated_data.get("dtype") + event = serializer.validated_data.get("event") + start_date = serializer.validated_data.get("start_date") + title = serializer.validated_data.get("title") + is_covid_report = serializer.validated_data.get("is_covid_report") + + summary = generate_field_report_title( + country=countries[0], dtype=dtype, event=event, start_date=start_date, title=title, is_covid_report=is_covid_report + ) + return Response( + FieldReportGeneratedTitleSerializer( + { + "title": summary, + } + ).data + ) + class ActionViewset(viewsets.ReadOnlyModelViewSet): queryset = Action.objects.exclude(is_disabled=True) diff --git a/api/models.py b/api/models.py index cf1a60f64..fb866f5a0 100644 --- a/api/models.py +++ b/api/models.py @@ -25,7 +25,6 @@ from tinymce.models import HTMLField from lang.translation import AVAILABLE_LANGUAGES - from main.fields import SecureFileField from .utils import validate_slug_number # is_user_ifrc, @@ -1718,22 +1717,6 @@ def generate_formatted_summary(self): if self.id and not self.event: self.fr_num = None - suffix = f"#{self.fr_num} ({current_date})" if self.event else "" - - if self.fr_num is None and self.event and self.id: - current_fr_number = ( - FieldReport.objects.filter(event=self.event, countries__iso3=country_iso3).aggregate( - max_fr_num=models.Max("fr_num") - )["max_fr_num"] - or 0 - ) - field_report_number = current_fr_number + 1 - self.fr_num = field_report_number - - # NOTE: Report number is set to None if the report is not associated with an event - if self.id and not self.event: - self.fr_num = None - suffix = "" if self.fr_num and self.fr_num > 1: suffix = f"#{self.fr_num} ({current_date})" diff --git a/api/serializers.py b/api/serializers.py index 8c8b2aa30..7219fe678 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -2104,6 +2104,27 @@ def update(self, instance, validated_data): return super().update(instance, validated_data) +class FieldReportGenerateTitleSerializer(serializers.ModelSerializer): + dtype = serializers.PrimaryKeyRelatedField(queryset=DisasterType.objects.all()) + event = serializers.PrimaryKeyRelatedField(queryset=Event.objects.all(), required=False) + title = serializers.CharField(required=True) + + class Meta: + model = FieldReport + fields = ( + "countries", + "dtype", + "title", + "event", + "start_date", + "is_covid_report", + ) + + +class FieldReportGeneratedTitleSerializer(serializers.Serializer): + title = serializers.CharField() + + class MainContactSerializer(ModelSerializer): class Meta: model = MainContact diff --git a/api/test_views.py b/api/test_views.py index 0c3d16ca2..4b9cff70c 100644 --- a/api/test_views.py +++ b/api/test_views.py @@ -1,4 +1,3 @@ -import json import uuid from django.contrib.auth.models import User diff --git a/api/utils.py b/api/utils.py index dad805161..291753f92 100644 --- a/api/utils.py +++ b/api/utils.py @@ -1,9 +1,16 @@ import base64 +import typing +from typing import Optional from django.core.exceptions import ValidationError +from django.db import models from django.http import JsonResponse +from django.utils import timezone from django.utils.translation import gettext +if typing.TYPE_CHECKING: + from api.models import Country, DisasterType, Event + class DebugPlaywright: """Basic helpers to debug PlayWright issues locally""" @@ -96,3 +103,38 @@ def write(self, value): def bad_request(message): return JsonResponse({"statusCode": 400, "error_message": message}, status=400) + + +def generate_field_report_title( + country: "Country", + dtype: "DisasterType", + event: "Event", + start_date: Optional[timezone.datetime], + title: str, + is_covid_report: bool = False, +): + """ + Generates the summary based on the country, dtype, event, start_date, title and is_covid_report + """ + from api.models import FieldReport + + current_date = timezone.now().strftime("%Y-%m-%d") + # NOTE: start_date is optional and setting it to current date if not provided + if start_date: + start_date = start_date.strftime("%m-%Y") + else: + start_date = timezone.now().strftime("%m-%Y") + current_fr_number = ( + FieldReport.objects.filter(event=event, countries__id=country.id).aggregate(max_fr_num=models.Max("fr_num"))["max_fr_num"] + or 0 + ) + fr_num = current_fr_number + 1 + + suffix = "" + if fr_num > 1 and event: + suffix = f"#{fr_num} ({current_date})" + if is_covid_report: + summary = f"{country.iso3}: COVID-19 {suffix}" + else: + summary = f"{country.iso3}: {dtype.name} - {start_date} - {title} {suffix}" + return summary diff --git a/deployments/snapshots/snap_tests.py b/deployments/snapshots/snap_tests.py index 5b6754c76..4f9d76aaf 100644 --- a/deployments/snapshots/snap_tests.py +++ b/deployments/snapshots/snap_tests.py @@ -91,16 +91,16 @@ snapshots[ "TestProjectAPI::test_project_csv_api 1" ] = """actual_expenditure,budget_amount,description,document,dtype,dtype_detail.id,dtype_detail.name,dtype_detail.summary,dtype_detail.translation_module_original_language,end_date,event,event_detail.dtype,event_detail.emergency_response_contact_email,event_detail.id,event_detail.name,event_detail.parent_event,event_detail.slug,event_detail.start_date,event_detail.translation_module_original_language,id,modified_at,modified_by,modified_by_detail,name,operation_type,operation_type_display,primary_sector,primary_sector_display,programme_type,programme_type_display,project_country,project_country_detail.id,project_country_detail.iso,project_country_detail.iso3,project_country_detail.name,project_country_detail.society_name,project_districts_detail.code,project_districts_detail.id,project_districts_detail.is_deprecated,project_districts_detail.is_enclave,project_districts_detail.name,reached_female,reached_male,reached_other,reached_total,regional_project,regional_project_detail.created_at,regional_project_detail.id,regional_project_detail.modified_at,regional_project_detail.name,regional_project_detail.translation_module_original_language,regional_project_detail.translation_module_skip_auto_translation,reporting_ns,reporting_ns_contact_email,reporting_ns_contact_name,reporting_ns_contact_role,reporting_ns_detail.id,reporting_ns_detail.iso,reporting_ns_detail.iso3,reporting_ns_detail.name,reporting_ns_detail.society_name,secondary_sectors,secondary_sectors_display,start_date,status,status_display,target_female,target_male,target_other,target_total,translation_module_original_language,translation_module_skip_auto_translation,user,visibility,visibility_display\r -0,100000,,,1,1,disaster-type-1,summary,en,2008-01-01,2,1,,2,rpo: disaster-type-1 - 01-2008 - event-1,1,iqzlhqbiawyyplublqdivahhveecxxglgcgoncuyqhtdpbdezb,,en,1,2008-01-01T00:00:00.123456Z,,,project-hbvPgRZkVpHlJkvJBDoZzOllOQBzbVNmCLByaTnnrWTZYeKgZI,1,Emergency Operation,1,sect-1,0,Bilateral,1,1,bV,rpo,country-1,society-name-iVgRVIfLBcbfnoGMbJmTPSIAoCLrZaWZkSBvrjnWvgfygwwMqZ,"ctFhgpIiyD, lmiYIxHGrk","2, 1","False, False","False, False","district-DejWoRURzZJxfYzaqIhDxRVRqLyOxgRoEbNJuNoPeODStPAhic, district-bQzraKRXVdMVFsXZoMZwoOmNqRWUXQRiOgOPctYCcLxUifsuVA",0,0,0,0,1,2008-01-01T00:00:00.123456Z,1,2008-01-01T00:00:00.123456Z,regional-project-1,en,False,1,,,,1,bV,rpo,country-1,society-name-iVgRVIfLBcbfnoGMbJmTPSIAoCLrZaWZkSBvrjnWvgfygwwMqZ,"1, 2","sec-tag-1, sec-tag-2",2008-01-01,1,Ongoing,0,0,0,0,en,False,5,public,Public\r -0,100000,,,1,1,disaster-type-1,summary,en,2008-01-01,2,1,,2,rpo: disaster-type-1 - 01-2008 - event-1,1,iqzlhqbiawyyplublqdivahhveecxxglgcgoncuyqhtdpbdezb,,en,2,2008-01-01T00:00:00.123456Z,,,project-NzLhwwDNlRTZtNLfRiuhpthlxSjGyAMiKyBlFOISPlJkFsiluC,1,Emergency Operation,1,sect-1,0,Bilateral,1,1,bV,rpo,country-1,society-name-iVgRVIfLBcbfnoGMbJmTPSIAoCLrZaWZkSBvrjnWvgfygwwMqZ,"ctFhgpIiyD, lmiYIxHGrk","2, 1","False, False","False, False","district-DejWoRURzZJxfYzaqIhDxRVRqLyOxgRoEbNJuNoPeODStPAhic, district-bQzraKRXVdMVFsXZoMZwoOmNqRWUXQRiOgOPctYCcLxUifsuVA",0,0,0,0,1,2008-01-01T00:00:00.123456Z,1,2008-01-01T00:00:00.123456Z,regional-project-1,en,False,1,,,,1,bV,rpo,country-1,society-name-iVgRVIfLBcbfnoGMbJmTPSIAoCLrZaWZkSBvrjnWvgfygwwMqZ,"1, 2","sec-tag-1, sec-tag-2",2008-01-01,1,Ongoing,0,0,0,0,en,False,6,public,Public\r -0,100000,,,1,1,disaster-type-1,summary,en,2008-01-01,2,1,,2,rpo: disaster-type-1 - 01-2008 - event-1,1,iqzlhqbiawyyplublqdivahhveecxxglgcgoncuyqhtdpbdezb,,en,3,2008-01-01T00:00:00.123456Z,,,project-ATCFkfKbYWoscroIskXDKVXXFJGhKhrXIxIWcWUCInBgVPWptc,1,Emergency Operation,1,sect-1,0,Bilateral,1,1,bV,rpo,country-1,society-name-iVgRVIfLBcbfnoGMbJmTPSIAoCLrZaWZkSBvrjnWvgfygwwMqZ,"ctFhgpIiyD, lmiYIxHGrk","2, 1","False, False","False, False","district-DejWoRURzZJxfYzaqIhDxRVRqLyOxgRoEbNJuNoPeODStPAhic, district-bQzraKRXVdMVFsXZoMZwoOmNqRWUXQRiOgOPctYCcLxUifsuVA",0,0,0,0,1,2008-01-01T00:00:00.123456Z,1,2008-01-01T00:00:00.123456Z,regional-project-1,en,False,1,,,,1,bV,rpo,country-1,society-name-iVgRVIfLBcbfnoGMbJmTPSIAoCLrZaWZkSBvrjnWvgfygwwMqZ,"1, 2","sec-tag-1, sec-tag-2",2008-01-01,1,Ongoing,0,0,0,0,en,False,7,public,Public\r -0,100000,,,1,1,disaster-type-1,summary,en,2008-01-01,2,1,,2,rpo: disaster-type-1 - 01-2008 - event-1,1,iqzlhqbiawyyplublqdivahhveecxxglgcgoncuyqhtdpbdezb,,en,4,2008-01-01T00:00:00.123456Z,,,project-NOBkNiYnnZdKwIrMIkuTssKrGRgiWYAdrPiSipjTupWRzFjKOr,1,Emergency Operation,1,sect-1,0,Bilateral,1,1,bV,rpo,country-1,society-name-iVgRVIfLBcbfnoGMbJmTPSIAoCLrZaWZkSBvrjnWvgfygwwMqZ,"ctFhgpIiyD, lmiYIxHGrk","2, 1","False, False","False, False","district-DejWoRURzZJxfYzaqIhDxRVRqLyOxgRoEbNJuNoPeODStPAhic, district-bQzraKRXVdMVFsXZoMZwoOmNqRWUXQRiOgOPctYCcLxUifsuVA",0,0,0,0,1,2008-01-01T00:00:00.123456Z,1,2008-01-01T00:00:00.123456Z,regional-project-1,en,False,1,,,,1,bV,rpo,country-1,society-name-iVgRVIfLBcbfnoGMbJmTPSIAoCLrZaWZkSBvrjnWvgfygwwMqZ,"1, 2","sec-tag-1, sec-tag-2",2008-01-01,1,Ongoing,0,0,0,0,en,False,8,public,Public\r -0,100000,,,1,1,disaster-type-1,summary,en,2008-01-01,2,1,,2,rpo: disaster-type-1 - 01-2008 - event-1,1,iqzlhqbiawyyplublqdivahhveecxxglgcgoncuyqhtdpbdezb,,en,5,2008-01-01T00:00:00.123456Z,,,project-uLaXUfUDOQSweYIznBnFrusvJKiKFYvRWdcgOYDbhkCDaBmSiP,1,Emergency Operation,1,sect-1,0,Bilateral,1,1,bV,rpo,country-1,society-name-iVgRVIfLBcbfnoGMbJmTPSIAoCLrZaWZkSBvrjnWvgfygwwMqZ,"ctFhgpIiyD, lmiYIxHGrk","2, 1","False, False","False, False","district-DejWoRURzZJxfYzaqIhDxRVRqLyOxgRoEbNJuNoPeODStPAhic, district-bQzraKRXVdMVFsXZoMZwoOmNqRWUXQRiOgOPctYCcLxUifsuVA",0,0,0,0,1,2008-01-01T00:00:00.123456Z,1,2008-01-01T00:00:00.123456Z,regional-project-1,en,False,1,,,,1,bV,rpo,country-1,society-name-iVgRVIfLBcbfnoGMbJmTPSIAoCLrZaWZkSBvrjnWvgfygwwMqZ,"1, 2","sec-tag-1, sec-tag-2",2008-01-01,1,Ongoing,0,0,0,0,en,False,9,public,Public\r -0,100000,,,1,1,disaster-type-1,summary,en,2008-01-01,2,1,,2,rpo: disaster-type-1 - 01-2008 - event-1,1,iqzlhqbiawyyplublqdivahhveecxxglgcgoncuyqhtdpbdezb,,en,6,2008-01-01T00:00:00.123456Z,,,project-OtUSWoBPfTganEeiLoHRCaaSvhBSiEeoyfUZgguxtiyXWiPRje,1,Emergency Operation,1,sect-1,0,Bilateral,1,1,bV,rpo,country-1,society-name-iVgRVIfLBcbfnoGMbJmTPSIAoCLrZaWZkSBvrjnWvgfygwwMqZ,"ctFhgpIiyD, lmiYIxHGrk","2, 1","False, False","False, False","district-DejWoRURzZJxfYzaqIhDxRVRqLyOxgRoEbNJuNoPeODStPAhic, district-bQzraKRXVdMVFsXZoMZwoOmNqRWUXQRiOgOPctYCcLxUifsuVA",0,0,0,0,1,2008-01-01T00:00:00.123456Z,1,2008-01-01T00:00:00.123456Z,regional-project-1,en,False,1,,,,1,bV,rpo,country-1,society-name-iVgRVIfLBcbfnoGMbJmTPSIAoCLrZaWZkSBvrjnWvgfygwwMqZ,"1, 2","sec-tag-1, sec-tag-2",2008-01-01,1,Ongoing,0,0,0,0,en,False,10,public,Public\r -0,100000,,,1,1,disaster-type-1,summary,en,2008-01-01,2,1,,2,rpo: disaster-type-1 - 01-2008 - event-1,1,iqzlhqbiawyyplublqdivahhveecxxglgcgoncuyqhtdpbdezb,,en,7,2008-01-01T00:00:00.123456Z,,,project-giWhLUywBuYiprPfpJMMUMsXSbQtnHMGmVzsPdYYpFyhpFOMeH,1,Emergency Operation,1,sect-1,0,Bilateral,1,1,bV,rpo,country-1,society-name-iVgRVIfLBcbfnoGMbJmTPSIAoCLrZaWZkSBvrjnWvgfygwwMqZ,"ctFhgpIiyD, lmiYIxHGrk","2, 1","False, False","False, False","district-DejWoRURzZJxfYzaqIhDxRVRqLyOxgRoEbNJuNoPeODStPAhic, district-bQzraKRXVdMVFsXZoMZwoOmNqRWUXQRiOgOPctYCcLxUifsuVA",0,0,0,0,1,2008-01-01T00:00:00.123456Z,1,2008-01-01T00:00:00.123456Z,regional-project-1,en,False,1,,,,1,bV,rpo,country-1,society-name-iVgRVIfLBcbfnoGMbJmTPSIAoCLrZaWZkSBvrjnWvgfygwwMqZ,"1, 2","sec-tag-1, sec-tag-2",2008-01-01,1,Ongoing,0,0,0,0,en,False,11,public,Public\r -0,100000,,,1,1,disaster-type-1,summary,en,2008-01-01,2,1,,2,rpo: disaster-type-1 - 01-2008 - event-1,1,iqzlhqbiawyyplublqdivahhveecxxglgcgoncuyqhtdpbdezb,,en,8,2008-01-01T00:00:00.123456Z,,,project-bLeaqncdYzGsOTGXABSzfOIINjrftfGnZjIuzLOWPRPetSBUpd,1,Emergency Operation,1,sect-1,0,Bilateral,1,1,bV,rpo,country-1,society-name-iVgRVIfLBcbfnoGMbJmTPSIAoCLrZaWZkSBvrjnWvgfygwwMqZ,"ctFhgpIiyD, lmiYIxHGrk","2, 1","False, False","False, False","district-DejWoRURzZJxfYzaqIhDxRVRqLyOxgRoEbNJuNoPeODStPAhic, district-bQzraKRXVdMVFsXZoMZwoOmNqRWUXQRiOgOPctYCcLxUifsuVA",0,0,0,0,1,2008-01-01T00:00:00.123456Z,1,2008-01-01T00:00:00.123456Z,regional-project-1,en,False,1,,,,1,bV,rpo,country-1,society-name-iVgRVIfLBcbfnoGMbJmTPSIAoCLrZaWZkSBvrjnWvgfygwwMqZ,"1, 2","sec-tag-1, sec-tag-2",2008-01-01,1,Ongoing,0,0,0,0,en,False,12,public,Public\r -0,100000,,,1,1,disaster-type-1,summary,en,2008-01-01,2,1,,2,rpo: disaster-type-1 - 01-2008 - event-1,1,iqzlhqbiawyyplublqdivahhveecxxglgcgoncuyqhtdpbdezb,,en,9,2008-01-01T00:00:00.123456Z,,,project-iSakFwHHYUqkxiVXrUhXbvZBrHeqTKOeFDGxdFKkxkqXgKRUho,1,Emergency Operation,1,sect-1,0,Bilateral,1,1,bV,rpo,country-1,society-name-iVgRVIfLBcbfnoGMbJmTPSIAoCLrZaWZkSBvrjnWvgfygwwMqZ,"ctFhgpIiyD, lmiYIxHGrk","2, 1","False, False","False, False","district-DejWoRURzZJxfYzaqIhDxRVRqLyOxgRoEbNJuNoPeODStPAhic, district-bQzraKRXVdMVFsXZoMZwoOmNqRWUXQRiOgOPctYCcLxUifsuVA",0,0,0,0,1,2008-01-01T00:00:00.123456Z,1,2008-01-01T00:00:00.123456Z,regional-project-1,en,False,1,,,,1,bV,rpo,country-1,society-name-iVgRVIfLBcbfnoGMbJmTPSIAoCLrZaWZkSBvrjnWvgfygwwMqZ,"1, 2","sec-tag-1, sec-tag-2",2008-01-01,1,Ongoing,0,0,0,0,en,False,13,public,Public\r -0,100000,,,1,1,disaster-type-1,summary,en,2008-01-01,2,1,,2,rpo: disaster-type-1 - 01-2008 - event-1,1,iqzlhqbiawyyplublqdivahhveecxxglgcgoncuyqhtdpbdezb,,en,10,2008-01-01T00:00:00.123456Z,,,project-cJZTVPAoupAUureKxhGRdloZHczeDsXtufJDaxmsKYtVNpDxLF,1,Emergency Operation,1,sect-1,0,Bilateral,1,1,bV,rpo,country-1,society-name-iVgRVIfLBcbfnoGMbJmTPSIAoCLrZaWZkSBvrjnWvgfygwwMqZ,"ctFhgpIiyD, lmiYIxHGrk","2, 1","False, False","False, False","district-DejWoRURzZJxfYzaqIhDxRVRqLyOxgRoEbNJuNoPeODStPAhic, district-bQzraKRXVdMVFsXZoMZwoOmNqRWUXQRiOgOPctYCcLxUifsuVA",0,0,0,0,1,2008-01-01T00:00:00.123456Z,1,2008-01-01T00:00:00.123456Z,regional-project-1,en,False,1,,,,1,bV,rpo,country-1,society-name-iVgRVIfLBcbfnoGMbJmTPSIAoCLrZaWZkSBvrjnWvgfygwwMqZ,"1, 2","sec-tag-1, sec-tag-2",2008-01-01,1,Ongoing,0,0,0,0,en,False,14,public,Public\r +0,100000,,,1,1,disaster-type-1,summary,en,2008-01-01,2,1,,2,rpo: disaster-type-1 - 01-2008 - event-1,1,event-slug,,en,1,2008-01-01T00:00:00.123456Z,,,project-1,1,Emergency Operation,1,sect-1,0,Bilateral,1,1,bV,rpo,country-1,society-name-1,"dct1, dct2","1, 2","True, False","False, True","district-1, district-2",0,0,0,0,1,2008-01-01T00:00:00.123456Z,1,2008-01-01T00:00:00.123456Z,regional-project-1,en,False,1,,,,1,bV,rpo,country-1,society-name-1,"1, 2","sec-tag-1, sec-tag-2",2008-01-01,1,Ongoing,0,0,0,0,en,False,5,public,Public\r +0,100000,,,1,1,disaster-type-1,summary,en,2008-01-01,2,1,,2,rpo: disaster-type-1 - 01-2008 - event-1,1,event-slug,,en,2,2008-01-01T00:00:00.123456Z,,,project-1,1,Emergency Operation,1,sect-1,0,Bilateral,1,1,bV,rpo,country-1,society-name-1,"dct1, dct2","1, 2","True, False","False, True","district-1, district-2",0,0,0,0,1,2008-01-01T00:00:00.123456Z,1,2008-01-01T00:00:00.123456Z,regional-project-1,en,False,1,,,,1,bV,rpo,country-1,society-name-1,"1, 2","sec-tag-1, sec-tag-2",2008-01-01,1,Ongoing,0,0,0,0,en,False,6,public,Public\r +0,100000,,,1,1,disaster-type-1,summary,en,2008-01-01,2,1,,2,rpo: disaster-type-1 - 01-2008 - event-1,1,event-slug,,en,3,2008-01-01T00:00:00.123456Z,,,project-1,1,Emergency Operation,1,sect-1,0,Bilateral,1,1,bV,rpo,country-1,society-name-1,"dct1, dct2","1, 2","True, False","False, True","district-1, district-2",0,0,0,0,1,2008-01-01T00:00:00.123456Z,1,2008-01-01T00:00:00.123456Z,regional-project-1,en,False,1,,,,1,bV,rpo,country-1,society-name-1,"1, 2","sec-tag-1, sec-tag-2",2008-01-01,1,Ongoing,0,0,0,0,en,False,7,public,Public\r +0,100000,,,1,1,disaster-type-1,summary,en,2008-01-01,2,1,,2,rpo: disaster-type-1 - 01-2008 - event-1,1,event-slug,,en,4,2008-01-01T00:00:00.123456Z,,,project-1,1,Emergency Operation,1,sect-1,0,Bilateral,1,1,bV,rpo,country-1,society-name-1,"dct1, dct2","1, 2","True, False","False, True","district-1, district-2",0,0,0,0,1,2008-01-01T00:00:00.123456Z,1,2008-01-01T00:00:00.123456Z,regional-project-1,en,False,1,,,,1,bV,rpo,country-1,society-name-1,"1, 2","sec-tag-1, sec-tag-2",2008-01-01,1,Ongoing,0,0,0,0,en,False,8,public,Public\r +0,100000,,,1,1,disaster-type-1,summary,en,2008-01-01,2,1,,2,rpo: disaster-type-1 - 01-2008 - event-1,1,event-slug,,en,5,2008-01-01T00:00:00.123456Z,,,project-1,1,Emergency Operation,1,sect-1,0,Bilateral,1,1,bV,rpo,country-1,society-name-1,"dct1, dct2","1, 2","True, False","False, True","district-1, district-2",0,0,0,0,1,2008-01-01T00:00:00.123456Z,1,2008-01-01T00:00:00.123456Z,regional-project-1,en,False,1,,,,1,bV,rpo,country-1,society-name-1,"1, 2","sec-tag-1, sec-tag-2",2008-01-01,1,Ongoing,0,0,0,0,en,False,9,public,Public\r +0,100000,,,1,1,disaster-type-1,summary,en,2008-01-01,2,1,,2,rpo: disaster-type-1 - 01-2008 - event-1,1,event-slug,,en,6,2008-01-01T00:00:00.123456Z,,,project-1,1,Emergency Operation,1,sect-1,0,Bilateral,1,1,bV,rpo,country-1,society-name-1,"dct1, dct2","1, 2","True, False","False, True","district-1, district-2",0,0,0,0,1,2008-01-01T00:00:00.123456Z,1,2008-01-01T00:00:00.123456Z,regional-project-1,en,False,1,,,,1,bV,rpo,country-1,society-name-1,"1, 2","sec-tag-1, sec-tag-2",2008-01-01,1,Ongoing,0,0,0,0,en,False,10,public,Public\r +0,100000,,,1,1,disaster-type-1,summary,en,2008-01-01,2,1,,2,rpo: disaster-type-1 - 01-2008 - event-1,1,event-slug,,en,7,2008-01-01T00:00:00.123456Z,,,project-1,1,Emergency Operation,1,sect-1,0,Bilateral,1,1,bV,rpo,country-1,society-name-1,"dct1, dct2","1, 2","True, False","False, True","district-1, district-2",0,0,0,0,1,2008-01-01T00:00:00.123456Z,1,2008-01-01T00:00:00.123456Z,regional-project-1,en,False,1,,,,1,bV,rpo,country-1,society-name-1,"1, 2","sec-tag-1, sec-tag-2",2008-01-01,1,Ongoing,0,0,0,0,en,False,11,public,Public\r +0,100000,,,1,1,disaster-type-1,summary,en,2008-01-01,2,1,,2,rpo: disaster-type-1 - 01-2008 - event-1,1,event-slug,,en,8,2008-01-01T00:00:00.123456Z,,,project-1,1,Emergency Operation,1,sect-1,0,Bilateral,1,1,bV,rpo,country-1,society-name-1,"dct1, dct2","1, 2","True, False","False, True","district-1, district-2",0,0,0,0,1,2008-01-01T00:00:00.123456Z,1,2008-01-01T00:00:00.123456Z,regional-project-1,en,False,1,,,,1,bV,rpo,country-1,society-name-1,"1, 2","sec-tag-1, sec-tag-2",2008-01-01,1,Ongoing,0,0,0,0,en,False,12,public,Public\r +0,100000,,,1,1,disaster-type-1,summary,en,2008-01-01,2,1,,2,rpo: disaster-type-1 - 01-2008 - event-1,1,event-slug,,en,9,2008-01-01T00:00:00.123456Z,,,project-1,1,Emergency Operation,1,sect-1,0,Bilateral,1,1,bV,rpo,country-1,society-name-1,"dct1, dct2","1, 2","True, False","False, True","district-1, district-2",0,0,0,0,1,2008-01-01T00:00:00.123456Z,1,2008-01-01T00:00:00.123456Z,regional-project-1,en,False,1,,,,1,bV,rpo,country-1,society-name-1,"1, 2","sec-tag-1, sec-tag-2",2008-01-01,1,Ongoing,0,0,0,0,en,False,13,public,Public\r +0,100000,,,1,1,disaster-type-1,summary,en,2008-01-01,2,1,,2,rpo: disaster-type-1 - 01-2008 - event-1,1,event-slug,,en,10,2008-01-01T00:00:00.123456Z,,,project-1,1,Emergency Operation,1,sect-1,0,Bilateral,1,1,bV,rpo,country-1,society-name-1,"dct1, dct2","1, 2","True, False","False, True","district-1, district-2",0,0,0,0,1,2008-01-01T00:00:00.123456Z,1,2008-01-01T00:00:00.123456Z,regional-project-1,en,False,1,,,,1,bV,rpo,country-1,society-name-1,"1, 2","sec-tag-1, sec-tag-2",2008-01-01,1,Ongoing,0,0,0,0,en,False,14,public,Public\r """ snapshots["TestProjectAPI::test_project_delete 1"] = b"" diff --git a/deployments/tests.py b/deployments/tests.py index 5e4ef1af9..2c8609d76 100644 --- a/deployments/tests.py +++ b/deployments/tests.py @@ -191,22 +191,24 @@ def test_personnel_csv_api(self): self.assertMatchSnapshot(resp.content.decode("utf-8")) def test_project_csv_api(self): - _country = country.CountryFactory(name="country-1") - sct = SectorFactory(title="sect-1") - sct_1 = SectorTagFactory(title="sec-tag-1") - sct_2 = SectorTagFactory(title="sec-tag-2") - district1 = district.DistrictFactory(country=_country) - district2 = district.DistrictFactory(country=_country) + _country = country.CountryFactory(name="country-1", society_name="society-name-1") + sct = SectorFactory(title="sect-1", order=1) + sct_1 = SectorTagFactory(title="sec-tag-1", order=2) + sct_2 = SectorTagFactory(title="sec-tag-2", order=3) + district1 = district.DistrictFactory(country=_country, name="district-1", code="dct1") + district2 = district.DistrictFactory(country=_country, name="district-2", code="dct2") dtype = DisasterTypeFactory(name="disaster-type-1", summary="summary") regional_project = RegionalProjectFactory(name="regional-project-1") event = EventFactory( countries=[_country.id], + slug="event-slug", districts=[district1.id, district2.id], dtype=dtype, title="event-1", ) ProjectFactory.create_batch( 10, + name="project-1", project_districts=[district1, district2], budget_amount=100000, primary_sector=sct,